diff options
author | Kyle Gunger <corechg@gmail.com> | 2020-09-18 12:19:44 -0400 |
---|---|---|
committer | Kyle Gunger <corechg@gmail.com> | 2020-09-18 12:19:44 -0400 |
commit | dbaf69557c0d6e648120b068fec1920b9391a24a (patch) | |
tree | f31f7b956455b1243d344d0c54d5b04e9e80fb3f /scripts/sock.js | |
parent | e5515d3e1603339b4957421c9494ca619490a03d (diff) |
Update from local repo
Diffstat (limited to 'scripts/sock.js')
-rw-r--r-- | scripts/sock.js | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/scripts/sock.js b/scripts/sock.js deleted file mode 100644 index cf06a5e..0000000 --- a/scripts/sock.js +++ /dev/null @@ -1,63 +0,0 @@ -// A wrapper around the wrapper -function SockWorker(serveraddr, version, callback) { - this.server = serveraddr; - this.version = version; - this.cb = callback; -} - -SockWorker.prototype = { - // Initialize the connection. - init: function() { - if(this.server == "" || this.server == null) { - return; - } - try { - this.socket = new WebSocket(this.server); - - this.socket.addEventListener("open", this.o.bind(this)); - this.socket.addEventListener("message", this.msg.bind(this)); - - this.socket.addEventListener("closed", this.c.bind(this)); - this.socket.addEventListener("error", this.err.bind(this)); - } catch (e) { - this.err(); - } - }, - - // Called when the connection connects to the server - o: function() { - this.send("version", this.version); - }, - - // Called when the connection gets a message from the server - // Attempts to turn the message into a usable object and pass it to the callback - msg: function(e) { - if(typeof e.data == "string") { - var dat = JSON.parse(e.data) - this.cb(dat); - } - }, - - // Called when the connection closes. - // Passes a close object to the callback. - c: function() { - this.cb({type: "close", data: ""}); - }, - - // Called when the connection encounters an error. - // Passes an error to the callback - err: function() { - this.cb({type: "error", data: ""}); - }, - - // Call to close the connection to the server - close: function() { - this.socket.close(); - }, - - // Send a message to the server - send: function(type, data) { - var m = new Message(type, data); - this.socket.send(m.stringify()) - } -};
\ No newline at end of file |