@nxtedition/deepstream.io-client-js 25.6.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "25.6.3",
3
+ "version": "25.6.4",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -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
- const NodeWebSocket = utils.isNode ? await import('ws').then((x) => x.default) : null
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
@@ -177,7 +177,10 @@ export function removeAbortListener(signal, handler) {
177
177
  }
178
178
  }
179
179
 
180
- const HASHER = await xxhash()
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)