mitmproxy/web/src/js/connection.js

32 lines
996 B
JavaScript
Raw Normal View History

function _Connection(url) {
this.url = url;
}
2014-09-17 00:13:37 +00:00
_Connection.prototype.init = function () {
2014-09-16 09:06:30 +00:00
this.openWebSocketConnection();
};
2014-09-17 00:13:37 +00:00
_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);
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.onopen = function (open) {
2014-09-16 09:06:30 +00:00
console.log("onopen", this, arguments);
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.onmessage = function (message) {
2014-09-16 09:06:30 +00:00
//AppDispatcher.dispatchServerAction(...);
var m = JSON.parse(message.data);
2014-09-17 13:22:42 +00:00
AppDispatcher.dispatchServerAction(m);
2014-09-16 09:06:30 +00:00
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.onerror = function (error) {
2014-09-16 09:06:30 +00:00
console.log("onerror", this, arguments);
};
2014-09-17 00:13:37 +00:00
_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");