summaryrefslogtreecommitdiff
path: root/lib/realtime.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/realtime.js')
-rw-r--r--lib/realtime.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/realtime.js b/lib/realtime.js
index 0b5a46b2..b5a3b182 100644
--- a/lib/realtime.js
+++ b/lib/realtime.js
@@ -26,6 +26,7 @@ var User = require("./user.js");
//public
var realtime = {
+ io: null,
onAuthorizeSuccess: onAuthorizeSuccess,
onAuthorizeFail: onAuthorizeFail,
secure: secure,
@@ -67,10 +68,13 @@ function emitCheck(note) {
var out = {
updatetime: note.updatetime
};
+ realtime.io.to(note.id).emit('check', out);
+ /*
for (var i = 0, l = note.socks.length; i < l; i++) {
var sock = note.socks[i];
sock.emit('check', out);
};
+ */
}
//actions
@@ -183,23 +187,29 @@ function emitOnlineUsers(socket) {
users: users
};
out = LZString.compressToUTF16(JSON.stringify(out));
+ realtime.io.to(notename).emit('online users', out);
+ /*
for (var i = 0, l = notes[notename].socks.length; i < l; i++) {
var sock = notes[notename].socks[i];
if (sock && out)
sock.emit('online users', out);
};
+ */
}
function emitUserStatus(socket) {
var notename = getNotenameFromSocket(socket);
if (!notename || !notes[notename]) return;
var out = buildUserOutData(users[socket.id]);
+ socket.broadcast.to(notename).emit('user status', out);
+ /*
for (var i = 0, l = notes[notename].socks.length; i < l; i++) {
var sock = notes[notename].socks[i];
if (sock != socket) {
sock.emit('user status', out);
}
};
+ */
}
function emitRefresh(socket) {
@@ -287,6 +297,7 @@ function startConnection(socket) {
var updatetime = data.rows[0].update_time;
var server = new ot.EditorSocketIOServer(body, [], notename, ifMayEdit);
notes[notename] = {
+ id: notename,
owner: owner,
permission: note.permission,
socks: [],
@@ -522,10 +533,13 @@ function connection(socket) {
var out = {
permission: permission
};
+ realtime.io.to(note.id).emit('permission', out);
+ /*
for (var i = 0, l = note.socks.length; i < l; i++) {
var sock = note.socks[i];
sock.emit('permission', out);
};
+ */
});
});
}
@@ -569,12 +583,15 @@ function connection(socket) {
if (!notename || !notes[notename]) return;
users[socket.id].cursor = data;
var out = buildUserOutData(users[socket.id]);
+ socket.broadcast.to(notename).emit('cursor focus', out);
+ /*
for (var i = 0, l = notes[notename].socks.length; i < l; i++) {
var sock = notes[notename].socks[i];
if (sock != socket) {
sock.emit('cursor focus', out);
}
};
+ */
});
//received cursor activity
@@ -583,12 +600,15 @@ function connection(socket) {
if (!notename || !notes[notename]) return;
users[socket.id].cursor = data;
var out = buildUserOutData(users[socket.id]);
+ socket.broadcast.to(notename).emit('cursor activity', out);
+ /*
for (var i = 0, l = notes[notename].socks.length; i < l; i++) {
var sock = notes[notename].socks[i];
if (sock != socket) {
sock.emit('cursor activity', out);
}
};
+ */
});
//received cursor blur
@@ -599,12 +619,15 @@ function connection(socket) {
var out = {
id: socket.id
};
+ socket.broadcast.to(notename).emit('cursor blur', out);
+ /*
for (var i = 0, l = notes[notename].socks.length; i < l; i++) {
var sock = notes[notename].socks[i];
if (sock != socket) {
sock.emit('cursor blur', out);
}
};
+ */
});
//when a new client disconnect