mitmproxy/web/src/js/connection.js

28 lines
749 B
JavaScript
Raw Normal View History

2014-12-09 17:18:14 +00:00
var actions = require("./actions.js");
function Connection(url) {
2014-12-09 17:18:14 +00:00
if (url[0] === "/") {
url = location.origin.replace("http", "ws") + url;
}
2014-12-09 17:18:14 +00:00
var ws = new WebSocket(url);
2014-11-27 00:40:26 +00:00
ws.onopen = function () {
actions.ConnectionActions.open();
2014-12-09 17:18:14 +00:00
};
ws.onmessage = function (message) {
var m = JSON.parse(message.data);
AppDispatcher.dispatchServerAction(m);
};
2014-11-27 00:40:26 +00:00
ws.onerror = function () {
actions.ConnectionActions.error();
2014-12-09 17:18:14 +00:00
EventLogActions.add_event("WebSocket connection error.");
};
2014-11-27 00:40:26 +00:00
ws.onclose = function () {
actions.ConnectionActions.close();
2014-12-09 17:18:14 +00:00
EventLogActions.add_event("WebSocket connection closed.");
};
return ws;
}
module.exports = Connection;