diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-12-09 18:18:14 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-12-09 18:18:14 +0100 |
commit | 14a8d2f5b83a1ea28abbb490f6c94c43b4e1f960 (patch) | |
tree | c114643959a6223289e8287e9daaa1b65a377356 /web/src/js/connection.js | |
parent | 096a3af273ccb309820351b466e62382f62a2c36 (diff) | |
download | mitmproxy-14a8d2f5b83a1ea28abbb490f6c94c43b4e1f960.tar.gz mitmproxy-14a8d2f5b83a1ea28abbb490f6c94c43b4e1f960.tar.bz2 mitmproxy-14a8d2f5b83a1ea28abbb490f6c94c43b4e1f960.zip |
always use the app dispatcher
Diffstat (limited to 'web/src/js/connection.js')
-rw-r--r-- | web/src/js/connection.js | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/web/src/js/connection.js b/web/src/js/connection.js index d511270d..6ca353b3 100644 --- a/web/src/js/connection.js +++ b/web/src/js/connection.js @@ -1,38 +1,24 @@ function Connection(url) { - if (url[0] != "/") { - this.url = url; - } else { - this.url = location.origin.replace("http", "ws") + url; + + if (url[0] === "/") { + url = location.origin.replace("http", "ws") + url; } - var ws = new WebSocket(this.url); + + var ws = new WebSocket(url); ws.onopen = function () { - this.onopen.apply(this, arguments); - }.bind(this); - ws.onmessage = function () { - this.onmessage.apply(this, arguments); - }.bind(this); + ConnectionActions.open(); + }; + ws.onmessage = function (message) { + var m = JSON.parse(message.data); + AppDispatcher.dispatchServerAction(m); + }; ws.onerror = function () { - this.onerror.apply(this, arguments); - }.bind(this); + ConnectionActions.error(); + EventLogActions.add_event("WebSocket connection error."); + }; ws.onclose = function () { - this.onclose.apply(this, arguments); - }.bind(this); - this.ws = ws; -} -Connection.prototype.onopen = function (open) { - console.debug("onopen", this, arguments); -}; -Connection.prototype.onmessage = function (message) { - console.warn("onmessage (not implemented)", this, message.data); -}; -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); -}; -Connection.prototype.close = function () { - this.ws.close(); -};
\ No newline at end of file + ConnectionActions.close(); + EventLogActions.add_event("WebSocket connection closed."); + }; + return ws; +}
\ No newline at end of file |