aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/connection.js
blob: a4369b5ad91f499ad6e91e951cf6ae40da32b2fa (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) {
    this.url = url;
}
_Connection.prototype.init = function () {
    this.openWebSocketConnection();
};
_Connection.prototype.openWebSocketConnection = function () {
    this.ws = new WebSocket(this.url.replace("http", "ws"));
    var ws = this.ws;

    ws.onopen = this.onopen.bind(this);
    ws.onmessage = this.onmessage.bind(this);
    ws.onerror = this.onerror.bind(this);
    ws.onclose = this.onclose.bind(this);
};
_Connection.prototype.onopen = function (open) {
    console.log("onopen", this, arguments);
};
_Connection.prototype.onmessage = function (message) {
    //AppDispatcher.dispatchServerAction(...);
    var m = JSON.parse(message.data);
    switch (m.type){
        case "flow":
            console.log("flow", m.data);
            break;
        case "event":
            console.log("event", m.data.message)
            break;
    }
};
_Connection.prototype.onerror = function (error) {
    console.log("onerror", this, arguments);
};
_Connection.prototype.onclose = function (close) {
    console.log("onclose", this, arguments);
};

var Connection = new _Connection(location.origin + "/updates");