hume 0.10.4-beta.3 → 0.10.4-beta.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/core/websocket/events.d.ts +1 -0
- package/core/websocket/events.js +1 -0
- package/core/websocket/ws.d.ts +1 -0
- package/core/websocket/ws.js +8 -3
- package/dist/core/websocket/events.d.ts +1 -0
- package/dist/core/websocket/events.js +1 -0
- package/dist/core/websocket/ws.d.ts +1 -0
- package/dist/core/websocket/ws.js +8 -3
- package/package.json +1 -1
package/core/websocket/events.js
CHANGED
package/core/websocket/ws.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare class ReconnectingWebSocket {
|
|
|
36
36
|
private readonly _url;
|
|
37
37
|
private readonly _protocols?;
|
|
38
38
|
private readonly _options;
|
|
39
|
+
private readonly _WebSocket;
|
|
39
40
|
constructor(url: UrlProvider, protocols?: string | string[], options?: Options);
|
|
40
41
|
static get CONNECTING(): number;
|
|
41
42
|
static get OPEN(): number;
|
package/core/websocket/ws.js
CHANGED
|
@@ -166,6 +166,7 @@ class ReconnectingWebSocket {
|
|
|
166
166
|
this._shouldReconnect = false;
|
|
167
167
|
this._debug("Reconnection stopped: Received close code 1000 (intentional server close).");
|
|
168
168
|
}
|
|
169
|
+
adaptedEvent.willReconnect = this._shouldReconnect;
|
|
169
170
|
// Dispatch event to listeners
|
|
170
171
|
if (this.onclose)
|
|
171
172
|
this.onclose(adaptedEvent);
|
|
@@ -174,15 +175,18 @@ class ReconnectingWebSocket {
|
|
|
174
175
|
if (this._shouldReconnect)
|
|
175
176
|
this._connect();
|
|
176
177
|
};
|
|
178
|
+
console.log('constructing...');
|
|
177
179
|
this._url = url;
|
|
178
180
|
this._protocols = protocols;
|
|
179
181
|
this._options = options;
|
|
180
|
-
|
|
182
|
+
this._WebSocket = this._options.WebSocket || getGlobalWebSocket();
|
|
183
|
+
if (!isWebSocket(this._WebSocket)) {
|
|
181
184
|
throw Error("No valid WebSocket class provided");
|
|
182
185
|
}
|
|
183
186
|
if (this._options.startClosed) {
|
|
184
187
|
this._shouldReconnect = false;
|
|
185
188
|
}
|
|
189
|
+
console.log('all good');
|
|
186
190
|
this._connect();
|
|
187
191
|
}
|
|
188
192
|
static get CONNECTING() {
|
|
@@ -414,6 +418,7 @@ class ReconnectingWebSocket {
|
|
|
414
418
|
this._listeners.error.forEach((listener) => this._callEventListener(errorEvent, listener));
|
|
415
419
|
// Dispatch close event
|
|
416
420
|
const closeEvent = new Events.CloseEvent(1000, closeReason, this);
|
|
421
|
+
closeEvent.willReconnect = false;
|
|
417
422
|
if (this.onclose)
|
|
418
423
|
this.onclose(closeEvent);
|
|
419
424
|
this._listeners.close.forEach((listener) => this._callEventListener(closeEvent, listener));
|
|
@@ -430,7 +435,7 @@ class ReconnectingWebSocket {
|
|
|
430
435
|
}
|
|
431
436
|
// Set lock for this attempt
|
|
432
437
|
this._connectLock = true;
|
|
433
|
-
const { maxRetries = DEFAULT.maxRetries, connectionTimeout = DEFAULT.connectionTimeout,
|
|
438
|
+
const { maxRetries = DEFAULT.maxRetries, connectionTimeout = DEFAULT.connectionTimeout, } = this._options;
|
|
434
439
|
// Max retries check
|
|
435
440
|
if (this._retryCount >= maxRetries) {
|
|
436
441
|
this._shutdown(new Error(`Max retries (${maxRetries}) reached. Giving up.`), "Max retries reached");
|
|
@@ -451,7 +456,7 @@ class ReconnectingWebSocket {
|
|
|
451
456
|
return;
|
|
452
457
|
}
|
|
453
458
|
this._debug("connect", { url, protocols: this._protocols });
|
|
454
|
-
this._ws = this._protocols ? new
|
|
459
|
+
this._ws = this._protocols ? new (this._WebSocket)(url, this._protocols) : new (this._WebSocket)(url);
|
|
455
460
|
this._ws.binaryType = this._binaryType;
|
|
456
461
|
this._addListeners();
|
|
457
462
|
this._connectLock = false;
|
|
@@ -36,6 +36,7 @@ export declare class ReconnectingWebSocket {
|
|
|
36
36
|
private readonly _url;
|
|
37
37
|
private readonly _protocols?;
|
|
38
38
|
private readonly _options;
|
|
39
|
+
private readonly _WebSocket;
|
|
39
40
|
constructor(url: UrlProvider, protocols?: string | string[], options?: Options);
|
|
40
41
|
static get CONNECTING(): number;
|
|
41
42
|
static get OPEN(): number;
|
|
@@ -166,6 +166,7 @@ class ReconnectingWebSocket {
|
|
|
166
166
|
this._shouldReconnect = false;
|
|
167
167
|
this._debug("Reconnection stopped: Received close code 1000 (intentional server close).");
|
|
168
168
|
}
|
|
169
|
+
adaptedEvent.willReconnect = this._shouldReconnect;
|
|
169
170
|
// Dispatch event to listeners
|
|
170
171
|
if (this.onclose)
|
|
171
172
|
this.onclose(adaptedEvent);
|
|
@@ -174,15 +175,18 @@ class ReconnectingWebSocket {
|
|
|
174
175
|
if (this._shouldReconnect)
|
|
175
176
|
this._connect();
|
|
176
177
|
};
|
|
178
|
+
console.log('constructing...');
|
|
177
179
|
this._url = url;
|
|
178
180
|
this._protocols = protocols;
|
|
179
181
|
this._options = options;
|
|
180
|
-
|
|
182
|
+
this._WebSocket = this._options.WebSocket || getGlobalWebSocket();
|
|
183
|
+
if (!isWebSocket(this._WebSocket)) {
|
|
181
184
|
throw Error("No valid WebSocket class provided");
|
|
182
185
|
}
|
|
183
186
|
if (this._options.startClosed) {
|
|
184
187
|
this._shouldReconnect = false;
|
|
185
188
|
}
|
|
189
|
+
console.log('all good');
|
|
186
190
|
this._connect();
|
|
187
191
|
}
|
|
188
192
|
static get CONNECTING() {
|
|
@@ -414,6 +418,7 @@ class ReconnectingWebSocket {
|
|
|
414
418
|
this._listeners.error.forEach((listener) => this._callEventListener(errorEvent, listener));
|
|
415
419
|
// Dispatch close event
|
|
416
420
|
const closeEvent = new Events.CloseEvent(1000, closeReason, this);
|
|
421
|
+
closeEvent.willReconnect = false;
|
|
417
422
|
if (this.onclose)
|
|
418
423
|
this.onclose(closeEvent);
|
|
419
424
|
this._listeners.close.forEach((listener) => this._callEventListener(closeEvent, listener));
|
|
@@ -430,7 +435,7 @@ class ReconnectingWebSocket {
|
|
|
430
435
|
}
|
|
431
436
|
// Set lock for this attempt
|
|
432
437
|
this._connectLock = true;
|
|
433
|
-
const { maxRetries = DEFAULT.maxRetries, connectionTimeout = DEFAULT.connectionTimeout,
|
|
438
|
+
const { maxRetries = DEFAULT.maxRetries, connectionTimeout = DEFAULT.connectionTimeout, } = this._options;
|
|
434
439
|
// Max retries check
|
|
435
440
|
if (this._retryCount >= maxRetries) {
|
|
436
441
|
this._shutdown(new Error(`Max retries (${maxRetries}) reached. Giving up.`), "Max retries reached");
|
|
@@ -451,7 +456,7 @@ class ReconnectingWebSocket {
|
|
|
451
456
|
return;
|
|
452
457
|
}
|
|
453
458
|
this._debug("connect", { url, protocols: this._protocols });
|
|
454
|
-
this._ws = this._protocols ? new
|
|
459
|
+
this._ws = this._protocols ? new (this._WebSocket)(url, this._protocols) : new (this._WebSocket)(url);
|
|
455
460
|
this._ws.binaryType = this._binaryType;
|
|
456
461
|
this._addListeners();
|
|
457
462
|
this._connectLock = false;
|