blob: 9daa82e2ddc15c3ad51c054375a4365bd38fd1d2 (
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
|
class Connection {
constructor(root){
if(!root){
root = location.origin + "/api/v1";
}
this.root = root;
this.openWebSocketConnection();
}
openWebSocketConnection(){
this.ws = new WebSocket(this.root.replace("http","ws") + "/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);
}
onopen(open){
console.log("onopen", this, arguments);
}
onmessage(message){
console.log("onmessage", this, arguments);
}
onerror(error){
console.log("onerror", this, arguments);
}
onclose(close){
console.log("onclose", this, arguments);
}
}
|