@nxtedition/deepstream.io-client-js 24.2.1 → 24.2.3
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,8 +1,8 @@
|
|
|
1
1
|
const BrowserWebSocket = globalThis.WebSocket || globalThis.MozWebSocket
|
|
2
|
-
const
|
|
2
|
+
const utils = require('../utils/utils')
|
|
3
|
+
const NodeWebSocket = utils.isNode ? require('ws') : null
|
|
3
4
|
const messageParser = require('./message-parser')
|
|
4
5
|
const messageBuilder = require('./message-builder')
|
|
5
|
-
const utils = require('../utils/utils')
|
|
6
6
|
const C = require('../constants/constants')
|
|
7
7
|
const pkg = require('../../package.json')
|
|
8
8
|
const xxhash = require('xxhash-wasm')
|
|
@@ -101,11 +101,11 @@ Connection.prototype.close = function () {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
Connection.prototype._createEndpoint = function () {
|
|
104
|
-
this._endpoint =
|
|
105
|
-
? new
|
|
106
|
-
: new NodeWebSocket(this._url, {
|
|
104
|
+
this._endpoint = NodeWebSocket
|
|
105
|
+
? new NodeWebSocket(this._url, {
|
|
107
106
|
generateMask() {},
|
|
108
107
|
})
|
|
108
|
+
: new BrowserWebSocket(this._url)
|
|
109
109
|
this._corked = false
|
|
110
110
|
|
|
111
111
|
this._endpoint.onopen = this._onOpen.bind(this)
|
|
@@ -45,9 +45,12 @@ function onTimeout(subscription) {
|
|
|
45
45
|
const current = C.RECORD_STATE_NAME[subscription.record.state]
|
|
46
46
|
|
|
47
47
|
subscription.subscriber.error(
|
|
48
|
-
Object.assign(
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
Object.assign(
|
|
49
|
+
new Error(`timeout state: ${subscription.record.name} [${current}<${expected}]`),
|
|
50
|
+
{
|
|
51
|
+
code: 'ETIMEDOUT',
|
|
52
|
+
}
|
|
53
|
+
)
|
|
51
54
|
)
|
|
52
55
|
}
|
|
53
56
|
|
|
@@ -68,16 +71,20 @@ function onSyncFast(opaque) {
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
function onTimeoutFast(opaque) {
|
|
71
|
-
const { rec, resolve } = opaque
|
|
74
|
+
const { rec, synced, resolve } = opaque
|
|
72
75
|
rec.unsubscribe(onUpdateFast, opaque)
|
|
73
76
|
rec.unref()
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)
|
|
80
|
-
|
|
77
|
+
|
|
78
|
+
let err
|
|
79
|
+
if (rec.state < opaque.state) {
|
|
80
|
+
err = new Error(`timeout state: ${opaque.rec.name} [${opaque.rec.state}<${opaque.state}]`)
|
|
81
|
+
} else if (!synced) {
|
|
82
|
+
err = new Error(`timeout sync: ${opaque.rec.name} `)
|
|
83
|
+
} else {
|
|
84
|
+
err = new Error('timeout')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
resolve(Promise.reject(Object.assign(err, { code: 'ETIMEDOUT' })))
|
|
81
88
|
}
|
|
82
89
|
|
|
83
90
|
class RecordHandler {
|
|
@@ -323,7 +330,7 @@ class RecordHandler {
|
|
|
323
330
|
|
|
324
331
|
let serverTimeout
|
|
325
332
|
const token = xuid()
|
|
326
|
-
await Promise.race([
|
|
333
|
+
return await Promise.race([
|
|
327
334
|
await new Promise((resolve) => {
|
|
328
335
|
this._syncEmitter.once(token, resolve)
|
|
329
336
|
this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
|
|
@@ -606,7 +613,7 @@ class RecordHandler {
|
|
|
606
613
|
}
|
|
607
614
|
|
|
608
615
|
if (message.action === C.ACTIONS.SYNC) {
|
|
609
|
-
this._syncEmitter.emit(message.data[0])
|
|
616
|
+
this._syncEmitter.emit(message.data[0], message.data[1]?.toString())
|
|
610
617
|
return true
|
|
611
618
|
}
|
|
612
619
|
|