diff options
Diffstat (limited to 'socket.js')
-rw-r--r-- | socket.js | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -1,4 +1,6 @@ /* socket.js, a simple wrapper for a YWOT websocket connection */ +const ws = require('ws') +const EventEmitter = require('events'); class retryws extends EventEmitter{ // a wrapper on ws that retries on failure constructor(addr) { @@ -38,7 +40,7 @@ class Socket extends retryws { case 'fetch': this.emit('fetch', message.tiles); break; // The response to a fetch request } - } + }); this.fetch = function(coords){ //coords is a list of quadruplets, each a min/max pair of y/x coordinate pairs which describes at most 1000 tiles //Unchecked for speed @@ -56,12 +58,14 @@ class Socket extends retryws { chars[i].splice(4,0,0); // chars[i].push(i); } - this.send(`{"edits":${JSON.stringify(chars)},"kind":"write"}`; + this.send(`{"edits":${JSON.stringify(chars)},"kind":"write"}`); } this.cursor = function(coords){ //coords is just one quadruplet analagous to fetch; I think the api could handle more, but it's unnecessary for now. - this.send(`"kind":"cursor","positions":[${JSON.stringify(coords)}]}`; + this.send(`"kind":"cursor","positions":[${JSON.stringify(coords)}]}`); } } } + +exports.Socket = Socket; |