hume 0.8.1-beta7 → 0.8.1-beta9

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/Client.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare namespace HumeClient {
9
9
  interface Options {
10
10
  environment?: core.Supplier<environments.HumeEnvironment | string>;
11
11
  apiKey?: core.Supplier<string | undefined>;
12
+ accessToken?: core.Supplier<string | undefined>;
12
13
  fetcher?: core.FetchFunction;
13
14
  }
14
15
  interface RequestOptions {
@@ -13,6 +13,7 @@ export declare namespace EmpathicVoice {
13
13
  interface Options {
14
14
  environment?: core.Supplier<environments.HumeEnvironment | string>;
15
15
  apiKey?: core.Supplier<string | undefined>;
16
+ accessToken?: core.Supplier<string | undefined>;
16
17
  fetcher?: core.FetchFunction;
17
18
  }
18
19
  interface RequestOptions {
@@ -35,13 +35,13 @@ class Chat {
35
35
  this._options = _options;
36
36
  }
37
37
  connect(args = {}) {
38
- var _a;
38
+ var _a, _b;
39
39
  const queryParams = {};
40
40
  if (this._options.accessToken != null) {
41
- queryParams["accessToken"] = core.Supplier.get(this._options.accessToken);
41
+ queryParams["accessToken"] = this._options.accessToken;
42
42
  }
43
43
  else if (this._options.apiKey != null) {
44
- queryParams["apiKey"] = core.Supplier.get(this._options.apiKey);
44
+ queryParams["apiKey"] = this._options.apiKey;
45
45
  }
46
46
  if (args.configId != null) {
47
47
  queryParams["config_id"] = args.configId;
@@ -58,9 +58,8 @@ class Chat {
58
58
  }
59
59
  }
60
60
  const socket = new core.ReconnectingWebSocket(`wss://api.hume.ai/v0/evi/chat?${qs_1.default.stringify(queryParams)}`, [], {
61
- startClosed: true,
62
61
  debug: (_a = args.debug) !== null && _a !== void 0 ? _a : false,
63
- maxRetries: args.reconnectAttempts,
62
+ maxRetries: (_b = args.reconnectAttempts) !== null && _b !== void 0 ? _b : 30,
64
63
  });
65
64
  return new Socket_1.ChatSocket({
66
65
  socket,
@@ -67,13 +67,14 @@ export declare class ChatSocket {
67
67
  /**
68
68
  * @name connect
69
69
  * @description
70
- * Connect to the websocket.
70
+ * Connect to the core.ReconnectingWebSocket.
71
71
  */
72
72
  connect(): ChatSocket;
73
73
  /**
74
74
  * Closes the underlying socket.
75
75
  */
76
76
  close(): void;
77
+ tillSocketOpen(): Promise<core.ReconnectingWebSocket>;
77
78
  private assertSocketIsOpen;
78
79
  private sendJson;
79
80
  private handleOpen;
@@ -22,8 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  exports.ChatSocket = void 0;
36
+ const core = __importStar(require("../../../../../../core"));
27
37
  const errors = __importStar(require("../../../../../../errors"));
28
38
  const serializers = __importStar(require("../../../../../../serialization/index"));
29
39
  class ChatSocket {
@@ -55,7 +65,7 @@ class ChatSocket {
55
65
  };
56
66
  this.handleError = (event) => {
57
67
  var _a, _b, _c;
58
- const message = (_a = event.message) !== null && _a !== void 0 ? _a : 'WebSocket error';
68
+ const message = (_a = event.message) !== null && _a !== void 0 ? _a : 'core.ReconnectingWebSocket error';
59
69
  (_c = (_b = this.eventHandlers).error) === null || _c === void 0 ? void 0 : _c.call(_b, new Error(message));
60
70
  };
61
71
  this.socket = socket;
@@ -142,7 +152,7 @@ class ChatSocket {
142
152
  /**
143
153
  * @name connect
144
154
  * @description
145
- * Connect to the websocket.
155
+ * Connect to the core.ReconnectingWebSocket.
146
156
  */
147
157
  connect() {
148
158
  this.socket.reconnect();
@@ -163,11 +173,26 @@ class ChatSocket {
163
173
  this.socket.removeEventListener('close', this.handleClose);
164
174
  this.socket.removeEventListener('error', this.handleError);
165
175
  }
176
+ tillSocketOpen() {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ if (this.socket.readyState === core.ReconnectingWebSocket.OPEN) {
179
+ return this.socket;
180
+ }
181
+ return new Promise((resolve, reject) => {
182
+ this.socket.addEventListener("open", () => {
183
+ resolve(this.socket);
184
+ });
185
+ this.socket.addEventListener("error", (event) => {
186
+ reject(event);
187
+ });
188
+ });
189
+ });
190
+ }
166
191
  assertSocketIsOpen() {
167
192
  if (!this.socket) {
168
193
  throw new errors.HumeError({ message: 'Socket is not connected.' });
169
194
  }
170
- if (this.socket.readyState !== WebSocket.OPEN) {
195
+ if (this.socket.readyState !== core.ReconnectingWebSocket.OPEN) {
171
196
  throw new errors.HumeError({ message: 'Socket is not open.' });
172
197
  }
173
198
  }
@@ -25,11 +25,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ReconnectingWebSocket = void 0;
27
27
  const Events = __importStar(require("./events"));
28
+ const ws_1 = require("ws");
28
29
  const getGlobalWebSocket = () => {
29
- if (typeof WebSocket !== 'undefined') {
30
- // @ts-ignore
31
- return WebSocket;
32
- }
30
+ var _a;
31
+ var _b;
32
+ return (_a = (_b = global).WebSocket) !== null && _a !== void 0 ? _a : (_b.WebSocket = ws_1.WebSocket);
33
33
  };
34
34
  /**
35
35
  * Returns true if given argument looks like a WebSocket class
package/dist/Client.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare namespace HumeClient {
9
9
  interface Options {
10
10
  environment?: core.Supplier<environments.HumeEnvironment | string>;
11
11
  apiKey?: core.Supplier<string | undefined>;
12
+ accessToken?: core.Supplier<string | undefined>;
12
13
  fetcher?: core.FetchFunction;
13
14
  }
14
15
  interface RequestOptions {
@@ -13,6 +13,7 @@ export declare namespace EmpathicVoice {
13
13
  interface Options {
14
14
  environment?: core.Supplier<environments.HumeEnvironment | string>;
15
15
  apiKey?: core.Supplier<string | undefined>;
16
+ accessToken?: core.Supplier<string | undefined>;
16
17
  fetcher?: core.FetchFunction;
17
18
  }
18
19
  interface RequestOptions {
@@ -35,13 +35,13 @@ class Chat {
35
35
  this._options = _options;
36
36
  }
37
37
  connect(args = {}) {
38
- var _a;
38
+ var _a, _b;
39
39
  const queryParams = {};
40
40
  if (this._options.accessToken != null) {
41
- queryParams["accessToken"] = core.Supplier.get(this._options.accessToken);
41
+ queryParams["accessToken"] = this._options.accessToken;
42
42
  }
43
43
  else if (this._options.apiKey != null) {
44
- queryParams["apiKey"] = core.Supplier.get(this._options.apiKey);
44
+ queryParams["apiKey"] = this._options.apiKey;
45
45
  }
46
46
  if (args.configId != null) {
47
47
  queryParams["config_id"] = args.configId;
@@ -58,9 +58,8 @@ class Chat {
58
58
  }
59
59
  }
60
60
  const socket = new core.ReconnectingWebSocket(`wss://api.hume.ai/v0/evi/chat?${qs_1.default.stringify(queryParams)}`, [], {
61
- startClosed: true,
62
61
  debug: (_a = args.debug) !== null && _a !== void 0 ? _a : false,
63
- maxRetries: args.reconnectAttempts,
62
+ maxRetries: (_b = args.reconnectAttempts) !== null && _b !== void 0 ? _b : 30,
64
63
  });
65
64
  return new Socket_1.ChatSocket({
66
65
  socket,
@@ -67,13 +67,14 @@ export declare class ChatSocket {
67
67
  /**
68
68
  * @name connect
69
69
  * @description
70
- * Connect to the websocket.
70
+ * Connect to the core.ReconnectingWebSocket.
71
71
  */
72
72
  connect(): ChatSocket;
73
73
  /**
74
74
  * Closes the underlying socket.
75
75
  */
76
76
  close(): void;
77
+ tillSocketOpen(): Promise<core.ReconnectingWebSocket>;
77
78
  private assertSocketIsOpen;
78
79
  private sendJson;
79
80
  private handleOpen;
@@ -22,8 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  exports.ChatSocket = void 0;
36
+ const core = __importStar(require("../../../../../../core"));
27
37
  const errors = __importStar(require("../../../../../../errors"));
28
38
  const serializers = __importStar(require("../../../../../../serialization/index"));
29
39
  class ChatSocket {
@@ -55,7 +65,7 @@ class ChatSocket {
55
65
  };
56
66
  this.handleError = (event) => {
57
67
  var _a, _b, _c;
58
- const message = (_a = event.message) !== null && _a !== void 0 ? _a : 'WebSocket error';
68
+ const message = (_a = event.message) !== null && _a !== void 0 ? _a : 'core.ReconnectingWebSocket error';
59
69
  (_c = (_b = this.eventHandlers).error) === null || _c === void 0 ? void 0 : _c.call(_b, new Error(message));
60
70
  };
61
71
  this.socket = socket;
@@ -142,7 +152,7 @@ class ChatSocket {
142
152
  /**
143
153
  * @name connect
144
154
  * @description
145
- * Connect to the websocket.
155
+ * Connect to the core.ReconnectingWebSocket.
146
156
  */
147
157
  connect() {
148
158
  this.socket.reconnect();
@@ -163,11 +173,26 @@ class ChatSocket {
163
173
  this.socket.removeEventListener('close', this.handleClose);
164
174
  this.socket.removeEventListener('error', this.handleError);
165
175
  }
176
+ tillSocketOpen() {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ if (this.socket.readyState === core.ReconnectingWebSocket.OPEN) {
179
+ return this.socket;
180
+ }
181
+ return new Promise((resolve, reject) => {
182
+ this.socket.addEventListener("open", () => {
183
+ resolve(this.socket);
184
+ });
185
+ this.socket.addEventListener("error", (event) => {
186
+ reject(event);
187
+ });
188
+ });
189
+ });
190
+ }
166
191
  assertSocketIsOpen() {
167
192
  if (!this.socket) {
168
193
  throw new errors.HumeError({ message: 'Socket is not connected.' });
169
194
  }
170
- if (this.socket.readyState !== WebSocket.OPEN) {
195
+ if (this.socket.readyState !== core.ReconnectingWebSocket.OPEN) {
171
196
  throw new errors.HumeError({ message: 'Socket is not open.' });
172
197
  }
173
198
  }
@@ -25,11 +25,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ReconnectingWebSocket = void 0;
27
27
  const Events = __importStar(require("./events"));
28
+ const ws_1 = require("ws");
28
29
  const getGlobalWebSocket = () => {
29
- if (typeof WebSocket !== 'undefined') {
30
- // @ts-ignore
31
- return WebSocket;
32
- }
30
+ var _a;
31
+ var _b;
32
+ return (_a = (_b = global).WebSocket) !== null && _a !== void 0 ? _a : (_b.WebSocket = ws_1.WebSocket);
33
33
  };
34
34
  /**
35
35
  * Returns true if given argument looks like a WebSocket class
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hume",
3
- "version": "0.8.1-beta7",
3
+ "version": "0.8.1-beta9",
4
4
  "private": false,
5
5
  "repository": "https://github.com/HumeAI/hume-typescript-sdk",
6
6
  "main": "./index.js",