diff options
author | Wu Cheng-Han | 2016-08-02 17:16:01 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-08-02 17:16:01 +0800 |
commit | 67474aa1d4bf1281f48dc3b0936ce7c32edf30d8 (patch) | |
tree | 7ff90c5547b2dc22698b93bb8a54edda258a5981 | |
parent | f49fc192f64a7fb86baa8eae5717ea87de43c8e5 (diff) |
Update realtime check and refresh event, compress data using LZString UTF16 to minimize network delay
Diffstat (limited to '')
-rw-r--r-- | lib/realtime.js | 7 | ||||
-rw-r--r-- | public/js/index.js | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/realtime.js b/lib/realtime.js index 11de294d..e18ac12a 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -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); } @@ -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, @@ -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) { diff --git a/public/js/index.js b/public/js/index.js index 7f9c8ad8..87c69770 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -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); }); @@ -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); |