2014-11-26 03:18:21 +00:00
|
|
|
function Connection(url) {
|
2014-11-27 00:40:26 +00:00
|
|
|
if (url[0] != "/") {
|
2014-11-26 03:18:21 +00:00
|
|
|
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 () {
|
2014-11-26 03:18:21 +00:00
|
|
|
this.onopen.apply(this, arguments);
|
|
|
|
}.bind(this);
|
2014-11-27 00:40:26 +00:00
|
|
|
ws.onmessage = function () {
|
2014-11-26 03:18:21 +00:00
|
|
|
this.onmessage.apply(this, arguments);
|
|
|
|
}.bind(this);
|
2014-11-27 00:40:26 +00:00
|
|
|
ws.onerror = function () {
|
2014-11-26 03:18:21 +00:00
|
|
|
this.onerror.apply(this, arguments);
|
|
|
|
}.bind(this);
|
2014-11-27 00:40:26 +00:00
|
|
|
ws.onclose = function () {
|
2014-11-26 03:18:21 +00:00
|
|
|
this.onclose.apply(this, arguments);
|
|
|
|
}.bind(this);
|
|
|
|
this.ws = ws;
|
2014-09-16 21:40:25 +00:00
|
|
|
}
|
2014-11-26 03:18:21 +00:00
|
|
|
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
|
|
|
};
|
2014-11-26 03:18:21 +00:00
|
|
|
Connection.prototype.onmessage = function (message) {
|
|
|
|
console.warn("onmessage (not implemented)", this, message.data);
|
2014-09-16 09:06:30 +00:00
|
|
|
};
|
2014-11-26 03:18:21 +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
|
|
|
};
|
2014-11-26 03:18:21 +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 () {
|
2014-11-26 03:18:21 +00:00
|
|
|
this.ws.close();
|
|
|
|
};
|