openkbs-pulse 1.0.13 → 1.0.15
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.
- package/package.json +2 -1
- package/pulse.js +21 -0
- package/server.js +0 -7
package/package.json
CHANGED
package/pulse.js
CHANGED
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
*/
|
|
87
87
|
disconnect() {
|
|
88
88
|
this._intentionalClose = true;
|
|
89
|
+
this._stopHeartbeat();
|
|
89
90
|
this._setConnectionState('disconnecting');
|
|
90
91
|
|
|
91
92
|
if (this._ws) {
|
|
@@ -140,6 +141,9 @@
|
|
|
140
141
|
this._reconnectAttempt = 0;
|
|
141
142
|
this._setConnectionState('connected');
|
|
142
143
|
|
|
144
|
+
// Start heartbeat to keep connection alive
|
|
145
|
+
this._startHeartbeat();
|
|
146
|
+
|
|
143
147
|
// Resubscribe to all channels
|
|
144
148
|
Object.values(this._channels).forEach(channel => {
|
|
145
149
|
channel._resubscribe();
|
|
@@ -151,6 +155,7 @@
|
|
|
151
155
|
|
|
152
156
|
this._ws.onclose = (e) => {
|
|
153
157
|
this._log('Disconnected:', e.code, e.reason);
|
|
158
|
+
this._stopHeartbeat();
|
|
154
159
|
this._setConnectionState('disconnected');
|
|
155
160
|
|
|
156
161
|
if (!this._intentionalClose) {
|
|
@@ -234,6 +239,22 @@
|
|
|
234
239
|
}, delay);
|
|
235
240
|
}
|
|
236
241
|
|
|
242
|
+
_startHeartbeat() {
|
|
243
|
+
this._stopHeartbeat();
|
|
244
|
+
this._heartbeatInterval = setInterval(() => {
|
|
245
|
+
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
|
246
|
+
this._send({ action: 'ping' });
|
|
247
|
+
}
|
|
248
|
+
}, 25000); // Ping every 25 seconds
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_stopHeartbeat() {
|
|
252
|
+
if (this._heartbeatInterval) {
|
|
253
|
+
clearInterval(this._heartbeatInterval);
|
|
254
|
+
this._heartbeatInterval = null;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
237
258
|
_setConnectionState(state) {
|
|
238
259
|
if (this._connectionState !== state) {
|
|
239
260
|
this._connectionState = state;
|