diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2014-09-17 09:40:25 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2014-09-17 09:40:25 +1200 |
commit | f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63 (patch) | |
tree | 956984514258b8ebde4548b2032202447ee37dc7 /web/src/js/connection.js | |
parent | 4f56b76b2c811006045c3226848aa5e122fb36ab (diff) | |
download | mitmproxy-f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63.tar.gz mitmproxy-f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63.tar.bz2 mitmproxy-f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63.zip |
Basic websocket connection, code cleanup.
Diffstat (limited to 'web/src/js/connection.js')
-rw-r--r-- | web/src/js/connection.js | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/web/src/js/connection.js b/web/src/js/connection.js index 3911d3f2..e752e2fe 100644 --- a/web/src/js/connection.js +++ b/web/src/js/connection.js @@ -1,14 +1,11 @@ -function _Connection(root) {"use strict"; - if (!root) { - root = location.origin + "/api/v1"; - } - this.root = root; - } -_Connection.prototype.init=function() {"use strict"; +function _Connection(url) { + this.url = url; +} +_Connection.prototype.init=function() { this.openWebSocketConnection(); }; -_Connection.prototype.openWebSocketConnection=function() {"use strict"; - this.ws = new WebSocket(this.root.replace("http", "ws") + "/ws"); +_Connection.prototype.openWebSocketConnection=function() { + this.ws = new WebSocket(this.url.replace("http", "ws")); var ws = this.ws; ws.onopen = this.onopen.bind(this); @@ -16,18 +13,18 @@ _Connection.prototype.openWebSocketConnection=function() {"use strict"; ws.onerror = this.onerror.bind(this); ws.onclose = this.onclose.bind(this); }; -_Connection.prototype.onopen=function(open) {"use strict"; +_Connection.prototype.onopen=function(open) { console.log("onopen", this, arguments); }; -_Connection.prototype.onmessage=function(message) {"use strict"; +_Connection.prototype.onmessage=function(message) { //AppDispatcher.dispatchServerAction(...); console.log("onmessage", this, arguments); }; -_Connection.prototype.onerror=function(error) {"use strict"; +_Connection.prototype.onerror=function(error) { console.log("onerror", this, arguments); }; -_Connection.prototype.onclose=function(close) {"use strict"; +_Connection.prototype.onclose=function(close) { console.log("onclose", this, arguments); }; -var Connection = new _Connection(); +var Connection = new _Connection(location.origin + "/updates"); |