From 93b81dd53d577dcbd9109574136af27396dc48dc Mon Sep 17 00:00:00 2001 From: SirPython Date: Wed, 5 Aug 2015 21:34:09 -0400 Subject: [PATCH] added onReady to .init Now, when initializing the API, you can pass in a function to be run when the socket is ready. Also, now, if the socket were to fail, it is set to null in the API so the API's methods that interact with the socket will no longer work. --- server_interface/server_interface.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server_interface/server_interface.js b/server_interface/server_interface.js index c5da7d3..f9426dc 100644 --- a/server_interface/server_interface.js +++ b/server_interface/server_interface.js @@ -197,7 +197,7 @@ * up the websocket that will be used to communicate to the server, and to recieve * information from the server. */ - init: function(server, isSecure) { + init: function(server, isSecure, onReady) { var types = this.messageTypes; var self = this; // for the events @@ -224,6 +224,12 @@ self.incomingMessages.push(message); } + socket.onopen = onReady; + + socket.onerror = function() { + this.socket = null; + } + this.socket = socket; },