@nxtedition/deepstream.io-client-js 25.6.2 → 25.6.4
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 +17 -2
- package/src/record/record.js +4 -2
- package/src/utils/utils.js +4 -1
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ import FixedQueue from '../utils/fixed-queue.js'
|
|
|
6
6
|
import Emitter from 'component-emitter2'
|
|
7
7
|
import pkg from '../../package.json' with { type: 'json' }
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
let NodeWebSocket = null
|
|
10
10
|
const BrowserWebSocket = globalThis.WebSocket || globalThis.MozWebSocket
|
|
11
11
|
|
|
12
12
|
export default function Connection(client, url, options) {
|
|
@@ -91,6 +91,16 @@ Connection.prototype.close = function () {
|
|
|
91
91
|
|
|
92
92
|
Connection.prototype._createEndpoint = function () {
|
|
93
93
|
if (utils.isNode) {
|
|
94
|
+
// This is a hack to avoid top-level await
|
|
95
|
+
// const HASHER = await xxhash()
|
|
96
|
+
if (!NodeWebSocket) {
|
|
97
|
+
import('ws').then(({ default: WebSocket }) => {
|
|
98
|
+
NodeWebSocket = WebSocket
|
|
99
|
+
this._createEndpoint()
|
|
100
|
+
})
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
94
104
|
this._endpoint = new NodeWebSocket(this._url, {
|
|
95
105
|
generateMask() {},
|
|
96
106
|
})
|
|
@@ -123,6 +133,10 @@ Connection.prototype.send = function (message) {
|
|
|
123
133
|
return false
|
|
124
134
|
}
|
|
125
135
|
|
|
136
|
+
if (!this._endpoint) {
|
|
137
|
+
return false
|
|
138
|
+
}
|
|
139
|
+
|
|
126
140
|
if (
|
|
127
141
|
this._state !== C.CONNECTION_STATE.OPEN ||
|
|
128
142
|
this._endpoint.readyState !== this._endpoint.OPEN
|
|
@@ -140,6 +154,7 @@ Connection.prototype.send = function (message) {
|
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
this.emit('send', message)
|
|
157
|
+
|
|
143
158
|
this._endpoint.send(message)
|
|
144
159
|
|
|
145
160
|
return true
|
|
@@ -152,7 +167,7 @@ Connection.prototype._submit = function (message) {
|
|
|
152
167
|
const err = new Error(`Packet to big: ${message.length} > ${maxPacketSize}`)
|
|
153
168
|
this._client._$onError(C.TOPIC.CONNECTION, C.EVENT.CONNECTION_ERROR, err)
|
|
154
169
|
return false
|
|
155
|
-
} else if (this._endpoint.readyState === this._endpoint.OPEN) {
|
|
170
|
+
} else if (this._endpoint != null && this._endpoint.readyState === this._endpoint.OPEN) {
|
|
156
171
|
this.emit('send', message)
|
|
157
172
|
this._endpoint.send(message)
|
|
158
173
|
return true
|
package/src/record/record.js
CHANGED
|
@@ -389,7 +389,7 @@ class Record {
|
|
|
389
389
|
this._version = nextVersion
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
_onUpdate([, version, data]) {
|
|
392
|
+
_onUpdate([, version, data, hasProvider]) {
|
|
393
393
|
const prevData = this._data
|
|
394
394
|
const prevVersion = this._version
|
|
395
395
|
const prevState = this._state
|
|
@@ -422,7 +422,9 @@ class Record {
|
|
|
422
422
|
this._onPatching(false)
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
if (
|
|
425
|
+
if (hasProvider === 'T') {
|
|
426
|
+
this._state = C.RECORD_STATE.PROVIDER
|
|
427
|
+
} else if (this._state < C.RECORD_STATE.SERVER) {
|
|
426
428
|
this._state = this._version.charAt(0) === 'I' ? C.RECORD_STATE.STALE : C.RECORD_STATE.SERVER
|
|
427
429
|
}
|
|
428
430
|
|
package/src/utils/utils.js
CHANGED
|
@@ -177,7 +177,10 @@ export function removeAbortListener(signal, handler) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
// This is a hack to avoid top-level await
|
|
181
|
+
// const HASHER = await xxhash()
|
|
182
|
+
let HASHER
|
|
183
|
+
xxhash().then((hasher) => (HASHER = hasher))
|
|
181
184
|
|
|
182
185
|
export function h64ToString(str) {
|
|
183
186
|
return HASHER.h64ToString(str)
|