2014-11-26 03:18:21 +00:00
|
|
|
function Connection(url) {
|
|
|
|
if(url[0] != "/"){
|
|
|
|
this.url = url;
|
|
|
|
} else {
|
|
|
|
this.url = location.origin.replace("http", "ws") + url;
|
|
|
|
}
|
|
|
|
var ws = new WebSocket(this.url);
|
|
|
|
ws.onopen = function(){
|
|
|
|
this.onopen.apply(this, arguments);
|
|
|
|
}.bind(this);
|
|
|
|
ws.onmessage = function(){
|
|
|
|
this.onmessage.apply(this, arguments);
|
|
|
|
}.bind(this);
|
|
|
|
ws.onerror = function(){
|
|
|
|
this.onerror.apply(this, arguments);
|
|
|
|
}.bind(this);
|
|
|
|
ws.onclose = function(){
|
|
|
|
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-26 03:18:21 +00:00
|
|
|
Connection.prototype.close = function(){
|
|
|
|
this.ws.close();
|
|
|
|
};
|