From f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 17 Sep 2014 09:40:25 +1200 Subject: Basic websocket connection, code cleanup. --- libmproxy/web/static/js/app.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'libmproxy/web/static/js/app.js') diff --git a/libmproxy/web/static/js/app.js b/libmproxy/web/static/js/app.js index c095fd44..6a157b24 100644 --- a/libmproxy/web/static/js/app.js +++ b/libmproxy/web/static/js/app.js @@ -198,17 +198,14 @@ _.extend(_EventLogStore.prototype, EventEmitter.prototype, { var EventLogStore = new _EventLogStore(); AppDispatcher.register(EventLogStore.handle.bind(EventLogStore)); -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); @@ -216,21 +213,21 @@ _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"); /** @jsx React.DOM */ -- cgit v1.2.3