Skip to content

Commit

Permalink
Update realtime check and refresh event, compress data using LZString…
Browse files Browse the repository at this point in the history
… UTF16 to minimize network delay
  • Loading branch information
jackycute committed Aug 2, 2016
1 parent f49fc19 commit 67474aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function emitCheck(note) {
authors: note.authors,
authorship: note.authorship
};
out = LZString.compressToUTF16(JSON.stringify(out));
realtime.io.to(note.id).emit('check', out);
}

Expand Down Expand Up @@ -310,7 +311,7 @@ function emitRefresh(socket) {
var noteId = socket.noteId;
if (!noteId || !notes[noteId]) return;
var note = notes[noteId];
socket.emit('refresh', {
var out = {
docmaxlength: config.documentmaxlength,
owner: note.owner,
ownerprofile: note.ownerprofile,
Expand All @@ -321,7 +322,9 @@ function emitRefresh(socket) {
permission: note.permission,
createtime: note.createtime,
updatetime: note.updatetime
});
};
out = LZString.compressToUTF16(JSON.stringify(out));
socket.emit('refresh', out);
}

function clearSocketQueue(queue, socket) {
Expand Down
4 changes: 4 additions & 0 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,8 @@ editor.on('update', function () {
});
});
socket.on('check', function (data) {
data = LZString.decompressFromUTF16(data);
data = JSON.parse(data);
//console.log(data);
updateLastInfo(data);
});
Expand All @@ -2371,6 +2373,8 @@ var otk = null;
var owner = null;
var permission = null;
socket.on('refresh', function (data) {
data = LZString.decompressFromUTF16(data);
data = JSON.parse(data);
//console.log(data);
docmaxlength = data.docmaxlength;
editor.setOption("maxLength", docmaxlength);
Expand Down

0 comments on commit 67474aa

Please sign in to comment.