Remove manual LZString compression for partial socket io event data
This commit is contained in:
parent
e65e09215a
commit
c904083d1f
5 changed files with 3 additions and 22 deletions
|
@ -7,7 +7,6 @@ var Server = require('./server');
|
||||||
var Selection = require('./selection');
|
var Selection = require('./selection');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
|
||||||
var LZString = require('lz-string');
|
|
||||||
var logger = require('../logger');
|
var logger = require('../logger');
|
||||||
|
|
||||||
function EditorSocketIOServer(document, operations, docId, mayWrite, operationCallback) {
|
function EditorSocketIOServer(document, operations, docId, mayWrite, operationCallback) {
|
||||||
|
@ -40,10 +39,8 @@ EditorSocketIOServer.prototype.addClient = function (socket) {
|
||||||
revision: this.operations.length,
|
revision: this.operations.length,
|
||||||
clients: this.users
|
clients: this.users
|
||||||
};
|
};
|
||||||
socket.emit('doc', LZString.compressToUTF16(JSON.stringify(docOut)));
|
socket.emit('doc', docOut);
|
||||||
socket.on('operation', function (revision, operation, selection) {
|
socket.on('operation', function (revision, operation, selection) {
|
||||||
operation = LZString.decompressFromUTF16(operation);
|
|
||||||
operation = JSON.parse(operation);
|
|
||||||
socket.origin = 'operation';
|
socket.origin = 'operation';
|
||||||
self.mayWrite(socket, function (mayWrite) {
|
self.mayWrite(socket, function (mayWrite) {
|
||||||
if (!mayWrite) {
|
if (!mayWrite) {
|
||||||
|
@ -62,7 +59,7 @@ EditorSocketIOServer.prototype.addClient = function (socket) {
|
||||||
clients: self.users,
|
clients: self.users,
|
||||||
force: true
|
force: true
|
||||||
};
|
};
|
||||||
socket.emit('doc', LZString.compressToUTF16(JSON.stringify(docOut)));
|
socket.emit('doc', docOut);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -129,7 +126,6 @@ EditorSocketIOServer.prototype.onGetOperations = function (socket, base, head) {
|
||||||
var operations = this.operations.slice(base, head).map(function (op) {
|
var operations = this.operations.slice(base, head).map(function (op) {
|
||||||
return op.wrapped.toJSON();
|
return op.wrapped.toJSON();
|
||||||
});
|
});
|
||||||
operations = LZString.compressToUTF16(JSON.stringify(operations));
|
|
||||||
socket.emit('operations', head, operations);
|
socket.emit('operations', head, operations);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,6 @@ function emitCheck(note) {
|
||||||
authors: note.authors,
|
authors: note.authors,
|
||||||
authorship: note.authorship
|
authorship: note.authorship
|
||||||
};
|
};
|
||||||
out = LZString.compressToUTF16(JSON.stringify(out));
|
|
||||||
realtime.io.to(note.id).emit('check', out);
|
realtime.io.to(note.id).emit('check', out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +300,6 @@ function emitOnlineUsers(socket) {
|
||||||
var out = {
|
var out = {
|
||||||
users: users
|
users: users
|
||||||
};
|
};
|
||||||
out = LZString.compressToUTF16(JSON.stringify(out));
|
|
||||||
realtime.io.to(noteId).emit('online users', out);
|
realtime.io.to(noteId).emit('online users', out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +328,6 @@ function emitRefresh(socket) {
|
||||||
createtime: note.createtime,
|
createtime: note.createtime,
|
||||||
updatetime: note.updatetime
|
updatetime: note.updatetime
|
||||||
};
|
};
|
||||||
out = LZString.compressToUTF16(JSON.stringify(out));
|
|
||||||
socket.emit('refresh', out);
|
socket.emit('refresh', out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,7 +860,6 @@ function connection(socket) {
|
||||||
var out = {
|
var out = {
|
||||||
users: users
|
users: users
|
||||||
};
|
};
|
||||||
out = LZString.compressToUTF16(JSON.stringify(out));
|
|
||||||
socket.emit('online users', out);
|
socket.emit('online users', out);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2645,8 +2645,6 @@ editor.on('update', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
socket.on('check', function (data) {
|
socket.on('check', function (data) {
|
||||||
data = LZString.decompressFromUTF16(data);
|
|
||||||
data = JSON.parse(data);
|
|
||||||
//console.log(data);
|
//console.log(data);
|
||||||
updateInfo(data);
|
updateInfo(data);
|
||||||
});
|
});
|
||||||
|
@ -2656,8 +2654,6 @@ socket.on('permission', function (data) {
|
||||||
var docmaxlength = null;
|
var docmaxlength = null;
|
||||||
var permission = null;
|
var permission = null;
|
||||||
socket.on('refresh', function (data) {
|
socket.on('refresh', function (data) {
|
||||||
data = LZString.decompressFromUTF16(data);
|
|
||||||
data = JSON.parse(data);
|
|
||||||
//console.log(data);
|
//console.log(data);
|
||||||
docmaxlength = data.docmaxlength;
|
docmaxlength = data.docmaxlength;
|
||||||
editor.setOption("maxLength", docmaxlength);
|
editor.setOption("maxLength", docmaxlength);
|
||||||
|
@ -2704,8 +2700,6 @@ var CodeMirrorAdapter = ot.CodeMirrorAdapter;
|
||||||
var cmClient = null;
|
var cmClient = null;
|
||||||
|
|
||||||
socket.on('doc', function (obj) {
|
socket.on('doc', function (obj) {
|
||||||
obj = LZString.decompressFromUTF16(obj);
|
|
||||||
obj = JSON.parse(obj);
|
|
||||||
var body = obj.str;
|
var body = obj.str;
|
||||||
var bodyMismatch = editor.getValue() !== body;
|
var bodyMismatch = editor.getValue() !== body;
|
||||||
var havePendingOperation = cmClient && Object.keys(cmClient.state).length > 0;
|
var havePendingOperation = cmClient && Object.keys(cmClient.state).length > 0;
|
||||||
|
@ -2766,8 +2760,6 @@ socket.on('operation', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('online users', function (data) {
|
socket.on('online users', function (data) {
|
||||||
data = LZString.decompressFromUTF16(data);
|
|
||||||
data = JSON.parse(data);
|
|
||||||
if (debug)
|
if (debug)
|
||||||
console.debug(data);
|
console.debug(data);
|
||||||
onlineUsers = data.users;
|
onlineUsers = data.users;
|
||||||
|
|
2
public/vendor/ot/ot.min.js
vendored
2
public/vendor/ot/ot.min.js
vendored
File diff suppressed because one or more lines are too long
3
public/vendor/ot/socketio-adapter.js
vendored
Normal file → Executable file
3
public/vendor/ot/socketio-adapter.js
vendored
Normal file → Executable file
|
@ -24,8 +24,6 @@ ot.SocketIOAdapter = (function () {
|
||||||
self.trigger('selection', clientId, selection);
|
self.trigger('selection', clientId, selection);
|
||||||
});
|
});
|
||||||
socket.on('operations', function (head, operations) {
|
socket.on('operations', function (head, operations) {
|
||||||
operations = LZString.decompressFromUTF16(operations);
|
|
||||||
operations = JSON.parse(operations);
|
|
||||||
self.trigger('operations', head, operations);
|
self.trigger('operations', head, operations);
|
||||||
});
|
});
|
||||||
socket.on('selection', function (clientId, selection) {
|
socket.on('selection', function (clientId, selection) {
|
||||||
|
@ -37,7 +35,6 @@ ot.SocketIOAdapter = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketIOAdapter.prototype.sendOperation = function (revision, operation, selection) {
|
SocketIOAdapter.prototype.sendOperation = function (revision, operation, selection) {
|
||||||
operation = LZString.compressToUTF16(JSON.stringify(operation));
|
|
||||||
this.socket.emit('operation', revision, operation, selection);
|
this.socket.emit('operation', revision, operation, selection);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue