mitmproxy/web/src/js/connection.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

function Connection(url) {
2014-11-27 00:40:26 +00:00
if (url[0] != "/") {
this.url = url;
} else {
this.url = location.origin.replace("http", "ws") + url;
}
var ws = new WebSocket(this.url);
2014-11-27 00:40:26 +00:00
ws.onopen = function () {
this.onopen.apply(this, arguments);
}.bind(this);
2014-11-27 00:40:26 +00:00
ws.onmessage = function () {
this.onmessage.apply(this, arguments);
}.bind(this);
2014-11-27 00:40:26 +00:00
ws.onerror = function () {
this.onerror.apply(this, arguments);
}.bind(this);
2014-11-27 00:40:26 +00:00
ws.onclose = function () {
this.onclose.apply(this, arguments);
}.bind(this);
this.ws = ws;
}
Connection.prototype.onopen = function (open) {
2014-09-22 01:06:19 +00:00
console.debug("onopen", this, arguments);
2014-09-16 09:06:30 +00:00
};
Connection.prototype.onmessage = function (message) {
console.warn("onmessage (not implemented)", this, message.data);
2014-09-16 09:06:30 +00:00
};
Connection.prototype.onerror = function (error) {
2014-09-17 15:30:19 +00:00
EventLogActions.add_event("WebSocket Connection Error.");
2014-09-22 01:06:19 +00:00
console.debug("onerror", this, arguments);
2014-09-16 09:06:30 +00:00
};
Connection.prototype.onclose = function (close) {
2014-09-17 15:30:19 +00:00
EventLogActions.add_event("WebSocket Connection closed.");
2014-09-22 01:06:19 +00:00
console.debug("onclose", this, arguments);
2014-09-16 09:06:30 +00:00
};
2014-11-27 00:40:26 +00:00
Connection.prototype.close = function () {
this.ws.close();
};