aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/connection.js
blob: 64d550bf4aa61cc0cabea27c1e6873782ce6a08e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
}
Connection.prototype.onopen = function (open) {
    console.debug("onopen", this, arguments);
};
Connection.prototype.onmessage = function (message) {
    console.warn("onmessage (not implemented)", this, message.data);
};
Connection.prototype.onerror = function (error) {
    EventLogActions.add_event("WebSocket Connection Error.");
    console.debug("onerror", this, arguments);
};
Connection.prototype.onclose = function (close) {
    EventLogActions.add_event("WebSocket Connection closed.");
    console.debug("onclose", this, arguments);
};
Connection.prototype.close = function(){
    this.ws.close();
};