whio-api-sdk 1.1.11 → 1.1.14
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.
|
@@ -30,10 +30,6 @@ export declare class WebSocketModule extends BaseClient {
|
|
|
30
30
|
* Get connection statistics
|
|
31
31
|
*/
|
|
32
32
|
getConnectionStats(): WebSocketConnectionStats;
|
|
33
|
-
/**
|
|
34
|
-
* Ensure WebSocket connection has a valid token
|
|
35
|
-
* Reconnects with fresh token if current token is expired
|
|
36
|
-
*/
|
|
37
33
|
private ensureValidConnection;
|
|
38
34
|
/**
|
|
39
35
|
* Stream audio chunk to server
|
|
@@ -46,8 +46,7 @@ export class WebSocketModule extends BaseClient {
|
|
|
46
46
|
const wsUrl = this.getWebSocketUrl();
|
|
47
47
|
try {
|
|
48
48
|
// Ensure we have a fresh token before connecting
|
|
49
|
-
yield this.
|
|
50
|
-
const token = this.getAccessToken();
|
|
49
|
+
const token = yield this.getValidToken();
|
|
51
50
|
if (!token) {
|
|
52
51
|
this.emit('connection-error', new Error('No access token available for WebSocket connection'));
|
|
53
52
|
throw new Error('No access token available for WebSocket connection');
|
|
@@ -122,32 +121,13 @@ export class WebSocketModule extends BaseClient {
|
|
|
122
121
|
getConnectionStats() {
|
|
123
122
|
return Object.assign({}, this.connectionStats);
|
|
124
123
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Ensure WebSocket connection has a valid token
|
|
127
|
-
* Reconnects with fresh token if current token is expired
|
|
128
|
-
*/
|
|
129
124
|
ensureValidConnection() {
|
|
130
125
|
var _a;
|
|
131
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!currentToken || this.isTokenExpired(currentToken)) {
|
|
135
|
-
try {
|
|
136
|
-
// Refresh token
|
|
137
|
-
yield this.getToken();
|
|
138
|
-
// Disconnect current connection and reconnect with fresh token
|
|
139
|
-
this.disconnect();
|
|
140
|
-
yield this.connect();
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
console.error('[WebSocket] Failed to refresh token and reconnect:', error);
|
|
144
|
-
throw new Error('Authentication failed: Unable to refresh token for WebSocket streaming');
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else if (!((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected)) {
|
|
148
|
-
// Token is valid but not connected - establish connection
|
|
149
|
-
yield this.connect();
|
|
127
|
+
if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
128
|
+
return;
|
|
150
129
|
}
|
|
130
|
+
yield this.connect();
|
|
151
131
|
});
|
|
152
132
|
}
|
|
153
133
|
/**
|
package/package.json
CHANGED
|
@@ -63,8 +63,7 @@ export class WebSocketModule extends BaseClient {
|
|
|
63
63
|
|
|
64
64
|
try {
|
|
65
65
|
// Ensure we have a fresh token before connecting
|
|
66
|
-
await this.
|
|
67
|
-
const token = this.getAccessToken();
|
|
66
|
+
const token = await this.getValidToken();
|
|
68
67
|
|
|
69
68
|
if (!token) {
|
|
70
69
|
this.emit('connection-error', new Error('No access token available for WebSocket connection'));
|
|
@@ -149,32 +148,11 @@ export class WebSocketModule extends BaseClient {
|
|
|
149
148
|
return { ...this.connectionStats };
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
/**
|
|
153
|
-
* Ensure WebSocket connection has a valid token
|
|
154
|
-
* Reconnects with fresh token if current token is expired
|
|
155
|
-
*/
|
|
156
151
|
private async ensureValidConnection(): Promise<void> {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// Check if we have a token and if it's expired
|
|
160
|
-
if (!currentToken || this.isTokenExpired(currentToken)) {
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
// Refresh token
|
|
164
|
-
await this.getToken();
|
|
165
|
-
|
|
166
|
-
// Disconnect current connection and reconnect with fresh token
|
|
167
|
-
this.disconnect();
|
|
168
|
-
await this.connect();
|
|
169
|
-
|
|
170
|
-
} catch (error) {
|
|
171
|
-
console.error('[WebSocket] Failed to refresh token and reconnect:', error);
|
|
172
|
-
throw new Error('Authentication failed: Unable to refresh token for WebSocket streaming');
|
|
173
|
-
}
|
|
174
|
-
} else if (!this.socket?.connected) {
|
|
175
|
-
// Token is valid but not connected - establish connection
|
|
176
|
-
await this.connect();
|
|
152
|
+
if(this.socket?.connected) {
|
|
153
|
+
return;
|
|
177
154
|
}
|
|
155
|
+
await this.connect();
|
|
178
156
|
}
|
|
179
157
|
|
|
180
158
|
/**
|