diff options
-rw-r--r-- | socket.js | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -32,6 +32,7 @@ class Socket extends retryws { let loc = (world == '') ? '' : `${world}/`; let addr = `wss://www.yourworldoftext.com/${loc}ws/`; super(addr); + let writect = 0; // A running counter to make the server write confirmations meaningful this.on('message', (msg)=>{ msg = JSON.parse(msg); switch (msg.kind){ @@ -62,23 +63,25 @@ class Socket extends retryws { if (chars.length > 200){ throw "Too many characters to write by server decree"; } - for (var i=0; i<chars.length; i++){ - let char = chars[i] - let coord = char[0]; - chars[i] = [ + let write = []; + for (let cha of chars){ + let coord = cha[0]; + write.push([ Math.floor(coord[0]/8), Math.floor(coord[1]/16), mod(coord[0], 8), mod(coord[1], 16), - char[1] - ]; - chars[i].splice(4,0,0); - chars[i].push(i); + 0, + cha[1], + writect + ]); + writect++; } this.send( JSON.stringify({ - "edits": chars, + "edits": write, "kind": "write" })); + return writect-chars.length; // First label within write for cross-referencing with confirmation } this.cursor = function(coords){ //coords is just one pair of char coords; I think the api could handle more, but it's unnecessary for now. |