Skip to content

Commit 67474aa

Browse files
committed
Update realtime check and refresh event, compress data using LZString UTF16 to minimize network delay
1 parent f49fc19 commit 67474aa

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/realtime.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function emitCheck(note) {
6969
authors: note.authors,
7070
authorship: note.authorship
7171
};
72+
out = LZString.compressToUTF16(JSON.stringify(out));
7273
realtime.io.to(note.id).emit('check', out);
7374
}
7475

@@ -310,7 +311,7 @@ function emitRefresh(socket) {
310311
var noteId = socket.noteId;
311312
if (!noteId || !notes[noteId]) return;
312313
var note = notes[noteId];
313-
socket.emit('refresh', {
314+
var out = {
314315
docmaxlength: config.documentmaxlength,
315316
owner: note.owner,
316317
ownerprofile: note.ownerprofile,
@@ -321,7 +322,9 @@ function emitRefresh(socket) {
321322
permission: note.permission,
322323
createtime: note.createtime,
323324
updatetime: note.updatetime
324-
});
325+
};
326+
out = LZString.compressToUTF16(JSON.stringify(out));
327+
socket.emit('refresh', out);
325328
}
326329

327330
function clearSocketQueue(queue, socket) {

public/js/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,8 @@ editor.on('update', function () {
23602360
});
23612361
});
23622362
socket.on('check', function (data) {
2363+
data = LZString.decompressFromUTF16(data);
2364+
data = JSON.parse(data);
23632365
//console.log(data);
23642366
updateLastInfo(data);
23652367
});
@@ -2371,6 +2373,8 @@ var otk = null;
23712373
var owner = null;
23722374
var permission = null;
23732375
socket.on('refresh', function (data) {
2376+
data = LZString.decompressFromUTF16(data);
2377+
data = JSON.parse(data);
23742378
//console.log(data);
23752379
docmaxlength = data.docmaxlength;
23762380
editor.setOption("maxLength", docmaxlength);

0 commit comments

Comments
 (0)