@nxtedition/deepstream.io-client-js 24.2.3 → 24.2.5
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 +1 -1
- package/src/message/connection.js +22 -19
- package/src/record/record-handler.js +14 -1
- package/src/record/record.js +5 -8
package/package.json
CHANGED
|
@@ -101,19 +101,22 @@ Connection.prototype.close = function () {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
Connection.prototype._createEndpoint = function () {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
if (NodeWebSocket) {
|
|
105
|
+
this._endpoint = new NodeWebSocket(this._url, {
|
|
106
|
+
generateMask() {},
|
|
107
|
+
})
|
|
108
|
+
} else {
|
|
109
|
+
this._endpoint = new BrowserWebSocket(this._url)
|
|
110
|
+
this._endpoint.binaryType = 'arraybuffer'
|
|
111
|
+
}
|
|
109
112
|
this._corked = false
|
|
110
113
|
|
|
111
114
|
this._endpoint.onopen = this._onOpen.bind(this)
|
|
112
115
|
this._endpoint.onerror = this._onError.bind(this)
|
|
113
116
|
this._endpoint.onclose = this._onClose.bind(this)
|
|
114
117
|
this._endpoint.onmessage = BrowserWebSocket
|
|
115
|
-
? ({ data }) => this._onMessage(
|
|
116
|
-
: ({ data }) => this._onMessage(
|
|
118
|
+
? ({ data }) => this._onMessage(Buffer.from(data))
|
|
119
|
+
: ({ data }) => this._onMessage(data)
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
Connection.prototype.send = function (message) {
|
|
@@ -249,20 +252,20 @@ Connection.prototype._recvMessages = function (deadline) {
|
|
|
249
252
|
continue
|
|
250
253
|
}
|
|
251
254
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
+
try {
|
|
256
|
+
messageParser.parseMessage(message, this._client, this._message)
|
|
255
257
|
|
|
256
|
-
|
|
258
|
+
this.emit('recv', this._message)
|
|
257
259
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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)
|
|
266
|
+
}
|
|
267
|
+
} catch (err) {
|
|
268
|
+
this._onError(err)
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
|
|
@@ -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)
|
package/src/record/record.js
CHANGED
|
@@ -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 =
|
|
24
|
+
this._subscribed = false
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
/** @type {string} */
|
|
@@ -205,17 +202,17 @@ class Record {
|
|
|
205
202
|
|
|
206
203
|
return new Promise((resolve, reject) => {
|
|
207
204
|
if (this._state >= state) {
|
|
208
|
-
resolve(
|
|
205
|
+
resolve(this)
|
|
209
206
|
return
|
|
210
207
|
}
|
|
211
208
|
|
|
212
209
|
let timeoutHandle
|
|
213
210
|
|
|
214
|
-
const onDone = (err
|
|
211
|
+
const onDone = (err) => {
|
|
215
212
|
if (err) {
|
|
216
213
|
reject(err)
|
|
217
214
|
} else {
|
|
218
|
-
resolve(
|
|
215
|
+
resolve(this)
|
|
219
216
|
}
|
|
220
217
|
|
|
221
218
|
this.unref()
|
|
@@ -231,7 +228,7 @@ class Record {
|
|
|
231
228
|
|
|
232
229
|
const onUpdate = () => {
|
|
233
230
|
if (this._state >= state) {
|
|
234
|
-
onDone(null
|
|
231
|
+
onDone(null)
|
|
235
232
|
}
|
|
236
233
|
}
|
|
237
234
|
|