diff options
author | Kyle Gunger <corechg@gmail.com> | 2020-02-28 02:33:14 -0500 |
---|---|---|
committer | Kyle Gunger <corechg@gmail.com> | 2020-02-28 02:33:14 -0500 |
commit | ab88ba8d0e23999f4d55a2721f610eff2b1d2054 (patch) | |
tree | a98692cd60598d34c73b089ffac4dc263c13623c /scripts/sock.js | |
parent | a4d0d1190b74cd1bfb596b8a02a2deacce3ad86c (diff) |
More comments
Diffstat (limited to 'scripts/sock.js')
-rw-r--r-- | scripts/sock.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/scripts/sock.js b/scripts/sock.js index 78c4195..cf06a5e 100644 --- a/scripts/sock.js +++ b/scripts/sock.js @@ -1,3 +1,4 @@ +// A wrapper around the wrapper function SockWorker(serveraddr, version, callback) { this.server = serveraddr; this.version = version; @@ -5,6 +6,7 @@ function SockWorker(serveraddr, version, callback) { } SockWorker.prototype = { + // Initialize the connection. init: function() { if(this.server == "" || this.server == null) { return; @@ -22,10 +24,13 @@ SockWorker.prototype = { } }, + // 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) @@ -33,18 +38,24 @@ SockWorker.prototype = { } }, + // 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()) |