@nxtedition/deepstream.io-client-js 24.2.4 → 24.2.6

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": "24.2.4",
3
+ "version": "24.2.6",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -101,19 +101,21 @@ Connection.prototype.close = function () {
101
101
  }
102
102
 
103
103
  Connection.prototype._createEndpoint = function () {
104
- this._endpoint = NodeWebSocket
105
- ? new NodeWebSocket(this._url, {
106
- generateMask() {},
107
- })
108
- : new BrowserWebSocket(this._url)
104
+ if (NodeWebSocket) {
105
+ this._endpoint = new NodeWebSocket(this._url, {
106
+ generateMask() {},
107
+ })
108
+ this._endpoint.onmessage = ({ data }) => this._onMessage(data)
109
+ } else {
110
+ this._endpoint = new BrowserWebSocket(this._url)
111
+ this._endpoint.binaryType = 'arraybuffer'
112
+ this._endpoint.onmessage = ({ data }) => this._onMessage(Buffer.from(data))
113
+ }
109
114
  this._corked = false
110
115
 
111
116
  this._endpoint.onopen = this._onOpen.bind(this)
112
117
  this._endpoint.onerror = this._onError.bind(this)
113
118
  this._endpoint.onclose = this._onClose.bind(this)
114
- this._endpoint.onmessage = BrowserWebSocket
115
- ? ({ data }) => this._onMessage(typeof data === 'string' ? data : Buffer.from(data).toString())
116
- : ({ data }) => this._onMessage(typeof data === 'string' ? data : data.toString())
117
119
  }
118
120
 
119
121
  Connection.prototype.send = function (message) {
@@ -249,20 +251,20 @@ Connection.prototype._recvMessages = function (deadline) {
249
251
  continue
250
252
  }
251
253
 
252
- if (this._logger) {
253
- this._logger.trace(message, 'receive')
254
- }
254
+ try {
255
+ messageParser.parseMessage(message, this._client, this._message)
255
256
 
256
- messageParser.parseMessage(message, this._client, this._message)
257
+ this.emit('recv', this._message)
257
258
 
258
- this.emit('recv', this._message)
259
-
260
- if (this._message.topic === C.TOPIC.CONNECTION) {
261
- this._handleConnectionResponse(this._message)
262
- } else if (this._message.topic === C.TOPIC.AUTH) {
263
- this._handleAuthResponse(this._message)
264
- } else {
265
- this._client._$onMessage(this._message)
259
+ if (this._message.topic === C.TOPIC.CONNECTION) {
260
+ this._handleConnectionResponse(this._message)
261
+ } else if (this._message.topic === C.TOPIC.AUTH) {
262
+ this._handleAuthResponse(this._message)
263
+ } else {
264
+ this._client._$onMessage(this._message)
265
+ }
266
+ } catch (err) {
267
+ this._onError(err)
266
268
  }
267
269
  }
268
270
 
@@ -97,11 +97,19 @@ class RecordHandler {
97
97
  this._connection = connection
98
98
  this._client = client
99
99
  this._records = new Map()
100
+ this._cache = new Map()
100
101
  this._listeners = new Map()
101
102
  this._pruning = new Set()
102
103
  this._patching = new Map()
103
104
  this._updating = new Map()
104
105
 
106
+ this._registry = new FinalizationRegistry((name) => {
107
+ const entry = this._cache.get(name)
108
+ if (entry && entry.deref && entry.deref() === undefined) {
109
+ this._cache.delete(name)
110
+ }
111
+ })
112
+
105
113
  this._connected = 0
106
114
  this._stats = {
107
115
  updating: 0,
@@ -134,6 +142,11 @@ class RecordHandler {
134
142
  for (const rec of pruning) {
135
143
  rec._$dispose()
136
144
  this._records.delete(rec.name)
145
+
146
+ if (!this._cache.has(rec.name)) {
147
+ this._cache.set(rec.name, new WeakRef(rec))
148
+ this._registry.register(rec, rec.name)
149
+ }
137
150
  }
138
151
 
139
152
  this._stats.pruning -= pruning.size
@@ -219,7 +232,7 @@ class RecordHandler {
219
232
  let record = this._records.get(name)
220
233
 
221
234
  if (!record) {
222
- record = new Record(name, this)
235
+ record = this._cache.get(name)?.deref() ?? new Record(name, this)
223
236
  this._stats.records += 1
224
237
  this._stats.created += 1
225
238
  this._records.set(name, record)
@@ -11,10 +11,7 @@ class Record {
11
11
  static STATE = C.RECORD_STATE
12
12
 
13
13
  constructor(name, handler) {
14
- const connection = handler._connection
15
-
16
14
  this._handler = handler
17
-
18
15
  this._name = name
19
16
  this._version = ''
20
17
  this._data = jsonPath.EMPTY
@@ -24,7 +21,7 @@ class Record {
24
21
  this._emitting = false
25
22
  /** @type Map? */ this._updating = null
26
23
  /** @type Array? */ this._patching = null
27
- this._subscribed = connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
24
+ this._subscribed = false
28
25
  }
29
26
 
30
27
  /** @type {string} */