mitmproxy/web/src/js/connection.js

31 lines
944 B
JavaScript
Raw Normal View History

function _Connection(url) {
this.url = url;
}
_Connection.prototype.init=function() {
2014-09-16 09:06:30 +00:00
this.openWebSocketConnection();
};
_Connection.prototype.openWebSocketConnection=function() {
this.ws = new WebSocket(this.url.replace("http", "ws"));
2014-09-16 09:06:30 +00:00
var ws = this.ws;
2014-09-15 16:08:26 +00:00
2014-09-16 09:06:30 +00:00
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) {
2014-09-16 09:06:30 +00:00
console.log("onopen", this, arguments);
};
_Connection.prototype.onmessage=function(message) {
2014-09-16 09:06:30 +00:00
//AppDispatcher.dispatchServerAction(...);
console.log("onmessage", this, arguments);
};
_Connection.prototype.onerror=function(error) {
2014-09-16 09:06:30 +00:00
console.log("onerror", this, arguments);
};
_Connection.prototype.onclose=function(close) {
2014-09-16 09:06:30 +00:00
console.log("onclose", this, arguments);
};
var Connection = new _Connection(location.origin + "/updates");