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.
@@ -13,6 +13,7 @@ export declare class CloseEvent extends Event {
13
13
  code: number;
14
14
  reason: string;
15
15
  wasClean: boolean;
16
+ willReconnect?: boolean;
16
17
  constructor(code: number | undefined, reason: string | undefined, target: any);
17
18
  }
18
19
  export interface WebSocketEventMap {
@@ -21,6 +21,7 @@ class CloseEvent extends Event {
21
21
  constructor(code = 1000, reason = "", target) {
22
22
  super("close", target);
23
23
  this.wasClean = true;
24
+ this.willReconnect = false;
24
25
  this.code = code;
25
26
  this.reason = reason;
26
27
  }
@@ -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
- if (!isWebSocket(this._options.WebSocket)) {
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, WebSocket = getGlobalWebSocket(), } = this._options;
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 WebSocket(url, this._protocols) : new WebSocket(url);
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;
@@ -13,6 +13,7 @@ export declare class CloseEvent extends Event {
13
13
  code: number;
14
14
  reason: string;
15
15
  wasClean: boolean;
16
+ willReconnect?: boolean;
16
17
  constructor(code: number | undefined, reason: string | undefined, target: any);
17
18
  }
18
19
  export interface WebSocketEventMap {
@@ -21,6 +21,7 @@ class CloseEvent extends Event {
21
21
  constructor(code = 1000, reason = "", target) {
22
22
  super("close", target);
23
23
  this.wasClean = true;
24
+ this.willReconnect = false;
24
25
  this.code = code;
25
26
  this.reason = reason;
26
27
  }
@@ -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
- if (!isWebSocket(this._options.WebSocket)) {
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, WebSocket = getGlobalWebSocket(), } = this._options;
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 WebSocket(url, this._protocols) : new WebSocket(url);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hume",
3
- "version": "0.10.4-beta.3",
3
+ "version": "0.10.4-beta.5",
4
4
  "private": false,
5
5
  "repository": "https://github.com/HumeAI/hume-typescript-sdk",
6
6
  "main": "./index.js",