aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2020-01-09 14:08:50 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2020-01-09 14:08:50 -0500
commit93a85ad37cefc4a704005d3e08f8afcd77bd43c0 (patch)
tree78d8bdb0e7776d13bce66bbd7eea27419932a7d8
parented9d3b42125a8fb6f54b6e6521f067ec7e7d8b62 (diff)
added write counter and simplified Socket.write
-rw-r--r--socket.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/socket.js b/socket.js
index dfd0999..aefc1c0 100644
--- a/socket.js
+++ b/socket.js
@@ -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.