whio-api-sdk 1.0.199-beta-staging → 1.0.200-beta-staging
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.
|
@@ -29,7 +29,9 @@ export class WebSocketModule extends BaseClient {
|
|
|
29
29
|
reconnectAttempts: 0
|
|
30
30
|
};
|
|
31
31
|
if (this.config.autoConnect) {
|
|
32
|
-
this.connect()
|
|
32
|
+
this.connect().catch(error => {
|
|
33
|
+
console.error('Failed to auto-connect WebSocket:', error);
|
|
34
|
+
});
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
@@ -37,23 +39,32 @@ export class WebSocketModule extends BaseClient {
|
|
|
37
39
|
*/
|
|
38
40
|
connect() {
|
|
39
41
|
var _a;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const wsUrl = this.getWebSocketUrl();
|
|
47
|
+
try {
|
|
48
|
+
// Ensure we have a fresh token before connecting
|
|
49
|
+
yield this.getToken();
|
|
50
|
+
const token = this.getAccessToken();
|
|
51
|
+
if (!token) {
|
|
52
|
+
this.emit('connection-error', new Error('No access token available for WebSocket connection'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.socket = io(wsUrl, {
|
|
56
|
+
auth: {
|
|
57
|
+
token: token
|
|
58
|
+
},
|
|
59
|
+
forceNew: true,
|
|
60
|
+
timeout: 10000
|
|
61
|
+
});
|
|
62
|
+
this.setupEventHandlers();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
this.emit('connection-error', error);
|
|
66
|
+
}
|
|
55
67
|
});
|
|
56
|
-
this.setupEventHandlers();
|
|
57
68
|
}
|
|
58
69
|
/**
|
|
59
70
|
* Disconnect from WebSocket server
|
|
@@ -230,9 +241,9 @@ export class WebSocketModule extends BaseClient {
|
|
|
230
241
|
// Calculate exponential backoff delay
|
|
231
242
|
const delay = Math.min(this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1), this.maxReconnectDelay);
|
|
232
243
|
this.emit('reconnecting', this.reconnectAttempts);
|
|
233
|
-
this.reconnectTimeout = setTimeout(() => {
|
|
234
|
-
this.connect();
|
|
235
|
-
}, delay);
|
|
244
|
+
this.reconnectTimeout = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
yield this.connect();
|
|
246
|
+
}), delay);
|
|
236
247
|
}
|
|
237
248
|
/**
|
|
238
249
|
* Get WebSocket URL
|
package/dist/src/sdk/sdk.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ export declare class ApiSDK extends BaseClient {
|
|
|
183
183
|
getExternalIntegration(...args: Parameters<ExternalIntegrationModule['getExternalIntegration']>): Promise<import("./types").ExternalIntegration>;
|
|
184
184
|
updateExternalIntegration(...args: Parameters<ExternalIntegrationModule['updateExternalIntegration']>): Promise<import("./types").ExternalIntegration>;
|
|
185
185
|
deleteExternalIntegration(...args: Parameters<ExternalIntegrationModule['deleteExternalIntegration']>): Promise<void>;
|
|
186
|
-
connectWebSocket(): void
|
|
186
|
+
connectWebSocket(): Promise<void>;
|
|
187
187
|
disconnectWebSocket(): void;
|
|
188
188
|
isWebSocketConnected(): boolean;
|
|
189
189
|
streamAudioChunk(...args: Parameters<WebSocketModule['streamAudioChunk']>): void;
|
package/package.json
CHANGED
|
@@ -45,35 +45,44 @@ export class WebSocketModule extends BaseClient {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
if (this.config.autoConnect) {
|
|
48
|
-
this.connect()
|
|
48
|
+
this.connect().catch(error => {
|
|
49
|
+
console.error('Failed to auto-connect WebSocket:', error);
|
|
50
|
+
});
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* Connect to WebSocket server
|
|
54
56
|
*/
|
|
55
|
-
public connect(): void {
|
|
57
|
+
public async connect(): Promise<void> {
|
|
56
58
|
if (this.socket?.connected) {
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
const wsUrl = this.getWebSocketUrl();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
// Ensure we have a fresh token before connecting
|
|
66
|
+
await this.getToken();
|
|
67
|
+
const token = this.getAccessToken();
|
|
68
|
+
|
|
69
|
+
if (!token) {
|
|
70
|
+
this.emit('connection-error', new Error('No access token available for WebSocket connection'));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
this.socket = io(wsUrl, {
|
|
75
|
+
auth: {
|
|
76
|
+
token: token
|
|
77
|
+
},
|
|
78
|
+
forceNew: true,
|
|
79
|
+
timeout: 10000
|
|
80
|
+
});
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
this.setupEventHandlers();
|
|
83
|
+
} catch (error) {
|
|
84
|
+
this.emit('connection-error', error as Error);
|
|
85
|
+
}
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
/**
|
|
@@ -300,8 +309,8 @@ export class WebSocketModule extends BaseClient {
|
|
|
300
309
|
|
|
301
310
|
this.emit('reconnecting', this.reconnectAttempts);
|
|
302
311
|
|
|
303
|
-
this.reconnectTimeout = setTimeout(() => {
|
|
304
|
-
this.connect();
|
|
312
|
+
this.reconnectTimeout = setTimeout(async () => {
|
|
313
|
+
await this.connect();
|
|
305
314
|
}, delay);
|
|
306
315
|
}
|
|
307
316
|
|