@nxtedition/deepstream.io-client-js 23.4.53 → 23.4.55

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "23.4.53",
3
+ "version": "23.4.55",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -21,7 +21,6 @@ const Connection = function (client, url, options) {
21
21
  this._tooManyAuthAttempts = false
22
22
  this._connectionAuthenticationTimeout = false
23
23
  this._challengeDenied = false
24
- this._sendQueue = new FixedQueue()
25
24
  this._message = {
26
25
  raw: null,
27
26
  topic: null,
@@ -35,8 +34,6 @@ const Connection = function (client, url, options) {
35
34
 
36
35
  this._processingRecv = false
37
36
  this._recvMessages = this._recvMessages.bind(this)
38
- this._processingSend = false
39
- this._sendMessages = this._sendMessages.bind(this)
40
37
 
41
38
  this._url = new URL(url)
42
39
 
@@ -82,22 +79,18 @@ Connection.prototype.authenticate = function (authParams, callback) {
82
79
  }
83
80
 
84
81
  Connection.prototype.sendMsg = function (topic, action, data) {
85
- this.send(messageBuilder.getMsg(topic, action, data))
82
+ return this.send(messageBuilder.getMsg(topic, action, data))
86
83
  }
87
84
 
88
85
  Connection.prototype.sendMsg1 = function (topic, action, p0) {
89
- this.send(messageBuilder.getMsg1(topic, action, p0))
86
+ return this.send(messageBuilder.getMsg1(topic, action, p0))
90
87
  }
91
88
 
92
89
  Connection.prototype.sendMsg2 = function (topic, action, p0, p1) {
93
- this.send(messageBuilder.getMsg2(topic, action, p0, p1))
90
+ return this.send(messageBuilder.getMsg2(topic, action, p0, p1))
94
91
  }
95
92
 
96
93
  Connection.prototype.close = function () {
97
- while (!this._sendQueue.isEmpty()) {
98
- this._submit(this._sendQueue.shift())
99
- }
100
- this._reset()
101
94
  this._deliberateClose = true
102
95
  this._endpoint?.close()
103
96
 
@@ -133,48 +126,16 @@ Connection.prototype.send = function (message) {
133
126
  err,
134
127
  message.split(C.MESSAGE_PART_SEPERATOR).map((x) => x.slice(0, 256))
135
128
  )
136
- return
129
+ return false
137
130
  }
138
131
 
139
- if (this._processingSend) {
140
- this._sendQueue.push(message)
141
- } else if (
132
+ if (
142
133
  this._state === C.CONNECTION_STATE.OPEN &&
143
134
  this._endpoint.readyState === this._endpoint.OPEN
144
135
  ) {
145
- this._submit(message)
146
- } else {
147
- this._sendQueue.push(message)
148
- this._processingSend = true
149
- this._sendMessages()
150
- }
151
- }
152
-
153
- Connection.prototype._sendMessages = function (deadline) {
154
- if (
155
- this._state !== C.CONNECTION_STATE.OPEN ||
156
- this._endpoint.readyState !== this._endpoint.OPEN
157
- ) {
158
- this._processingSend = false
159
- return
160
- }
161
-
162
- for (
163
- let n = 0;
164
- // eslint-disable-next-line no-unmodified-loop-condition
165
- n < this._batchSize && (!deadline || deadline.timeRemaining() || deadline.didTimeout);
166
- ++n
167
- ) {
168
- const message = this._sendQueue.shift()
169
- if (!message) {
170
- this._processingSend = false
171
- return
172
- }
173
-
174
- this._submit(message)
136
+ this.emit('send', message)
137
+ this._endpoint.send(message)
175
138
  }
176
-
177
- this._schedule(this._sendMessages)
178
139
  }
179
140
 
180
141
  Connection.prototype._submit = function (message) {
@@ -183,12 +144,15 @@ Connection.prototype._submit = function (message) {
183
144
  if (message.length > maxPacketSize) {
184
145
  const err = new Error(`Packet to big: ${message.length} > ${maxPacketSize}`)
185
146
  this._client._$onError(C.TOPIC.CONNECTION, C.EVENT.CONNECTION_ERROR, err)
147
+ return false
186
148
  } else if (this._endpoint.readyState === this._endpoint.OPEN) {
187
149
  this.emit('send', message)
188
150
  this._endpoint.send(message)
151
+ return true
189
152
  } else {
190
153
  const err = new Error('Tried to send message on a closed websocket connection')
191
154
  this._client._$onError(C.TOPIC.CONNECTION, C.EVENT.CONNECTION_ERROR, err)
155
+ return false
192
156
  }
193
157
  }
194
158
 
@@ -210,7 +174,7 @@ Connection.prototype._onOpen = function () {
210
174
  }
211
175
 
212
176
  Connection.prototype._onError = function (err) {
213
- this._reset()
177
+ this._recvMessages()
214
178
 
215
179
  if (err.error) {
216
180
  const { message, error } = err
@@ -232,7 +196,7 @@ Connection.prototype._onError = function (err) {
232
196
  }
233
197
 
234
198
  Connection.prototype._onClose = function () {
235
- this._reset()
199
+ this._recvMessages()
236
200
 
237
201
  if (this._deliberateClose === true) {
238
202
  this._setState(C.CONNECTION_STATE.CLOSED)
@@ -291,11 +255,6 @@ Connection.prototype._recvMessages = function (deadline) {
291
255
  this._schedule(this._recvMessages)
292
256
  }
293
257
 
294
- Connection.prototype._reset = function () {
295
- this._recvQueue = new FixedQueue()
296
- this._sendQueue = new FixedQueue()
297
- }
298
-
299
258
  Connection.prototype._handleConnectionResponse = function (message) {
300
259
  if (message.action === C.ACTIONS.PING) {
301
260
  this._submit(messageBuilder.getMsg(C.TOPIC.CONNECTION, C.ACTIONS.PONG))
@@ -363,7 +322,6 @@ Connection.prototype._setState = function (state) {
363
322
  this._client.emit(C.EVENT.CONNECTED, true)
364
323
  } else if (state === C.CONNECTION_STATE.RECONNECTING || state === C.CONNECTION_STATE.CLOSED) {
365
324
  this._client.emit(C.EVENT.CONNECTED, false)
366
- this._reset()
367
325
  }
368
326
  }
369
327
 
@@ -162,10 +162,7 @@ class RecordHandler {
162
162
 
163
163
  const token = xuid()
164
164
  this._syncEmitter.once(token, resolve)
165
-
166
- if (this._connected) {
167
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
168
- }
165
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
169
166
  }
170
167
 
171
168
  for (const rec of this._pending) {
@@ -22,11 +22,9 @@ class Record {
22
22
  this._updating = null
23
23
  this._patching = null
24
24
  this._pending = false
25
- this._subscribed = false
25
+ this._subscribed = this._sendMsg1(C.ACTIONS.SUBSCRIBE, this._name)
26
26
 
27
27
  this._onPending(true)
28
-
29
- this._subscribe()
30
28
  }
31
29
 
32
30
  get name() {
@@ -56,7 +54,7 @@ class Record {
56
54
  }
57
55
 
58
56
  if (!this._subscribed) {
59
- this._subscribe()
57
+ this._subscribed = this._sendMsg1(C.ACTIONS.SUBSCRIBE, this._name)
60
58
  }
61
59
 
62
60
  return this
@@ -235,13 +233,11 @@ class Record {
235
233
 
236
234
  _$onConnectionStateChange(connected) {
237
235
  if (connected) {
238
- if (this._refs > 0) {
239
- this._subscribe()
240
- }
236
+ this._subscribed = this._refs > 0 && this._sendMsg1(C.ACTIONS.SUBSCRIBE, this._name)
241
237
 
242
238
  if (this._updating) {
243
239
  for (const update of this._updating.values()) {
244
- this._handler._connection.connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, update)
240
+ this._sendMsg1(C.ACTIONS.UPDATE, update)
245
241
  }
246
242
  }
247
243
  } else {
@@ -258,29 +254,14 @@ class Record {
258
254
  }
259
255
  }
260
256
 
261
- _subscribe() {
262
- if (!this._handler._connection.connected) {
263
- return
264
- }
265
-
266
- invariant(this._handler._connection.connected, 'must be connected')
267
-
268
- this._handler._connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
269
- this._subscribed = true
270
- }
271
-
272
257
  _$dispose() {
273
258
  invariant(!this._refs, 'must not have refs')
274
259
  invariant(!this._patching, 'must not have patches')
275
260
  invariant(!this._updating, 'must not have updates')
276
261
  invariant(!this._pending, 'must not be pending')
277
- invariant(
278
- !this._subscribed || this._handler._connection.connected,
279
- 'must be unsubscribed or connected'
280
- )
281
262
 
282
263
  if (this._subscribed) {
283
- this._handler._connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, this._name)
264
+ this._sendMsg1(C.ACTIONS.UNSUBSCRIBE, this._name)
284
265
  this._subscribed = false
285
266
  }
286
267
 
@@ -293,6 +274,8 @@ class Record {
293
274
  _update(nextData) {
294
275
  invariant(this._version, 'must have version')
295
276
 
277
+ const connection = this._handler._connection
278
+
296
279
  if (nextData === this._data) {
297
280
  return
298
281
  }
@@ -310,10 +293,7 @@ class Record {
310
293
  this._updating.set(nextVersion, update)
311
294
  this._handler._stats.updating += 1
312
295
 
313
- const connection = this._handler._connection
314
- if (connection.connected) {
315
- connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, update)
316
- }
296
+ connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, update)
317
297
 
318
298
  this._data = nextData
319
299
  this._version = nextVersion
@@ -404,6 +384,10 @@ class Record {
404
384
  }
405
385
  }
406
386
 
387
+ _sendMsg1(action, data) {
388
+ return this._handler._connection.sendMsg1(C.TOPIC.RECORD, action, data)
389
+ }
390
+
407
391
  _error(event, msgOrError, data) {
408
392
  this._handler._client._$onError(C.TOPIC.RECORD, event, msgOrError, [
409
393
  ...(Array.isArray(data) ? data : []),