@rc-ex/ws 1.1.1 → 1.1.4
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/README.md +11 -21
- package/lib/exceptions/ClosedException.js.map +1 -1
- package/lib/exceptions/ConnectionException.d.ts +1 -1
- package/lib/exceptions/ConnectionException.js.map +1 -1
- package/lib/exceptions/TimeoutException.js.map +1 -1
- package/lib/index.d.ts +5 -5
- package/lib/index.js +24 -30
- package/lib/index.js.map +1 -1
- package/lib/rest.d.ts +2 -2
- package/lib/rest.js +2 -3
- package/lib/rest.js.map +1 -1
- package/lib/subscription.d.ts +5 -5
- package/lib/subscription.js +1 -3
- package/lib/subscription.js.map +1 -1
- package/lib/types.d.ts +19 -18
- package/lib/utils.d.ts +2 -2
- package/lib/utils.js +1 -4
- package/lib/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/exceptions/ClosedException.ts +1 -1
- package/src/exceptions/ConnectionException.ts +4 -4
- package/src/exceptions/TimeoutException.ts +1 -1
- package/src/index.ts +64 -93
- package/src/rest.ts +5 -17
- package/src/subscription.ts +23 -41
- package/src/types.ts +21 -25
- package/src/utils.ts +7 -13
package/README.md
CHANGED
|
@@ -4,14 +4,12 @@ WebSocket Extension adds support for WebSocket protocol.
|
|
|
4
4
|
|
|
5
5
|
Please read this article: [Create WebSocket subscriptions using RingCentral JavaScript SDKs](https://medium.com/@tylerlong/create-websocket-subscriptions-using-ringcentral-javascript-sdks-1204ce5843b8).
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
## Install
|
|
9
8
|
|
|
10
9
|
```
|
|
11
10
|
yarn add @rc-ex/ws
|
|
12
11
|
```
|
|
13
12
|
|
|
14
|
-
|
|
15
13
|
## Usage
|
|
16
14
|
|
|
17
15
|
```ts
|
|
@@ -55,7 +53,6 @@ If you need to create multiple subscriptions, you need to create multiple `WebSo
|
|
|
55
53
|
|
|
56
54
|
`WebSocketExtension` constructor requires `WebSocketOptions` as parameter:
|
|
57
55
|
|
|
58
|
-
|
|
59
56
|
```ts
|
|
60
57
|
type WebSocketOptions = {
|
|
61
58
|
restOverWebSocket?: boolean;
|
|
@@ -64,7 +61,6 @@ type WebSocketOptions = {
|
|
|
64
61
|
};
|
|
65
62
|
```
|
|
66
63
|
|
|
67
|
-
|
|
68
64
|
### restOverWebSocket
|
|
69
65
|
|
|
70
66
|
`restOverWebSocket` indicates whether to make Rest API call over WebSocket protocol.
|
|
@@ -79,7 +75,6 @@ Please note that, not all Rest API calls can be done over WebSocket protocol. Th
|
|
|
79
75
|
|
|
80
76
|
If `restOverWebSocket` is true and an Rest API call cannot be done over WebSocket, it will be done over HTTPS instead.
|
|
81
77
|
|
|
82
|
-
|
|
83
78
|
### debugMode
|
|
84
79
|
|
|
85
80
|
`debugMode` indicates whether to enable debug mode.
|
|
@@ -88,7 +83,6 @@ Default value is false.
|
|
|
88
83
|
|
|
89
84
|
If enabled, WebSocket incoming message and outgoing message will be printed using `console.debug`.
|
|
90
85
|
|
|
91
|
-
|
|
92
86
|
### autoRecover
|
|
93
87
|
|
|
94
88
|
`autoRecover` indicates whether to auto recover when WebSocket connection is lost.
|
|
@@ -97,11 +91,10 @@ Default value is true.
|
|
|
97
91
|
|
|
98
92
|
If disabled, you need to manually invoke `await webSocketExtension.recover()` whenever WebSocket connection is lost.
|
|
99
93
|
|
|
100
|
-
|
|
101
94
|
## Access WebSocket object
|
|
102
95
|
|
|
103
96
|
```ts
|
|
104
|
-
webSocketExtension.ws
|
|
97
|
+
webSocketExtension.ws;
|
|
105
98
|
```
|
|
106
99
|
|
|
107
100
|
gives you the WebSocket object. But if the network is unstable and `autoRecover` is enabled, sometimes a new WebSocket connection will be created to replace the current one.
|
|
@@ -120,7 +113,6 @@ webSocketExtension.eventEmitter.on(Events.autoRecoverFailed, ws => {
|
|
|
120
113
|
});
|
|
121
114
|
```
|
|
122
115
|
|
|
123
|
-
|
|
124
116
|
## Session Recovery
|
|
125
117
|
|
|
126
118
|
### Auto recover
|
|
@@ -128,39 +120,37 @@ webSocketExtension.eventEmitter.on(Events.autoRecoverFailed, ws => {
|
|
|
128
120
|
By default auto recover is enabled. You can subscribe to auto recover events:
|
|
129
121
|
|
|
130
122
|
```ts
|
|
131
|
-
webSocketExtension.eventEmitter.on(Events.autoRecoverSuccess, ws => {
|
|
123
|
+
webSocketExtension.eventEmitter.on(Events.autoRecoverSuccess, (ws) => {
|
|
132
124
|
console.log(`auto recover success: ${ws}`);
|
|
133
125
|
});
|
|
134
|
-
webSocketExtension.eventEmitter.on(Events.autoRecoverFailed, ws => {
|
|
126
|
+
webSocketExtension.eventEmitter.on(Events.autoRecoverFailed, (ws) => {
|
|
135
127
|
console.log(`auto recover failed: ${ws}`);
|
|
136
128
|
});
|
|
137
|
-
webSocketExtension.eventEmitter.on(Events.autoRecoverError, error => {
|
|
129
|
+
webSocketExtension.eventEmitter.on(Events.autoRecoverError, (error) => {
|
|
138
130
|
console.log(`auto recover error: ${error}`);
|
|
139
131
|
});
|
|
140
132
|
```
|
|
141
133
|
|
|
142
134
|
- Note #1: `autoRecoverError` means cannot connect to WebSocket server at all. There will be more tries. So `autoRecoverError` does NOT mean auto recover gives up trying.
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
- This is most likely caused by local network issue, or in rare cases remote WebSocket server is down.
|
|
136
|
+
- This means a local exception or error.
|
|
145
137
|
- Note #2: `autoRecoverFailed` means connection to WebSocket server has been restored, but existing subscriptions haven't. The SDK automatically created new subscriptions for you.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
- Notifications during WebSocket disconnection are all lost.
|
|
139
|
+
- It could mean `recoveryTimeout` and client side gives up recovery but creates brand new connection instead.
|
|
140
|
+
- It could mean a message from WebSocket server with `"recoveryState": "Failed"`
|
|
149
141
|
- Note #3: `autoRecoverSuccess` means connection to WebSocket server has been restored, and existing subscriptions have been restored too. And server side keeps your notification messages in a buffer and it will send you the messages soon.
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
- There is a `recoveryBufferSize` setting on server side. If there are too many messages queued before session recover success, oldest messages will be discarded.
|
|
152
143
|
|
|
153
144
|
### Manual recover
|
|
154
145
|
|
|
155
146
|
In case of network outage and the WebSocket connection is lost, you can restore the session by:
|
|
156
147
|
|
|
157
148
|
```ts
|
|
158
|
-
await webSocketExtension.recover()
|
|
149
|
+
await webSocketExtension.recover();
|
|
159
150
|
```
|
|
160
151
|
|
|
161
152
|
Command above will create a new WebSocket connection and make sure that subscriptions are recovered.
|
|
162
153
|
|
|
163
|
-
|
|
164
154
|
## How to recover after page refresh?
|
|
165
155
|
|
|
166
156
|
When you refresh page, you lost everything currently in the page's memory.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClosedException.js","sourceRoot":"","sources":["../../src/exceptions/ClosedException.ts"],"names":[],"mappings":";;AAAA,MAAM,eAAgB,SAAQ,KAAK;IACjC,
|
|
1
|
+
{"version":3,"file":"ClosedException.js","sourceRoot":"","sources":["../../src/exceptions/ClosedException.ts"],"names":[],"mappings":";;AAAA,MAAM,eAAgB,SAAQ,KAAK;IACjC,YAAmB,OAAgB;QACjC,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,2BAA2B,CAAC,CAAC;IAChD,CAAC;CACF;AAED,kBAAe,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionException.js","sourceRoot":"","sources":["../../src/exceptions/ConnectionException.ts"],"names":[],"mappings":";;;;;AACA,qDAA6B;AAE7B,MAAM,mBAAoB,SAAQ,KAAK;IAKrC,
|
|
1
|
+
{"version":3,"file":"ConnectionException.js","sourceRoot":"","sources":["../../src/exceptions/ConnectionException.ts"],"names":[],"mappings":";;;;;AACA,qDAA6B;AAE7B,MAAM,mBAAoB,SAAQ,KAAK;IAKrC,YAAmB,QAAkB;QACnC,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAwB,eAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5E,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,kBAAe,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeoutException.js","sourceRoot":"","sources":["../../src/exceptions/TimeoutException.ts"],"names":[],"mappings":";;AAAA,MAAM,gBAAiB,SAAQ,KAAK;IAClC,
|
|
1
|
+
{"version":3,"file":"TimeoutException.js","sourceRoot":"","sources":["../../src/exceptions/TimeoutException.ts"],"names":[],"mappings":";;AAAA,MAAM,gBAAiB,SAAQ,KAAK;IAClC,YAAmB,OAAgB;QACjC,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,uDAAuD,CAAC,CAAC;IAC5E,CAAC;CACF;AAED,kBAAe,gBAAgB,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="ws" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import RingCentral from '@rc-ex/core';
|
|
4
|
+
import type RingCentral from '@rc-ex/core';
|
|
5
5
|
import SdkExtension from '@rc-ex/core/lib/SdkExtension';
|
|
6
6
|
import WS from 'isomorphic-ws';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
|
-
import SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
8
|
+
import type SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
9
9
|
import { request } from './rest';
|
|
10
|
-
import { WsToken, ConnectionDetails, WebSocketOptions, Wsc } from './types';
|
|
10
|
+
import type { WsToken, ConnectionDetails, WebSocketOptions, Wsc } from './types';
|
|
11
11
|
import Subscription from './subscription';
|
|
12
12
|
export declare enum Events {
|
|
13
13
|
autoRecoverSuccess = "autoRecoverSuccess",
|
|
@@ -30,15 +30,15 @@ declare class WebSocketExtension extends SdkExtension {
|
|
|
30
30
|
intervalHandle?: NodeJS.Timeout;
|
|
31
31
|
recoverTimestamp?: number;
|
|
32
32
|
pingServerHandle?: NodeJS.Timeout;
|
|
33
|
+
_recoverPromise?: Promise<void>;
|
|
34
|
+
_connectPromise?: Promise<void>;
|
|
33
35
|
request: typeof request;
|
|
34
36
|
constructor(options?: WebSocketOptions);
|
|
35
37
|
disable(): void;
|
|
36
38
|
install(rc: RingCentral): Promise<void>;
|
|
37
|
-
_recoverPromise?: Promise<void>;
|
|
38
39
|
recover(): Promise<void>;
|
|
39
40
|
_recover(): Promise<void>;
|
|
40
41
|
pingServer(): Promise<void>;
|
|
41
|
-
_connectPromise?: Promise<void>;
|
|
42
42
|
connect(recoverSession?: boolean): Promise<void>;
|
|
43
43
|
_connect(recoverSession?: boolean): Promise<void>;
|
|
44
44
|
revoke(keepInterval?: boolean): Promise<void>;
|
package/lib/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var Events;
|
|
|
25
25
|
Events["newWebSocketObject"] = "newWebSocketObject";
|
|
26
26
|
Events["newWsc"] = "newWsc";
|
|
27
27
|
Events["connectionReady"] = "connectionReady";
|
|
28
|
-
})(Events
|
|
28
|
+
})(Events || (exports.Events = Events = {}));
|
|
29
29
|
class WebSocketExtension extends SdkExtension_1.default {
|
|
30
30
|
constructor(options = {}) {
|
|
31
31
|
var _a, _b, _c, _d, _e;
|
|
@@ -44,7 +44,7 @@ class WebSocketExtension extends SdkExtension_1.default {
|
|
|
44
44
|
const interval = 2000 + 2000 * retriesAttempted;
|
|
45
45
|
return Math.min(8000, interval);
|
|
46
46
|
});
|
|
47
|
-
(_e = (_k = this.options.autoRecover).pingServerInterval) !== null && _e !== void 0 ? _e : (_k.pingServerInterval =
|
|
47
|
+
(_e = (_k = this.options.autoRecover).pingServerInterval) !== null && _e !== void 0 ? _e : (_k.pingServerInterval = 60000);
|
|
48
48
|
}
|
|
49
49
|
disable() {
|
|
50
50
|
super.disable();
|
|
@@ -63,9 +63,9 @@ class WebSocketExtension extends SdkExtension_1.default {
|
|
|
63
63
|
}
|
|
64
64
|
if (
|
|
65
65
|
// the following cannot be done with WebSocket
|
|
66
|
-
((_c = (
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
((_c = (_b = (_a = config === null || config === void 0 ? void 0 : config.headers) === null || _a === void 0 ? void 0 : _a.getContentType) === null || _b === void 0 ? void 0 : _b.toString()) === null || _c === void 0 ? void 0 : _c.includes('multipart/form-data')) ||
|
|
67
|
+
(config === null || config === void 0 ? void 0 : config.responseType) === 'arraybuffer' ||
|
|
68
|
+
endpoint.startsWith('/restapi/oauth/') // token, revoke, wstoken
|
|
69
69
|
) {
|
|
70
70
|
return request(method, endpoint, content, queryParams, config);
|
|
71
71
|
}
|
|
@@ -178,9 +178,8 @@ class WebSocketExtension extends SdkExtension_1.default {
|
|
|
178
178
|
if (this.recoverTimestamp === undefined) {
|
|
179
179
|
this.recoverTimestamp = Date.now();
|
|
180
180
|
}
|
|
181
|
-
if (this.connectionDetails !== undefined
|
|
182
|
-
|
|
183
|
-
> this.connectionDetails.recoveryTimeout * 1000) {
|
|
181
|
+
if (this.connectionDetails !== undefined &&
|
|
182
|
+
Date.now() - this.recoverTimestamp > this.connectionDetails.recoveryTimeout * 1000) {
|
|
184
183
|
if (this.options.debugMode) {
|
|
185
184
|
console.debug('connect to WSG but do not recover');
|
|
186
185
|
}
|
|
@@ -196,27 +195,23 @@ class WebSocketExtension extends SdkExtension_1.default {
|
|
|
196
195
|
this.enable();
|
|
197
196
|
}
|
|
198
197
|
async pingServer() {
|
|
199
|
-
var _a, _b
|
|
198
|
+
var _a, _b;
|
|
200
199
|
if (((_a = this.options.autoRecover) === null || _a === void 0 ? void 0 : _a.enabled) !== true) {
|
|
201
200
|
return;
|
|
202
201
|
}
|
|
202
|
+
if (((_b = this.ws) === null || _b === void 0 ? void 0 : _b.readyState) !== OPEN) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
203
205
|
try {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
await ((_d = this.ws) === null || _d === void 0 ? void 0 : _d.send(JSON.stringify([
|
|
211
|
-
{
|
|
212
|
-
type: 'Heartbeat',
|
|
213
|
-
messageId: uuid(),
|
|
214
|
-
},
|
|
215
|
-
])));
|
|
216
|
-
}
|
|
206
|
+
await this.ws.send(JSON.stringify([
|
|
207
|
+
{
|
|
208
|
+
type: 'Heartbeat',
|
|
209
|
+
messageId: uuid(),
|
|
210
|
+
},
|
|
211
|
+
]));
|
|
217
212
|
}
|
|
218
213
|
catch (e) {
|
|
219
|
-
|
|
214
|
+
this.ws.close(); // Explicitly mark WS as closed
|
|
220
215
|
}
|
|
221
216
|
}
|
|
222
217
|
async connect(recoverSession) {
|
|
@@ -238,7 +233,7 @@ class WebSocketExtension extends SdkExtension_1.default {
|
|
|
238
233
|
const r = await this.rc.post('/restapi/oauth/wstoken');
|
|
239
234
|
this.wsToken = r.data;
|
|
240
235
|
// `expires_in` default value is 600 seconds. That's why we `* 0.8`
|
|
241
|
-
this.wsTokenExpiresAt = Date.now() +
|
|
236
|
+
this.wsTokenExpiresAt = Date.now() + this.wsToken.expires_in * 0.8 * 1000;
|
|
242
237
|
}
|
|
243
238
|
let wsUri = `${this.wsToken.uri}?access_token=${this.wsToken.ws_access_token}`;
|
|
244
239
|
if (recoverSession && this.wsc) {
|
|
@@ -273,10 +268,10 @@ class WebSocketExtension extends SdkExtension_1.default {
|
|
|
273
268
|
this.ws.addEventListener('message', (mEvent) => {
|
|
274
269
|
const event = mEvent;
|
|
275
270
|
const [meta, body] = utils_1.default.splitWsgData(event.data);
|
|
276
|
-
if (meta.wsc
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
271
|
+
if (meta.wsc &&
|
|
272
|
+
(!this.wsc ||
|
|
273
|
+
(meta.type === 'ConnectionDetails' && body.recoveryState) ||
|
|
274
|
+
this.wsc.sequence < meta.wsc.sequence)) {
|
|
280
275
|
this.wsc = meta.wsc;
|
|
281
276
|
this.eventEmitter.emit(Events.newWsc, this.wsc);
|
|
282
277
|
}
|
|
@@ -293,8 +288,7 @@ class WebSocketExtension extends SdkExtension_1.default {
|
|
|
293
288
|
if (this.subscription && this.subscription.enabled) {
|
|
294
289
|
// because we have a new ws object
|
|
295
290
|
this.subscription.setupWsEventListener();
|
|
296
|
-
if (!recoverSession
|
|
297
|
-
|| this.connectionDetails.recoveryState === 'Failed') {
|
|
291
|
+
if (!recoverSession || this.connectionDetails.recoveryState === 'Failed') {
|
|
298
292
|
// create new subscription if don't recover existing one
|
|
299
293
|
await this.subscription.subscribe();
|
|
300
294
|
}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAOA,gFAAwD;AACxD,kEAAiD;AACjD,sDAA8B;AAC9B,mCAAsC;AACtC,oEAAqC;AACrC,kFAA0D;AAG1D,iCAAiC;AASjC,kEAA0C;AAC1C,2FAAmE;AACnE,oDAA4B;AAE5B,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,IAAI,GAAG,CAAC,CAAC;AAEf,MAAM,IAAI,GAAG,IAAA,iBAAO,GAAE,CAAC;AAEvB,IAAY,MAOX;AAPD,WAAY,MAAM;IAChB,mDAAyC,CAAA;IACzC,iDAAuC,CAAA;IACvC,+CAAqC,CAAA;IACrC,mDAAyC,CAAA;IACzC,2BAAiB,CAAA;IACjB,6CAAmC,CAAA;AACrC,CAAC,EAPW,MAAM,GAAN,cAAM,KAAN,cAAM,QAOjB;AAED,MAAM,kBAAmB,SAAQ,sBAAY;IA4B3C,YAAY,UAA4B,EAAE;;;QACxC,KAAK,EAAE,CAAC;QA5BV,i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,SAAS,EAAE,CAAC;SAChC;aAAM;YACL,YAAY,CAAC,gBAAgB,GAAG,KAAK,CAAC;YACtC,MAAM,YAAY,CAAC,OAAO,EAAE,CAAC;SAC9B;QACD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED,kBAAe,kBAAkB,CAAC"}
|
package/lib/rest.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
2
|
-
import { WebSocketExtensionInterface } from './types';
|
|
1
|
+
import type { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
2
|
+
import type { WebSocketExtensionInterface } from './types';
|
|
3
3
|
export declare function request<T>(this: WebSocketExtensionInterface, method: RestMethod, endpoint: string, content?: {}, queryParams?: {}, config?: RestRequestConfig): Promise<RestResponse<T>>;
|
package/lib/rest.js
CHANGED
|
@@ -10,6 +10,7 @@ const http_status_codes_1 = require("http-status-codes");
|
|
|
10
10
|
const utils_1 = __importDefault(require("./utils"));
|
|
11
11
|
const version = '0.16';
|
|
12
12
|
const uuid = (0, hyperid_1.default)();
|
|
13
|
+
// eslint-disable-next-line max-params
|
|
13
14
|
async function request(method, endpoint, content, queryParams, config) {
|
|
14
15
|
var _a;
|
|
15
16
|
const newConfig = {
|
|
@@ -47,9 +48,7 @@ async function request(method, endpoint, content, queryParams, config) {
|
|
|
47
48
|
headers: meta.headers,
|
|
48
49
|
config: newConfig,
|
|
49
50
|
};
|
|
50
|
-
if (meta.type === 'ClientRequest'
|
|
51
|
-
&& meta.status >= 200
|
|
52
|
-
&& meta.status < 300) {
|
|
51
|
+
if (meta.type === 'ClientRequest' && meta.status >= 200 && meta.status < 300) {
|
|
53
52
|
return response;
|
|
54
53
|
}
|
|
55
54
|
throw new RestException_1.default(response);
|
package/lib/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":";;;;;;AACA,kFAA0D;AAC1D,sDAA8B;AAC9B,yDAAoD;AAEpD,oDAA4B;AAG5B,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,MAAM,IAAI,GAAG,IAAA,iBAAO,GAAE,CAAC;AAEvB,sCAAsC;AAC/B,KAAK,UAAU,OAAO,CAE3B,MAAkB,EAClB,QAAgB,EAChB,OAAY,EACZ,WAAgB,EAChB,MAA0B;;IAE1B,MAAM,SAAS,GAAsB;QACnC,MAAM;QACN,OAAO,EAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,GAAG;QAC1B,GAAG,EAAE,QAAQ;QACb,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,WAAW;QACnB,GAAG,MAAM;KACV,CAAC;IACF,SAAS,CAAC,OAAO,GAAG;QAClB,GAAG,SAAS,CAAC,OAAO;QACpB,cAAc,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,IAAK,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,IAAK,CAAC,UAAU,8BAA8B,OAAO,EAAE;KACrG,CAAC;IACT,MAAM,SAAS,GAAG,IAAI,EAAE,CAAC;IACzB,MAAM,WAAW,GAAG;QAClB;YACE,IAAI,EAAE,eAAe;YACrB,SAAS;YACT,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,IAAI,EAAE,SAAS,CAAC,GAAG;YACnB,OAAO,EAAE,SAAS,CAAC,OAAO;YAC1B,KAAK,EAAE,SAAS,CAAC,MAAM;SACxB;KACF,CAAC;IACF,IAAI,SAAS,CAAC,IAAI,EAAE;QAClB,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAClC;IACD,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAChD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,eAAK,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;IAC5G,MAAM,QAAQ,GAAiB;QAC7B,IAAI,EAAE,IAAS;QACf,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,UAAU,EAAE,IAAA,mCAAe,EAAC,IAAI,CAAC,MAAM,CAAC;QACxC,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,EAAE,SAAgB;KACzB,CAAC;IACF,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE;QAC5E,OAAO,QAAQ,CAAC;KACjB;IACD,MAAM,IAAI,uBAAa,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AA/CD,0BA+CC"}
|
package/lib/subscription.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import CreateSubscriptionRequest from '@rc-ex/core/lib/definitions/CreateSubscriptionRequest';
|
|
3
|
-
import SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
4
|
-
import { MessageEvent } from 'ws';
|
|
5
|
-
import { WebSocketExtensionInterface } from './types';
|
|
2
|
+
import type CreateSubscriptionRequest from '@rc-ex/core/lib/definitions/CreateSubscriptionRequest';
|
|
3
|
+
import type SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
4
|
+
import type { MessageEvent } from 'ws';
|
|
5
|
+
import type { WebSocketExtensionInterface } from './types';
|
|
6
6
|
declare class Subscription {
|
|
7
|
+
subscriptionInfo?: SubscriptionInfo;
|
|
7
8
|
wse: WebSocketExtensionInterface;
|
|
8
9
|
eventFilters: string[];
|
|
9
10
|
eventListener: (event: MessageEvent) => void;
|
|
@@ -12,7 +13,6 @@ declare class Subscription {
|
|
|
12
13
|
constructor(wse: WebSocketExtensionInterface, eventFilters: string[], callback: (event: {}) => void);
|
|
13
14
|
setupWsEventListener(): void;
|
|
14
15
|
get requestBody(): CreateSubscriptionRequest;
|
|
15
|
-
subscriptionInfo?: SubscriptionInfo;
|
|
16
16
|
subscribe(): Promise<void>;
|
|
17
17
|
refresh(): Promise<void>;
|
|
18
18
|
revoke(): Promise<void>;
|
package/lib/subscription.js
CHANGED
|
@@ -12,9 +12,7 @@ class Subscription {
|
|
|
12
12
|
this.eventListener = (mEvent) => {
|
|
13
13
|
const event = mEvent;
|
|
14
14
|
const [meta, body] = utils_1.default.splitWsgData(event.data);
|
|
15
|
-
if (this.enabled
|
|
16
|
-
&& meta.type === 'ServerNotification'
|
|
17
|
-
&& body.subscriptionId === this.subscriptionInfo.id) {
|
|
15
|
+
if (this.enabled && meta.type === 'ServerNotification' && body.subscriptionId === this.subscriptionInfo.id) {
|
|
18
16
|
callback(body);
|
|
19
17
|
}
|
|
20
18
|
};
|
package/lib/subscription.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../src/subscription.ts"],"names":[],"mappings":";;;;;AAOA,oDAA4B;AAE5B,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../src/subscription.ts"],"names":[],"mappings":";;;;;AAOA,oDAA4B;AAE5B,MAAM,YAAY;IAahB,YAAmB,GAAgC,EAAE,YAAsB,EAAE,QAA6B;QAFnG,YAAO,GAAG,IAAI,CAAC;QAGpB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,CAAC,MAAoB,EAAE,EAAE;YAC5C,MAAM,KAAK,GAAG,MAAkB,CAAC;YACjC,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,CAAC,EAAE,EAAE;YACf,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;SAChE;QACD,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,SAAS,CAAC;IACpC,CAAC;CACF;AAED,kBAAe,YAAY,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/// <reference types="ws" />
|
|
2
|
-
import RingCentral from '@rc-ex/core';
|
|
3
|
-
import { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
4
|
-
import WS from 'isomorphic-ws';
|
|
5
|
-
export
|
|
2
|
+
import type RingCentral from '@rc-ex/core';
|
|
3
|
+
import type { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
4
|
+
import type WS from 'isomorphic-ws';
|
|
5
|
+
export interface WsToken {
|
|
6
6
|
uri: string;
|
|
7
7
|
ws_access_token: string;
|
|
8
8
|
expires_in: number;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
export type CheckInterval = (retriesAttempted: number) => number;
|
|
11
|
-
export
|
|
11
|
+
export interface WebSocketOptions {
|
|
12
12
|
restOverWebSocket?: boolean;
|
|
13
13
|
debugMode?: boolean;
|
|
14
14
|
autoRecover?: {
|
|
@@ -17,15 +17,15 @@ export type WebSocketOptions = {
|
|
|
17
17
|
pingServerInterval?: number;
|
|
18
18
|
};
|
|
19
19
|
wscToken?: string;
|
|
20
|
-
}
|
|
21
|
-
export
|
|
20
|
+
}
|
|
21
|
+
export interface WsgEvent {
|
|
22
22
|
data: string;
|
|
23
|
-
}
|
|
24
|
-
export
|
|
23
|
+
}
|
|
24
|
+
export interface Wsc {
|
|
25
25
|
token: string;
|
|
26
26
|
sequence: number;
|
|
27
|
-
}
|
|
28
|
-
export
|
|
27
|
+
}
|
|
28
|
+
export interface WsgMeta {
|
|
29
29
|
type: 'ClientRequest' | 'ServerNotification' | 'Error' | 'ConnectionDetails' | 'Heartbeat';
|
|
30
30
|
messageId: string;
|
|
31
31
|
status: number;
|
|
@@ -33,12 +33,12 @@ export type WsgMeta = {
|
|
|
33
33
|
[key: string]: string;
|
|
34
34
|
};
|
|
35
35
|
wsc?: Wsc;
|
|
36
|
-
}
|
|
37
|
-
export
|
|
36
|
+
}
|
|
37
|
+
export interface WsgError {
|
|
38
38
|
errorCode: string;
|
|
39
39
|
message: string;
|
|
40
|
-
}
|
|
41
|
-
export
|
|
40
|
+
}
|
|
41
|
+
export interface ConnectionDetails {
|
|
42
42
|
creationTime: string;
|
|
43
43
|
maxConnectionsPerSession: number;
|
|
44
44
|
recoveryBufferSize: number;
|
|
@@ -48,14 +48,15 @@ export type ConnectionDetails = {
|
|
|
48
48
|
maxActiveRequests: number;
|
|
49
49
|
recoveryState?: 'Successful' | 'Failed';
|
|
50
50
|
recoveryErrorCode?: string;
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
export interface WebSocketExtensionInterface {
|
|
53
53
|
options: WebSocketOptions;
|
|
54
54
|
subscription?: SubscriptionInterface;
|
|
55
55
|
ws: WS;
|
|
56
56
|
wsToken?: WsToken;
|
|
57
57
|
rc: RingCentral;
|
|
58
|
-
request<T>(method: RestMethod, endpoint: string, content?: {}, queryParams?: {}, config?: RestRequestConfig)
|
|
58
|
+
request: <T>(method: RestMethod, endpoint: string, content?: {}, queryParams?: {}, config?: RestRequestConfig) => Promise<RestResponse<T>>;
|
|
59
59
|
}
|
|
60
60
|
export interface SubscriptionInterface {
|
|
61
|
+
eventFilters: string[];
|
|
61
62
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="ws" />
|
|
2
|
-
import WS from 'isomorphic-ws';
|
|
3
|
-
import { WsgMeta, WsgEvent } from './types';
|
|
2
|
+
import type WS from 'isomorphic-ws';
|
|
3
|
+
import type { WsgMeta, WsgEvent } from './types';
|
|
4
4
|
declare class Utils {
|
|
5
5
|
static splitWsgData(wsgData: string): [WsgMeta, any];
|
|
6
6
|
static debugWebSocket(_ws: WS): void;
|
package/lib/utils.js
CHANGED
|
@@ -10,10 +10,7 @@ class Utils {
|
|
|
10
10
|
static splitWsgData(wsgData) {
|
|
11
11
|
if (wsgData.includes(',--Boundary')) {
|
|
12
12
|
const index = wsgData.indexOf(',--Boundary');
|
|
13
|
-
return [
|
|
14
|
-
JSON.parse(wsgData.substring(1, index)),
|
|
15
|
-
wsgData.substring(index + 1, wsgData.length - 1),
|
|
16
|
-
];
|
|
13
|
+
return [JSON.parse(wsgData.substring(1, index)), wsgData.substring(index + 1, wsgData.length - 1)];
|
|
17
14
|
}
|
|
18
15
|
return JSON.parse(wsgData);
|
|
19
16
|
}
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;AAKA,mFAA2D;AAC3D,qFAA6D;AAE7D,MAAM,KAAK;IACT,8DAA8D;IACvD,MAAM,CAAC,YAAY,CAAC,OAAe;QACxC,IAAI,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;YACnC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;SACpG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAEM,MAAM,CAAC,cAAc,CAAC,GAAO;QAClC,MAAM,EAAE,GAAG,G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-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "WebSocket extension for ringcentral-extensible project",
|
|
5
5
|
"author": "Tyler Liu <tyler.liu@ringcentral.com>",
|
|
6
6
|
"homepage": "https://github.com/ringcentral/ringcentral-extensible/tree/master/packages/extensions/ws",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@types/ws": "^8.5.
|
|
22
|
-
"http-status-codes": "^2.
|
|
21
|
+
"@types/ws": "^8.5.6",
|
|
22
|
+
"http-status-codes": "^2.3.0",
|
|
23
23
|
"hyperid": "^3.1.1",
|
|
24
24
|
"isomorphic-ws": "^5.0.0",
|
|
25
25
|
"wait-for-async": "^0.6.1",
|
|
26
|
-
"ws": "^8.
|
|
26
|
+
"ws": "^8.14.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@rc-ex/core": "^1.3.
|
|
29
|
+
"@rc-ex/core": "^1.3.4"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "bf8d43e82125e8b888a7c761e8ca74c90c97e726"
|
|
32
32
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { WsgError, WsgEvent, WsgMeta } from '../types';
|
|
1
|
+
import type { WsgError, WsgEvent, WsgMeta } from '../types';
|
|
2
2
|
import Utils from '../utils';
|
|
3
3
|
|
|
4
4
|
class ConnectionException extends Error {
|
|
5
|
-
wsgEvent: WsgEvent;
|
|
5
|
+
public wsgEvent: WsgEvent;
|
|
6
6
|
|
|
7
|
-
wsgError: WsgError;
|
|
7
|
+
public wsgError: WsgError;
|
|
8
8
|
|
|
9
|
-
constructor(wsgEvent: WsgEvent) {
|
|
9
|
+
public constructor(wsgEvent: WsgEvent) {
|
|
10
10
|
const [, wsgError]: [WsgMeta, WsgError] = Utils.splitWsgData(wsgEvent.data);
|
|
11
11
|
super(JSON.stringify(wsgError, null, 2));
|
|
12
12
|
this.wsgEvent = wsgEvent;
|
package/src/index.ts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import RingCentral from '@rc-ex/core';
|
|
3
|
-
import {
|
|
4
|
-
RestMethod,
|
|
5
|
-
RestRequestConfig,
|
|
6
|
-
RestResponse,
|
|
7
|
-
} from '@rc-ex/core/lib/types';
|
|
2
|
+
import type RingCentral from '@rc-ex/core';
|
|
3
|
+
import type { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
8
4
|
import SdkExtension from '@rc-ex/core/lib/SdkExtension';
|
|
9
|
-
import
|
|
5
|
+
import type { MessageEvent } from 'isomorphic-ws';
|
|
6
|
+
import WS from 'isomorphic-ws';
|
|
10
7
|
import hyperid from 'hyperid';
|
|
11
8
|
import { EventEmitter } from 'events';
|
|
12
9
|
import waitFor from 'wait-for-async';
|
|
13
10
|
import RestException from '@rc-ex/core/lib/RestException';
|
|
14
|
-
import SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
11
|
+
import type SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
15
12
|
|
|
16
13
|
import { request } from './rest';
|
|
17
|
-
import {
|
|
18
|
-
WsToken,
|
|
19
|
-
ConnectionDetails,
|
|
20
|
-
WebSocketOptions,
|
|
21
|
-
WsgEvent,
|
|
22
|
-
Wsc,
|
|
23
|
-
WebSocketExtensionInterface,
|
|
24
|
-
} from './types';
|
|
14
|
+
import type { WsToken, ConnectionDetails, WebSocketOptions, WsgEvent, Wsc, WebSocketExtensionInterface } from './types';
|
|
25
15
|
import Subscription from './subscription';
|
|
26
16
|
import ConnectionException from './exceptions/ConnectionException';
|
|
27
17
|
import Utils from './utils';
|
|
@@ -41,34 +31,38 @@ export enum Events {
|
|
|
41
31
|
}
|
|
42
32
|
|
|
43
33
|
class WebSocketExtension extends SdkExtension {
|
|
44
|
-
eventEmitter = new EventEmitter();
|
|
34
|
+
public eventEmitter = new EventEmitter();
|
|
45
35
|
|
|
46
|
-
options: WebSocketOptions;
|
|
36
|
+
public options: WebSocketOptions;
|
|
47
37
|
|
|
48
|
-
rc!: RingCentral;
|
|
38
|
+
public rc!: RingCentral;
|
|
49
39
|
|
|
50
|
-
wsToken?: WsToken;
|
|
40
|
+
public wsToken?: WsToken;
|
|
51
41
|
|
|
52
|
-
wsTokenExpiresAt = 0;
|
|
42
|
+
public wsTokenExpiresAt = 0;
|
|
53
43
|
|
|
54
|
-
ws!: WS;
|
|
44
|
+
public ws!: WS;
|
|
55
45
|
|
|
56
|
-
connectionDetails!: ConnectionDetails;
|
|
46
|
+
public connectionDetails!: ConnectionDetails;
|
|
57
47
|
|
|
58
|
-
wsc?: Wsc;
|
|
48
|
+
public wsc?: Wsc;
|
|
59
49
|
|
|
60
|
-
subscription?: Subscription;
|
|
50
|
+
public subscription?: Subscription;
|
|
61
51
|
|
|
62
52
|
// for auto recover
|
|
63
|
-
intervalHandle?: NodeJS.Timeout;
|
|
53
|
+
public intervalHandle?: NodeJS.Timeout;
|
|
64
54
|
|
|
65
|
-
recoverTimestamp?: number;
|
|
55
|
+
public recoverTimestamp?: number;
|
|
66
56
|
|
|
67
|
-
pingServerHandle?: NodeJS.Timeout;
|
|
57
|
+
public pingServerHandle?: NodeJS.Timeout;
|
|
68
58
|
|
|
69
|
-
|
|
59
|
+
public _recoverPromise?: Promise<void>;
|
|
70
60
|
|
|
71
|
-
|
|
61
|
+
public _connectPromise?: Promise<void>;
|
|
62
|
+
|
|
63
|
+
public request = request; // request method was moved to another file to keep this file short
|
|
64
|
+
|
|
65
|
+
public constructor(options: WebSocketOptions = {}) {
|
|
72
66
|
super();
|
|
73
67
|
this.options = options;
|
|
74
68
|
this.options.restOverWebSocket ??= false;
|
|
@@ -80,17 +74,17 @@ class WebSocketExtension extends SdkExtension {
|
|
|
80
74
|
const interval = 2000 + 2000 * retriesAttempted;
|
|
81
75
|
return Math.min(8000, interval);
|
|
82
76
|
};
|
|
83
|
-
this.options.autoRecover.pingServerInterval ??=
|
|
77
|
+
this.options.autoRecover.pingServerInterval ??= 60000;
|
|
84
78
|
}
|
|
85
79
|
|
|
86
|
-
disable() {
|
|
80
|
+
public disable() {
|
|
87
81
|
super.disable();
|
|
88
82
|
if (this.subscription) {
|
|
89
83
|
this.subscription.enabled = false;
|
|
90
84
|
}
|
|
91
85
|
}
|
|
92
86
|
|
|
93
|
-
async install(rc: RingCentral) {
|
|
87
|
+
public async install(rc: RingCentral) {
|
|
94
88
|
this.rc = rc;
|
|
95
89
|
if (this.options.restOverWebSocket) {
|
|
96
90
|
const request = rc.request.bind(rc);
|
|
@@ -100,19 +94,18 @@ class WebSocketExtension extends SdkExtension {
|
|
|
100
94
|
content?: {},
|
|
101
95
|
queryParams?: {},
|
|
102
96
|
config?: RestRequestConfig,
|
|
97
|
+
// eslint-disable-next-line max-params
|
|
103
98
|
): Promise<RestResponse<T>> => {
|
|
104
99
|
if (!this.enabled || !this.options.restOverWebSocket) {
|
|
105
|
-
return request
|
|
100
|
+
return request(method, endpoint, content, queryParams, config);
|
|
106
101
|
}
|
|
107
102
|
if (
|
|
108
103
|
// the following cannot be done with WebSocket
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
|| config?.responseType === 'arraybuffer'
|
|
113
|
-
|| endpoint.startsWith('/restapi/oauth/') // token, revoke, wstoken
|
|
104
|
+
config?.headers?.getContentType?.toString()?.includes('multipart/form-data') ||
|
|
105
|
+
config?.responseType === 'arraybuffer' ||
|
|
106
|
+
endpoint.startsWith('/restapi/oauth/') // token, revoke, wstoken
|
|
114
107
|
) {
|
|
115
|
-
return request
|
|
108
|
+
return request(method, endpoint, content, queryParams, config);
|
|
116
109
|
}
|
|
117
110
|
return this.request<T>(method, endpoint, content, queryParams, config);
|
|
118
111
|
};
|
|
@@ -163,9 +156,7 @@ class WebSocketExtension extends SdkExtension {
|
|
|
163
156
|
await this.recover();
|
|
164
157
|
retriesAttempted = 0;
|
|
165
158
|
if (this.options.debugMode) {
|
|
166
|
-
console.debug(
|
|
167
|
-
`Auto recover done, recoveryState: ${this.connectionDetails.recoveryState}`,
|
|
168
|
-
);
|
|
159
|
+
console.debug(`Auto recover done, recoveryState: ${this.connectionDetails.recoveryState}`);
|
|
169
160
|
}
|
|
170
161
|
this.eventEmitter.emit(
|
|
171
162
|
this.connectionDetails.recoveryState === 'Successful'
|
|
@@ -183,17 +174,11 @@ class WebSocketExtension extends SdkExtension {
|
|
|
183
174
|
}
|
|
184
175
|
this.eventEmitter.emit(Events.autoRecoverError, e);
|
|
185
176
|
}
|
|
186
|
-
this.intervalHandle = setInterval(
|
|
187
|
-
check,
|
|
188
|
-
this.options.autoRecover!.checkInterval!(retriesAttempted),
|
|
189
|
-
);
|
|
177
|
+
this.intervalHandle = setInterval(check, this.options.autoRecover!.checkInterval!(retriesAttempted));
|
|
190
178
|
}
|
|
191
179
|
checking = false;
|
|
192
180
|
};
|
|
193
|
-
this.intervalHandle = setInterval(
|
|
194
|
-
check,
|
|
195
|
-
this.options.autoRecover!.checkInterval!(retriesAttempted),
|
|
196
|
-
);
|
|
181
|
+
this.intervalHandle = setInterval(check, this.options.autoRecover!.checkInterval!(retriesAttempted));
|
|
197
182
|
|
|
198
183
|
// browser only code start
|
|
199
184
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
@@ -210,9 +195,7 @@ class WebSocketExtension extends SdkExtension {
|
|
|
210
195
|
// browser only code end
|
|
211
196
|
}
|
|
212
197
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
async recover() {
|
|
198
|
+
public async recover() {
|
|
216
199
|
if (this._recoverPromise) {
|
|
217
200
|
return this._recoverPromise;
|
|
218
201
|
}
|
|
@@ -225,7 +208,7 @@ class WebSocketExtension extends SdkExtension {
|
|
|
225
208
|
return undefined;
|
|
226
209
|
}
|
|
227
210
|
|
|
228
|
-
async _recover() {
|
|
211
|
+
public async _recover() {
|
|
229
212
|
if (this.ws?.readyState === OPEN || this.ws?.readyState === CONNECTING) {
|
|
230
213
|
return;
|
|
231
214
|
}
|
|
@@ -237,9 +220,8 @@ class WebSocketExtension extends SdkExtension {
|
|
|
237
220
|
this.recoverTimestamp = Date.now();
|
|
238
221
|
}
|
|
239
222
|
if (
|
|
240
|
-
this.connectionDetails !== undefined
|
|
241
|
-
|
|
242
|
-
> this.connectionDetails.recoveryTimeout * 1000
|
|
223
|
+
this.connectionDetails !== undefined &&
|
|
224
|
+
Date.now() - this.recoverTimestamp > this.connectionDetails.recoveryTimeout * 1000
|
|
243
225
|
) {
|
|
244
226
|
if (this.options.debugMode) {
|
|
245
227
|
console.debug('connect to WSG but do not recover');
|
|
@@ -255,33 +237,28 @@ class WebSocketExtension extends SdkExtension {
|
|
|
255
237
|
this.enable();
|
|
256
238
|
}
|
|
257
239
|
|
|
258
|
-
async pingServer() {
|
|
240
|
+
public async pingServer() {
|
|
259
241
|
if (this.options.autoRecover?.enabled !== true) {
|
|
260
242
|
return;
|
|
261
243
|
}
|
|
244
|
+
if (this.ws?.readyState !== OPEN) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
262
247
|
try {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
type: 'Heartbeat',
|
|
272
|
-
messageId: uuid(),
|
|
273
|
-
},
|
|
274
|
-
]),
|
|
275
|
-
);
|
|
276
|
-
}
|
|
248
|
+
await this.ws.send(
|
|
249
|
+
JSON.stringify([
|
|
250
|
+
{
|
|
251
|
+
type: 'Heartbeat',
|
|
252
|
+
messageId: uuid(),
|
|
253
|
+
},
|
|
254
|
+
]),
|
|
255
|
+
);
|
|
277
256
|
} catch (e) {
|
|
278
|
-
this.ws
|
|
257
|
+
this.ws.close(); // Explicitly mark WS as closed
|
|
279
258
|
}
|
|
280
259
|
}
|
|
281
260
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
async connect(recoverSession?: boolean) {
|
|
261
|
+
public async connect(recoverSession?: boolean) {
|
|
285
262
|
if (this._connectPromise) {
|
|
286
263
|
return this._connectPromise;
|
|
287
264
|
}
|
|
@@ -294,12 +271,12 @@ class WebSocketExtension extends SdkExtension {
|
|
|
294
271
|
return undefined;
|
|
295
272
|
}
|
|
296
273
|
|
|
297
|
-
async _connect(recoverSession = false) {
|
|
274
|
+
public async _connect(recoverSession = false) {
|
|
298
275
|
if (!this.wsToken || Date.now() > this.wsTokenExpiresAt) {
|
|
299
276
|
const r = await this.rc.post('/restapi/oauth/wstoken');
|
|
300
277
|
this.wsToken = r.data as WsToken;
|
|
301
278
|
// `expires_in` default value is 600 seconds. That's why we `* 0.8`
|
|
302
|
-
this.wsTokenExpiresAt = Date.now() +
|
|
279
|
+
this.wsTokenExpiresAt = Date.now() + this.wsToken.expires_in * 0.8 * 1000;
|
|
303
280
|
}
|
|
304
281
|
let wsUri = `${this.wsToken!.uri}?access_token=${this.wsToken!.ws_access_token}`;
|
|
305
282
|
if (recoverSession && this.wsc) {
|
|
@@ -325,10 +302,7 @@ class WebSocketExtension extends SdkExtension {
|
|
|
325
302
|
if (this.pingServerHandle) {
|
|
326
303
|
clearTimeout(this.pingServerHandle);
|
|
327
304
|
}
|
|
328
|
-
this.pingServerHandle = setTimeout(
|
|
329
|
-
() => this.pingServer(),
|
|
330
|
-
this.options.autoRecover!.pingServerInterval,
|
|
331
|
-
);
|
|
305
|
+
this.pingServerHandle = setTimeout(() => this.pingServer(), this.options.autoRecover!.pingServerInterval);
|
|
332
306
|
});
|
|
333
307
|
}
|
|
334
308
|
|
|
@@ -342,10 +316,10 @@ class WebSocketExtension extends SdkExtension {
|
|
|
342
316
|
const event = mEvent as WsgEvent;
|
|
343
317
|
const [meta, body] = Utils.splitWsgData(event.data);
|
|
344
318
|
if (
|
|
345
|
-
meta.wsc
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
319
|
+
meta.wsc &&
|
|
320
|
+
(!this.wsc ||
|
|
321
|
+
(meta.type === 'ConnectionDetails' && body.recoveryState) ||
|
|
322
|
+
this.wsc.sequence < meta.wsc.sequence)
|
|
349
323
|
) {
|
|
350
324
|
this.wsc = meta.wsc;
|
|
351
325
|
this.eventEmitter.emit(Events.newWsc, this.wsc);
|
|
@@ -369,10 +343,7 @@ class WebSocketExtension extends SdkExtension {
|
|
|
369
343
|
if (this.subscription && this.subscription.enabled) {
|
|
370
344
|
// because we have a new ws object
|
|
371
345
|
this.subscription.setupWsEventListener();
|
|
372
|
-
if (
|
|
373
|
-
!recoverSession
|
|
374
|
-
|| this.connectionDetails.recoveryState === 'Failed'
|
|
375
|
-
) {
|
|
346
|
+
if (!recoverSession || this.connectionDetails.recoveryState === 'Failed') {
|
|
376
347
|
// create new subscription if don't recover existing one
|
|
377
348
|
await this.subscription.subscribe();
|
|
378
349
|
}
|
|
@@ -380,7 +351,7 @@ class WebSocketExtension extends SdkExtension {
|
|
|
380
351
|
}
|
|
381
352
|
|
|
382
353
|
// keepInterval means we do not clear the interval
|
|
383
|
-
async revoke(keepInterval = false) {
|
|
354
|
+
public async revoke(keepInterval = false) {
|
|
384
355
|
await this.subscription?.revoke();
|
|
385
356
|
this.subscription = undefined;
|
|
386
357
|
if (!keepInterval && this.intervalHandle) {
|
|
@@ -396,7 +367,7 @@ class WebSocketExtension extends SdkExtension {
|
|
|
396
367
|
this.disable();
|
|
397
368
|
}
|
|
398
369
|
|
|
399
|
-
async subscribe(
|
|
370
|
+
public async subscribe(
|
|
400
371
|
eventFilters: string[],
|
|
401
372
|
callback: (event: {}) => void,
|
|
402
373
|
cache: SubscriptionInfo | undefined | null = undefined,
|
package/src/rest.ts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RestMethod,
|
|
3
|
-
RestRequestConfig,
|
|
4
|
-
RestResponse,
|
|
5
|
-
} from '@rc-ex/core/lib/types';
|
|
1
|
+
import type { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
6
2
|
import RestException from '@rc-ex/core/lib/RestException';
|
|
7
3
|
import hyperid from 'hyperid';
|
|
8
4
|
import { getReasonPhrase } from 'http-status-codes';
|
|
9
5
|
|
|
10
6
|
import Utils from './utils';
|
|
11
|
-
import {
|
|
12
|
-
WebSocketExtensionInterface,
|
|
13
|
-
} from './types';
|
|
7
|
+
import type { WebSocketExtensionInterface } from './types';
|
|
14
8
|
|
|
15
9
|
const version = '0.16';
|
|
16
10
|
|
|
17
11
|
const uuid = hyperid();
|
|
18
12
|
|
|
13
|
+
// eslint-disable-next-line max-params
|
|
19
14
|
export async function request<T>(
|
|
20
15
|
this: WebSocketExtensionInterface,
|
|
21
16
|
method: RestMethod,
|
|
@@ -51,10 +46,7 @@ export async function request<T>(
|
|
|
51
46
|
requestBody.push(newConfig.data);
|
|
52
47
|
}
|
|
53
48
|
await this.ws.send(JSON.stringify(requestBody));
|
|
54
|
-
const [meta, body] = await Utils.waitForWebSocketMessage(
|
|
55
|
-
this.ws,
|
|
56
|
-
(_meta) => _meta.messageId === messageId,
|
|
57
|
-
);
|
|
49
|
+
const [meta, body] = await Utils.waitForWebSocketMessage(this.ws, (_meta) => _meta.messageId === messageId);
|
|
58
50
|
const response: RestResponse = {
|
|
59
51
|
data: body as T,
|
|
60
52
|
status: meta.status,
|
|
@@ -62,11 +54,7 @@ export async function request<T>(
|
|
|
62
54
|
headers: meta.headers,
|
|
63
55
|
config: newConfig as any,
|
|
64
56
|
};
|
|
65
|
-
if (
|
|
66
|
-
meta.type === 'ClientRequest'
|
|
67
|
-
&& meta.status >= 200
|
|
68
|
-
&& meta.status < 300
|
|
69
|
-
) {
|
|
57
|
+
if (meta.type === 'ClientRequest' && meta.status >= 200 && meta.status < 300) {
|
|
70
58
|
return response;
|
|
71
59
|
}
|
|
72
60
|
throw new RestException(response);
|
package/src/subscription.ts
CHANGED
|
@@ -1,68 +1,56 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import CreateSubscriptionRequest from '@rc-ex/core/lib/definitions/CreateSubscriptionRequest';
|
|
3
|
-
import SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
4
|
-
import { RestResponse } from '@rc-ex/core/lib/types';
|
|
5
|
-
import { MessageEvent } from 'ws';
|
|
2
|
+
import type CreateSubscriptionRequest from '@rc-ex/core/lib/definitions/CreateSubscriptionRequest';
|
|
3
|
+
import type SubscriptionInfo from '@rc-ex/core/lib/definitions/SubscriptionInfo';
|
|
4
|
+
import type { RestResponse } from '@rc-ex/core/lib/types';
|
|
5
|
+
import type { MessageEvent } from 'ws';
|
|
6
6
|
|
|
7
|
-
import { WsgEvent, WsgMeta, WebSocketExtensionInterface } from './types';
|
|
7
|
+
import type { WsgEvent, WsgMeta, WebSocketExtensionInterface } from './types';
|
|
8
8
|
import Utils from './utils';
|
|
9
9
|
|
|
10
10
|
class Subscription {
|
|
11
|
-
|
|
11
|
+
public subscriptionInfo?: SubscriptionInfo;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
public wse: WebSocketExtensionInterface;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
public eventFilters: string[];
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
public eventListener: (event: MessageEvent) => void;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
public timeout?: NodeJS.Timeout;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
callback: (event: {}) => void,
|
|
25
|
-
) {
|
|
21
|
+
public enabled = true;
|
|
22
|
+
|
|
23
|
+
public constructor(wse: WebSocketExtensionInterface, eventFilters: string[], callback: (event: {}) => void) {
|
|
26
24
|
this.wse = wse;
|
|
27
25
|
this.eventFilters = eventFilters;
|
|
28
26
|
this.eventListener = (mEvent: MessageEvent) => {
|
|
29
27
|
const event = mEvent as WsgEvent;
|
|
30
28
|
const [meta, body]: [WsgMeta, { subscriptionId: string }] = Utils.splitWsgData(event.data);
|
|
31
|
-
if (
|
|
32
|
-
this.enabled
|
|
33
|
-
&& meta.type === 'ServerNotification'
|
|
34
|
-
&& body.subscriptionId === this.subscriptionInfo!.id
|
|
35
|
-
) {
|
|
29
|
+
if (this.enabled && meta.type === 'ServerNotification' && body.subscriptionId === this.subscriptionInfo!.id) {
|
|
36
30
|
callback(body);
|
|
37
31
|
}
|
|
38
32
|
};
|
|
39
33
|
this.setupWsEventListener();
|
|
40
34
|
}
|
|
41
35
|
|
|
42
|
-
setupWsEventListener() {
|
|
36
|
+
public setupWsEventListener() {
|
|
43
37
|
this.wse.ws.addEventListener('message', this.eventListener);
|
|
44
38
|
}
|
|
45
39
|
|
|
46
|
-
get requestBody(): CreateSubscriptionRequest {
|
|
40
|
+
public get requestBody(): CreateSubscriptionRequest {
|
|
47
41
|
return {
|
|
48
42
|
deliveryMode: { transportType: 'WebSocket' as any }, // because WebSocket is not in spec
|
|
49
43
|
eventFilters: this.eventFilters,
|
|
50
44
|
};
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
async subscribe() {
|
|
47
|
+
public async subscribe() {
|
|
56
48
|
this.subscriptionInfo = (
|
|
57
|
-
await this.wse.request<SubscriptionInfo>(
|
|
58
|
-
'POST',
|
|
59
|
-
'/restapi/v1.0/subscription',
|
|
60
|
-
this.requestBody,
|
|
61
|
-
)
|
|
49
|
+
await this.wse.request<SubscriptionInfo>('POST', '/restapi/v1.0/subscription', this.requestBody)
|
|
62
50
|
).data;
|
|
63
51
|
}
|
|
64
52
|
|
|
65
|
-
async refresh() {
|
|
53
|
+
public async refresh() {
|
|
66
54
|
if (!this.subscriptionInfo) {
|
|
67
55
|
return;
|
|
68
56
|
}
|
|
@@ -83,24 +71,18 @@ class Subscription {
|
|
|
83
71
|
}
|
|
84
72
|
}
|
|
85
73
|
|
|
86
|
-
async revoke() {
|
|
74
|
+
public async revoke() {
|
|
87
75
|
if (!this.subscriptionInfo) {
|
|
88
76
|
return;
|
|
89
77
|
}
|
|
90
78
|
try {
|
|
91
|
-
await this.wse.request<SubscriptionInfo>(
|
|
92
|
-
'DELETE',
|
|
93
|
-
`/restapi/v1.0/subscription/${this.subscriptionInfo!.id}`,
|
|
94
|
-
);
|
|
79
|
+
await this.wse.request<SubscriptionInfo>('DELETE', `/restapi/v1.0/subscription/${this.subscriptionInfo!.id}`);
|
|
95
80
|
} catch (e) {
|
|
96
81
|
const re = e as { response: RestResponse };
|
|
97
82
|
if (re.response && re.response.status === 404) {
|
|
98
83
|
// ignore
|
|
99
84
|
if (this.wse.options.debugMode) {
|
|
100
|
-
console.debug(
|
|
101
|
-
`Subscription ${this.subscriptionInfo!.id
|
|
102
|
-
} doesn't exist on server side`,
|
|
103
|
-
);
|
|
85
|
+
console.debug(`Subscription ${this.subscriptionInfo!.id} doesn't exist on server side`);
|
|
104
86
|
}
|
|
105
87
|
} else if (re.response && re.response.status === 401) {
|
|
106
88
|
// ignore
|
|
@@ -114,7 +96,7 @@ class Subscription {
|
|
|
114
96
|
this.remove();
|
|
115
97
|
}
|
|
116
98
|
|
|
117
|
-
remove() {
|
|
99
|
+
public remove() {
|
|
118
100
|
if (this.timeout) {
|
|
119
101
|
global.clearTimeout(this.timeout);
|
|
120
102
|
this.timeout = undefined;
|
package/src/types.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import RingCentral from '@rc-ex/core';
|
|
2
|
-
import { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
3
|
-
import WS from 'isomorphic-ws';
|
|
1
|
+
import type RingCentral from '@rc-ex/core';
|
|
2
|
+
import type { RestMethod, RestRequestConfig, RestResponse } from '@rc-ex/core/lib/types';
|
|
3
|
+
import type WS from 'isomorphic-ws';
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export interface WsToken {
|
|
6
6
|
uri: string;
|
|
7
7
|
ws_access_token: string;
|
|
8
8
|
expires_in: number;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
|
|
11
11
|
export type CheckInterval = (retriesAttempted: number) => number;
|
|
12
|
-
export
|
|
12
|
+
export interface WebSocketOptions {
|
|
13
13
|
restOverWebSocket?: boolean;
|
|
14
14
|
debugMode?: boolean;
|
|
15
15
|
autoRecover?: {
|
|
@@ -18,38 +18,33 @@ export type WebSocketOptions = {
|
|
|
18
18
|
pingServerInterval?: number;
|
|
19
19
|
};
|
|
20
20
|
wscToken?: string;
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
export
|
|
23
|
+
export interface WsgEvent {
|
|
24
24
|
data: string;
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
export
|
|
27
|
+
export interface Wsc {
|
|
28
28
|
token: string;
|
|
29
29
|
sequence: number;
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
export
|
|
33
|
-
type:
|
|
34
|
-
| 'ClientRequest'
|
|
35
|
-
| 'ServerNotification'
|
|
36
|
-
| 'Error'
|
|
37
|
-
| 'ConnectionDetails'
|
|
38
|
-
| 'Heartbeat';
|
|
32
|
+
export interface WsgMeta {
|
|
33
|
+
type: 'ClientRequest' | 'ServerNotification' | 'Error' | 'ConnectionDetails' | 'Heartbeat';
|
|
39
34
|
messageId: string;
|
|
40
35
|
status: number;
|
|
41
36
|
headers: {
|
|
42
37
|
[key: string]: string;
|
|
43
38
|
};
|
|
44
39
|
wsc?: Wsc;
|
|
45
|
-
}
|
|
40
|
+
}
|
|
46
41
|
|
|
47
|
-
export
|
|
42
|
+
export interface WsgError {
|
|
48
43
|
errorCode: string;
|
|
49
44
|
message: string;
|
|
50
|
-
}
|
|
45
|
+
}
|
|
51
46
|
|
|
52
|
-
export
|
|
47
|
+
export interface ConnectionDetails {
|
|
53
48
|
creationTime: string;
|
|
54
49
|
maxConnectionsPerSession: number;
|
|
55
50
|
recoveryBufferSize: number;
|
|
@@ -59,7 +54,7 @@ export type ConnectionDetails = {
|
|
|
59
54
|
maxActiveRequests: number;
|
|
60
55
|
recoveryState?: 'Successful' | 'Failed';
|
|
61
56
|
recoveryErrorCode?: string;
|
|
62
|
-
}
|
|
57
|
+
}
|
|
63
58
|
|
|
64
59
|
export interface WebSocketExtensionInterface {
|
|
65
60
|
options: WebSocketOptions;
|
|
@@ -67,14 +62,15 @@ export interface WebSocketExtensionInterface {
|
|
|
67
62
|
ws: WS;
|
|
68
63
|
wsToken?: WsToken;
|
|
69
64
|
rc: RingCentral;
|
|
70
|
-
request<T>(
|
|
65
|
+
request: <T>(
|
|
71
66
|
method: RestMethod,
|
|
72
67
|
endpoint: string,
|
|
73
68
|
content?: {},
|
|
74
69
|
queryParams?: {},
|
|
75
70
|
config?: RestRequestConfig,
|
|
76
|
-
)
|
|
71
|
+
) => Promise<RestResponse<T>>;
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
export interface SubscriptionInterface {
|
|
75
|
+
eventFilters: string[];
|
|
80
76
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import
|
|
2
|
+
import type { MessageEvent } from 'isomorphic-ws';
|
|
3
|
+
import type WS from 'isomorphic-ws';
|
|
3
4
|
|
|
4
|
-
import { WsgMeta, WsgEvent } from './types';
|
|
5
|
+
import type { WsgMeta, WsgEvent } from './types';
|
|
5
6
|
import ClosedException from './exceptions/ClosedException';
|
|
6
7
|
import TimeoutException from './exceptions/TimeoutException';
|
|
7
8
|
|
|
8
9
|
class Utils {
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
static splitWsgData(wsgData: string): [WsgMeta, any] {
|
|
11
|
+
public static splitWsgData(wsgData: string): [WsgMeta, any] {
|
|
11
12
|
if (wsgData.includes(',--Boundary')) {
|
|
12
13
|
const index = wsgData.indexOf(',--Boundary');
|
|
13
|
-
return [
|
|
14
|
-
JSON.parse(wsgData.substring(1, index)),
|
|
15
|
-
wsgData.substring(index + 1, wsgData.length - 1),
|
|
16
|
-
];
|
|
14
|
+
return [JSON.parse(wsgData.substring(1, index)), wsgData.substring(index + 1, wsgData.length - 1)];
|
|
17
15
|
}
|
|
18
16
|
return JSON.parse(wsgData);
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
static debugWebSocket(_ws: WS) {
|
|
19
|
+
public static debugWebSocket(_ws: WS) {
|
|
22
20
|
const ws = _ws;
|
|
23
21
|
const send = ws.send.bind(ws);
|
|
24
22
|
ws.send = async (str: string) => {
|
|
@@ -48,11 +46,7 @@ ${JSON.stringify(JSON.parse(event.data), null, 2)}
|
|
|
48
46
|
});
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
static waitForWebSocketMessage(
|
|
52
|
-
ws: WS,
|
|
53
|
-
matchCondition: (meta: WsgMeta) => boolean,
|
|
54
|
-
timeout = 60000,
|
|
55
|
-
) {
|
|
49
|
+
public static waitForWebSocketMessage(ws: WS, matchCondition: (meta: WsgMeta) => boolean, timeout = 60000) {
|
|
56
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
51
|
return new Promise<[WsgMeta, any, WsgEvent]>((resolve, reject) => {
|
|
58
52
|
const checkHandle = setInterval(() => {
|