diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2014-12-12 22:08:15 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2014-12-12 22:08:15 +1300 |
commit | 01fa5d3f07d26d52e5ad7eef139e1ed6f9b7dae1 (patch) | |
tree | 43c2460a9dc670421ee4e361b133a2aa45ae9e31 /web/src/js/connection.js | |
parent | 93d4a0132a1f31597fa24a5001c4c2b2cd752b4f (diff) | |
parent | dbb51640d967f7857ceb70b5b697e089085b7c6b (diff) | |
download | mitmproxy-01fa5d3f07d26d52e5ad7eef139e1ed6f9b7dae1.tar.gz mitmproxy-01fa5d3f07d26d52e5ad7eef139e1ed6f9b7dae1.tar.bz2 mitmproxy-01fa5d3f07d26d52e5ad7eef139e1ed6f9b7dae1.zip |
Merge pull request #414 from mitmproxy/flowviews2
Flowviews2
Diffstat (limited to 'web/src/js/connection.js')
-rw-r--r-- | web/src/js/connection.js | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/web/src/js/connection.js b/web/src/js/connection.js index 3edbfc20..6ca353b3 100644 --- a/web/src/js/connection.js +++ b/web/src/js/connection.js @@ -1,33 +1,24 @@ -function _Connection(url) { - this.url = url; -} -_Connection.prototype.init = function () { - this.openWebSocketConnection(); -}; -_Connection.prototype.openWebSocketConnection = function () { - this.ws = new WebSocket(this.url.replace("http", "ws")); - var ws = this.ws; +function Connection(url) { - ws.onopen = this.onopen.bind(this); - ws.onmessage = this.onmessage.bind(this); - ws.onerror = this.onerror.bind(this); - ws.onclose = this.onclose.bind(this); -}; -_Connection.prototype.onopen = function (open) { - console.debug("onopen", this, arguments); -}; -_Connection.prototype.onmessage = function (message) { - //AppDispatcher.dispatchServerAction(...); - var m = JSON.parse(message.data); - AppDispatcher.dispatchServerAction(m); -}; -_Connection.prototype.onerror = function (error) { - EventLogActions.add_event("WebSocket Connection Error."); - console.debug("onerror", this, arguments); -}; -_Connection.prototype.onclose = function (close) { - EventLogActions.add_event("WebSocket Connection closed."); - console.debug("onclose", this, arguments); -}; + if (url[0] === "/") { + url = location.origin.replace("http", "ws") + url; + } -var Connection = new _Connection(location.origin + "/updates"); + var ws = new WebSocket(url); + ws.onopen = function () { + ConnectionActions.open(); + }; + ws.onmessage = function (message) { + var m = JSON.parse(message.data); + AppDispatcher.dispatchServerAction(m); + }; + ws.onerror = function () { + ConnectionActions.error(); + EventLogActions.add_event("WebSocket connection error."); + }; + ws.onclose = function () { + ConnectionActions.close(); + EventLogActions.add_event("WebSocket connection closed."); + }; + return ws; +}
\ No newline at end of file |