@nxtedition/deepstream.io-client-js 23.3.6 → 23.4.0
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
CHANGED
package/src/default-options.js
CHANGED
|
@@ -32,8 +32,6 @@ const Connection = function (client, url, options) {
|
|
|
32
32
|
this._reconnectTimeout = null
|
|
33
33
|
this._reconnectionAttempt = 0
|
|
34
34
|
this._endpoint = null
|
|
35
|
-
this._lastHeartBeat = null
|
|
36
|
-
this._heartbeatInterval = null
|
|
37
35
|
|
|
38
36
|
this._processingRecv = false
|
|
39
37
|
this._recvMessages = this._recvMessages.bind(this)
|
|
@@ -96,7 +94,7 @@ Connection.prototype.sendMsg2 = function (topic, action, p0, p1) {
|
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
Connection.prototype.close = function () {
|
|
99
|
-
while (this._sendQueue.
|
|
97
|
+
while (!this._sendQueue.isEmpty()) {
|
|
100
98
|
this._submit(this._sendQueue.shift())
|
|
101
99
|
}
|
|
102
100
|
this._reset()
|
|
@@ -199,27 +197,8 @@ Connection.prototype._sendAuthParams = function () {
|
|
|
199
197
|
this._submit(authMessage)
|
|
200
198
|
}
|
|
201
199
|
|
|
202
|
-
Connection.prototype._checkHeartBeat = function () {
|
|
203
|
-
const heartBeatTolerance = this._options.heartbeatInterval * 3
|
|
204
|
-
|
|
205
|
-
if (Date.now() - this._lastHeartBeat > heartBeatTolerance) {
|
|
206
|
-
clearInterval(this._heartbeatInterval)
|
|
207
|
-
this._endpoint.close()
|
|
208
|
-
const err = new Error(`heartbeat not received in the last ${heartBeatTolerance} milliseconds`)
|
|
209
|
-
this._client._$onError(C.TOPIC.CONNECTION, C.EVENT.CONNECTION_ERROR, err)
|
|
210
|
-
} else {
|
|
211
|
-
this._submit(messageBuilder.getMsg(C.TOPIC.CONNECTION, C.ACTIONS.PING))
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
200
|
Connection.prototype._onOpen = function () {
|
|
216
201
|
this._clearReconnect()
|
|
217
|
-
this._lastHeartBeat = Date.now()
|
|
218
|
-
this._heartbeatInterval = setInterval(
|
|
219
|
-
this._checkHeartBeat.bind(this),
|
|
220
|
-
this._options.heartbeatInterval
|
|
221
|
-
)
|
|
222
|
-
this._heartbeatInterval.unref?.()
|
|
223
202
|
this._setState(C.CONNECTION_STATE.AWAITING_CONNECTION)
|
|
224
203
|
}
|
|
225
204
|
|
|
@@ -306,20 +285,13 @@ Connection.prototype._recvMessages = function (deadline) {
|
|
|
306
285
|
}
|
|
307
286
|
|
|
308
287
|
Connection.prototype._reset = function () {
|
|
309
|
-
clearInterval(this._heartbeatInterval)
|
|
310
|
-
this._heartbeatInterval = null
|
|
311
|
-
this._lastHeartBeat = null
|
|
312
|
-
|
|
313
288
|
this._recvQueue = new FixedQueue()
|
|
314
289
|
this._sendQueue = new FixedQueue()
|
|
315
290
|
}
|
|
316
291
|
|
|
317
292
|
Connection.prototype._handleConnectionResponse = function (message) {
|
|
318
293
|
if (message.action === C.ACTIONS.PING) {
|
|
319
|
-
this._lastHeartBeat = Date.now()
|
|
320
294
|
this._submit(messageBuilder.getMsg(C.TOPIC.CONNECTION, C.ACTIONS.PONG))
|
|
321
|
-
} else if (message.action === C.ACTIONS.PONG) {
|
|
322
|
-
this._lastHeartBeat = Date.now()
|
|
323
295
|
} else if (message.action === C.ACTIONS.ACK) {
|
|
324
296
|
this._setState(C.CONNECTION_STATE.AWAITING_AUTHENTICATION)
|
|
325
297
|
if (this._authParams) {
|
|
@@ -394,13 +366,10 @@ Connection.prototype._tryReconnect = function () {
|
|
|
394
366
|
|
|
395
367
|
if (this._reconnectionAttempt < this._options.maxReconnectAttempts) {
|
|
396
368
|
this._setState(C.CONNECTION_STATE.RECONNECTING)
|
|
397
|
-
this._reconnectTimeout = setTimeout(
|
|
398
|
-
this.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
this._options.reconnectIntervalIncrement * this._reconnectionAttempt
|
|
402
|
-
)
|
|
403
|
-
)
|
|
369
|
+
this._reconnectTimeout = setTimeout(() => {
|
|
370
|
+
this._reconnectTimeout = null
|
|
371
|
+
this._createEndpoint()
|
|
372
|
+
}, Math.min(this._options.maxReconnectInterval, this._options.reconnectIntervalIncrement * this._reconnectionAttempt))
|
|
404
373
|
this._reconnectionAttempt++
|
|
405
374
|
} else {
|
|
406
375
|
this._clearReconnect()
|
|
@@ -409,14 +378,11 @@ Connection.prototype._tryReconnect = function () {
|
|
|
409
378
|
}
|
|
410
379
|
}
|
|
411
380
|
|
|
412
|
-
Connection.prototype._tryOpen = function () {
|
|
413
|
-
this._createEndpoint()
|
|
414
|
-
this._reconnectTimeout = null
|
|
415
|
-
}
|
|
416
|
-
|
|
417
381
|
Connection.prototype._clearReconnect = function () {
|
|
418
|
-
|
|
419
|
-
|
|
382
|
+
if (this._reconnectTimeout) {
|
|
383
|
+
clearTimeout(this._reconnectTimeout)
|
|
384
|
+
this._reconnectTimeout = null
|
|
385
|
+
}
|
|
420
386
|
this._reconnectionAttempt = 0
|
|
421
387
|
}
|
|
422
388
|
|
|
@@ -24,7 +24,6 @@ class RecordHandler {
|
|
|
24
24
|
this._records = new Map()
|
|
25
25
|
this._listeners = new Map()
|
|
26
26
|
this._prune = new Map()
|
|
27
|
-
this._purge = new Set()
|
|
28
27
|
this._patch = new Set()
|
|
29
28
|
this._now = Date.now()
|
|
30
29
|
this._pruning = false
|
|
@@ -34,8 +33,6 @@ class RecordHandler {
|
|
|
34
33
|
updating: 0,
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
this._purgeCapacity = options.cacheSize
|
|
38
|
-
|
|
39
36
|
this._syncEmitter = new EventEmitter()
|
|
40
37
|
|
|
41
38
|
this.set = this.set.bind(this)
|
|
@@ -52,8 +49,6 @@ class RecordHandler {
|
|
|
52
49
|
this._client.on(C.EVENT.CONNECTED, this._onConnectionStateChange.bind(this))
|
|
53
50
|
|
|
54
51
|
const prune = () => {
|
|
55
|
-
this._pruning = false
|
|
56
|
-
|
|
57
52
|
let counter = 0
|
|
58
53
|
for (const [rec, timestamp] of this._prune) {
|
|
59
54
|
if (this._now - timestamp < 1e3) {
|
|
@@ -64,59 +59,26 @@ class RecordHandler {
|
|
|
64
59
|
continue
|
|
65
60
|
}
|
|
66
61
|
|
|
67
|
-
invariant(rec._refs === 0, 'record must have no refs')
|
|
68
|
-
|
|
69
62
|
rec._unsubscribe()
|
|
70
63
|
|
|
71
|
-
this.
|
|
64
|
+
this._records.delete(rec.name)
|
|
72
65
|
this._prune.delete(rec)
|
|
73
66
|
|
|
74
67
|
if (counter++ > 1024) {
|
|
75
|
-
this._pruning = true
|
|
76
68
|
this._schedule(prune)
|
|
77
69
|
return
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const purge = () => {
|
|
83
|
-
this._purging = false
|
|
84
|
-
|
|
85
|
-
if (!this._connected) {
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let counter = 0
|
|
90
|
-
for (const rec of this._purge) {
|
|
91
|
-
if (this._purge.size < this._purgeCapacity) {
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
72
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this._records.delete(rec.name)
|
|
98
|
-
this._purge.delete(rec)
|
|
99
|
-
|
|
100
|
-
if (counter++ > 1024) {
|
|
101
|
-
this._purging = true
|
|
102
|
-
this._schedule(purge)
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
}
|
|
73
|
+
this._pruning = false
|
|
106
74
|
}
|
|
107
75
|
|
|
108
76
|
const pruneInterval = setInterval(() => {
|
|
109
77
|
this._now = Date.now()
|
|
110
|
-
|
|
111
78
|
if (!this._pruning) {
|
|
112
79
|
this._pruning = true
|
|
113
80
|
this._schedule(prune)
|
|
114
81
|
}
|
|
115
|
-
|
|
116
|
-
if (!this._purging) {
|
|
117
|
-
this._purging = true
|
|
118
|
-
this._schedule(purge)
|
|
119
|
-
}
|
|
120
82
|
}, 1e3)
|
|
121
83
|
pruneInterval.unref?.()
|
|
122
84
|
}
|
|
@@ -125,7 +87,6 @@ class RecordHandler {
|
|
|
125
87
|
if (rec.refs === 0) {
|
|
126
88
|
this._prune.set(rec, this._now)
|
|
127
89
|
} else if (rec.refs === 1) {
|
|
128
|
-
this._purge.delete(rec)
|
|
129
90
|
this._prune.delete(rec)
|
|
130
91
|
}
|
|
131
92
|
}
|
|
@@ -140,7 +101,6 @@ class RecordHandler {
|
|
|
140
101
|
listeners: this._listeners.size,
|
|
141
102
|
records: this._records.size,
|
|
142
103
|
pruning: this._prune.size,
|
|
143
|
-
purging: this._purge.size,
|
|
144
104
|
}
|
|
145
105
|
}
|
|
146
106
|
|
|
@@ -423,6 +383,7 @@ class RecordHandler {
|
|
|
423
383
|
const record = this.getRecord(name)
|
|
424
384
|
|
|
425
385
|
record.subscribe(onUpdate)
|
|
386
|
+
record.unref()
|
|
426
387
|
|
|
427
388
|
if (timeout && state && record.state < state) {
|
|
428
389
|
timeoutHandle = setTimeout(() => {
|
|
@@ -444,7 +405,6 @@ class RecordHandler {
|
|
|
444
405
|
|
|
445
406
|
return () => {
|
|
446
407
|
record.unsubscribe(onUpdate)
|
|
447
|
-
record.unref()
|
|
448
408
|
}
|
|
449
409
|
})
|
|
450
410
|
|
package/src/record/record.js
CHANGED
|
@@ -61,12 +61,14 @@ class Record {
|
|
|
61
61
|
|
|
62
62
|
subscribe(fn) {
|
|
63
63
|
this._subscriptions.push(fn)
|
|
64
|
+
this.ref()
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
unsubscribe(fn) {
|
|
67
68
|
const idx = this._subscriptions.indexOf(fn)
|
|
68
69
|
if (idx !== -1) {
|
|
69
70
|
this._subscriptions.splice(idx, 1)
|
|
71
|
+
this.unref()
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
|
|
@@ -131,12 +133,10 @@ class Record {
|
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
this.unsubscribe(onUpdate)
|
|
134
|
-
this.unref()
|
|
135
136
|
|
|
136
137
|
resolve(null)
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
this.ref()
|
|
140
140
|
this.subscribe(onUpdate)
|
|
141
141
|
})
|
|
142
142
|
}
|