aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/connection.js
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-11-26 04:18:21 +0100
committerMaximilian Hils <git@maximilianhils.com>2014-11-26 04:18:21 +0100
commited8249023fb7c0d429b9278c63b51ac071700987 (patch)
tree8bd83354e7484f15029ec678744234bd32e9906d /web/src/js/connection.js
parent47a78e3c729f4ddb7971b72bfae30140562f4dd6 (diff)
downloadmitmproxy-ed8249023fb7c0d429b9278c63b51ac071700987.tar.gz
mitmproxy-ed8249023fb7c0d429b9278c63b51ac071700987.tar.bz2
mitmproxy-ed8249023fb7c0d429b9278c63b51ac071700987.zip
introduce revised views, port over changes from multiple_views branch
Diffstat (limited to 'web/src/js/connection.js')
-rw-r--r--web/src/js/connection.js51
1 files changed, 28 insertions, 23 deletions
diff --git a/web/src/js/connection.js b/web/src/js/connection.js
index 3edbfc20..64d550bf 100644
--- a/web/src/js/connection.js
+++ b/web/src/js/connection.js
@@ -1,33 +1,38 @@
-function _Connection(url) {
- this.url = url;
+function Connection(url) {
+ if(url[0] != "/"){
+ this.url = url;
+ } else {
+ this.url = location.origin.replace("http", "ws") + url;
+ }
+ var ws = new WebSocket(this.url);
+ ws.onopen = function(){
+ this.onopen.apply(this, arguments);
+ }.bind(this);
+ ws.onmessage = function(){
+ this.onmessage.apply(this, arguments);
+ }.bind(this);
+ ws.onerror = function(){
+ this.onerror.apply(this, arguments);
+ }.bind(this);
+ ws.onclose = function(){
+ this.onclose.apply(this, arguments);
+ }.bind(this);
+ this.ws = ws;
}
-_Connection.prototype.init = function () {
- this.openWebSocketConnection();
-};
-_Connection.prototype.openWebSocketConnection = function () {
- this.ws = new WebSocket(this.url.replace("http", "ws"));
- var ws = this.ws;
-
- 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) {
+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.onmessage = function (message) {
+ console.warn("onmessage (not implemented)", this, message.data);
};
-_Connection.prototype.onerror = function (error) {
+Connection.prototype.onerror = function (error) {
EventLogActions.add_event("WebSocket Connection Error.");
console.debug("onerror", this, arguments);
};
-_Connection.prototype.onclose = function (close) {
+Connection.prototype.onclose = function (close) {
EventLogActions.add_event("WebSocket Connection closed.");
console.debug("onclose", this, arguments);
};
-
-var Connection = new _Connection(location.origin + "/updates");
+Connection.prototype.close = function(){
+ this.ws.close();
+}; \ No newline at end of file