dbm 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,22 +4,39 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
4
4
|
_construct() {
|
|
5
5
|
super._construct();
|
|
6
6
|
|
|
7
|
+
this._url = null;
|
|
7
8
|
this._webSocket = null;
|
|
9
|
+
|
|
10
|
+
this._intervalId = -1;
|
|
8
11
|
this._callback_onOpenBound = this._callback_onOpen.bind(this);
|
|
9
12
|
this._callback_onMessageBound = this._callback_onMessage.bind(this);
|
|
13
|
+
this._callback_onMessageBound = this._callback_onMessage.bind(this);
|
|
14
|
+
this._callback_onCloseBound = this._callback_onClose.bind(this);
|
|
15
|
+
this._callback_onErrorBound = this._callback_onError.bind(this);
|
|
16
|
+
this._callback_sendHeartbeatBound = this._callback_sendHeartbeat.bind(this);
|
|
10
17
|
|
|
11
18
|
this.item.setValue("requests", []);
|
|
12
19
|
this.item.setValue("status", 0);
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
setup(aUrl) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this._webSocket.onopen = this._callback_onOpenBound;
|
|
20
|
-
this._webSocket.onmessage = this._callback_onMessageBound;
|
|
23
|
+
this._url = aUrl;
|
|
24
|
+
this._connect();
|
|
25
|
+
|
|
21
26
|
return this;
|
|
22
27
|
}
|
|
28
|
+
|
|
29
|
+
_connect() {
|
|
30
|
+
if(this.item.status === 0) {
|
|
31
|
+
this._webSocket = new WebSocket(this._url);
|
|
32
|
+
this.item.setValue("status", 2);
|
|
33
|
+
|
|
34
|
+
this._webSocket.onopen = this._callback_onOpenBound;
|
|
35
|
+
this._webSocket.onmessage = this._callback_onMessageBound;
|
|
36
|
+
this._webSocket.onclose = this._callback_onCloseBound;
|
|
37
|
+
this._webSocket.onerror = this._callback_onErrorBound;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
23
40
|
|
|
24
41
|
_getRequestItem() {
|
|
25
42
|
let requestId = "graphApi/webSocketRequest" + Dbm.getInstance().getNextId();
|
|
@@ -94,10 +111,47 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
94
111
|
}
|
|
95
112
|
|
|
96
113
|
_callback_onOpen(aEvent) {
|
|
97
|
-
|
|
114
|
+
console.log("_callback_onOpen");
|
|
115
|
+
|
|
116
|
+
if(this._intervalId === -1) {
|
|
117
|
+
this._intervalId = setInterval(this._callback_sendHeartbeatBound, 20*1000);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_callback_onClose(aEvent) {
|
|
122
|
+
console.log("_callback_onClose");
|
|
123
|
+
console.log(aEvent);
|
|
124
|
+
|
|
125
|
+
if(this._intervalId !== -1) {
|
|
126
|
+
clearInterval(this._intervalId);
|
|
127
|
+
this._intervalId = -1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if(this._webSocket) {
|
|
131
|
+
this._webSocket.onopen = null;
|
|
132
|
+
this._webSocket.onmessage = null;
|
|
133
|
+
this._webSocket.onclose = null;
|
|
134
|
+
this._webSocket.onerror = null;
|
|
135
|
+
|
|
136
|
+
this._webSocket = null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.item.setValue("status", 0);
|
|
140
|
+
this._connect();;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_callback_onError(aEvent) {
|
|
144
|
+
console.log("_callback_onError");
|
|
145
|
+
console.log(aEvent);
|
|
98
146
|
|
|
99
147
|
//MENOTE: do nothing
|
|
100
148
|
}
|
|
149
|
+
|
|
150
|
+
_callback_sendHeartbeat() {
|
|
151
|
+
console.log("_callback_sendHeartbeat");
|
|
152
|
+
|
|
153
|
+
this._webSocket.send(JSON.stringify({"type": "heartbeat"}));
|
|
154
|
+
}
|
|
101
155
|
|
|
102
156
|
_connectionReady() {
|
|
103
157
|
this.item.setValue("status", 1);
|
|
@@ -213,6 +267,9 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
213
267
|
this._connectionReady();
|
|
214
268
|
}
|
|
215
269
|
break;
|
|
270
|
+
case "heartbeat/response":
|
|
271
|
+
//MENOTE: do nothing
|
|
272
|
+
break;
|
|
216
273
|
default:
|
|
217
274
|
console.warn("Unknown message type " + data.type);
|
|
218
275
|
break;
|