@socket-mesh/client 18.1.5 → 19.0.0
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/dist/client-auth-engine.d.ts +7 -7
- package/dist/client-auth-engine.js +15 -12
- package/dist/client-channels.d.ts +13 -12
- package/dist/client-channels.js +80 -75
- package/dist/client-socket-options.d.ts +17 -15
- package/dist/client-socket-options.js +13 -1
- package/dist/client-socket.d.ts +56 -11
- package/dist/client-socket.js +35 -18
- package/dist/client-transport.d.ts +18 -28
- package/dist/client-transport.js +74 -66
- package/dist/handlers/index.d.ts +4 -4
- package/dist/handlers/index.js +4 -4
- package/dist/handlers/kickout.d.ts +6 -7
- package/dist/handlers/kickout.js +1 -3
- package/dist/handlers/publish.d.ts +5 -7
- package/dist/handlers/publish.js +1 -1
- package/dist/handlers/remove-auth-token.d.ts +1 -1
- package/dist/handlers/set-auth-token.d.ts +3 -3
- package/dist/handlers/set-auth-token.js +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/dist/maps/client-map.d.ts +8 -8
- package/dist/maps/index.d.ts +2 -2
- package/dist/maps/index.js +2 -2
- package/dist/maps/server-map.d.ts +11 -11
- package/dist/plugins/batching-plugin.d.ts +20 -22
- package/dist/plugins/batching-plugin.js +41 -22
- package/dist/plugins/in-order-plugin.d.ts +6 -6
- package/dist/plugins/in-order-plugin.js +31 -28
- package/dist/plugins/index.d.ts +3 -3
- package/dist/plugins/index.js +3 -3
- package/dist/plugins/offline-plugin.d.ts +7 -7
- package/dist/plugins/offline-plugin.js +29 -23
- package/package.json +30 -28
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { AutoReconnectOptions, ClientSocketOptions, ConnectOptions } from
|
|
6
|
-
|
|
7
|
-
import { ClientPrivateMap } from "./maps/client-map.js";
|
|
8
|
-
export declare class ClientTransport<TIncoming extends MethodMap, TService extends ServiceMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TState extends object> extends SocketTransport<TIncoming & ClientPrivateMap, TOutgoing, TPrivateOutgoing & ServerPrivateMap, TService, TState> {
|
|
9
|
-
readonly authEngine: ClientAuthEngine;
|
|
10
|
-
private _uri;
|
|
11
|
-
private _wsOptions;
|
|
12
|
-
connectTimeoutMs: number;
|
|
13
|
-
private _connectTimeoutRef;
|
|
1
|
+
import { AuthToken } from '@socket-mesh/auth';
|
|
2
|
+
import { BaseSocketTransport, InvokeMethodOptions, InvokeServiceOptions, SocketStatus, SocketTransport } from '@socket-mesh/core';
|
|
3
|
+
import ws from 'isomorphic-ws';
|
|
4
|
+
import { ClientAuthEngine } from './client-auth-engine.js';
|
|
5
|
+
import { AutoReconnectOptions, ClientSocketOptions, ConnectOptions } from './client-socket-options.js';
|
|
6
|
+
export declare class ClientTransport<TState extends object = {}> extends BaseSocketTransport<TState> implements SocketTransport<{}, {}, TState> {
|
|
14
7
|
private _autoReconnect;
|
|
15
8
|
private _connectAttempts;
|
|
9
|
+
private _connectTimeoutRef;
|
|
16
10
|
private _pendingReconnectTimeout;
|
|
17
11
|
private _pingTimeoutMs;
|
|
12
|
+
private _uri;
|
|
13
|
+
private _wsOptions;
|
|
14
|
+
readonly authEngine: ClientAuthEngine;
|
|
15
|
+
connectTimeoutMs: number;
|
|
18
16
|
isPingTimeoutDisabled: boolean;
|
|
19
|
-
|
|
17
|
+
type: 'client';
|
|
18
|
+
constructor(options: ClientSocketOptions<TState>);
|
|
20
19
|
get autoReconnect(): AutoReconnectOptions | false;
|
|
21
|
-
set autoReconnect(value: Partial<AutoReconnectOptions>
|
|
20
|
+
set autoReconnect(value: boolean | Partial<AutoReconnectOptions>);
|
|
22
21
|
connect(options?: ConnectOptions): void;
|
|
23
22
|
get connectAttempts(): number;
|
|
24
23
|
disconnect(code?: number, reason?: string): void;
|
|
25
24
|
private handshake;
|
|
25
|
+
invoke(methodOptions: [string, string, (false | number)?] | InvokeMethodOptions | InvokeServiceOptions | string, arg?: unknown): [Promise<unknown>, () => void];
|
|
26
26
|
protected onClose(code: number, reason?: Buffer): void;
|
|
27
27
|
protected onOpen(): void;
|
|
28
28
|
protected onPingPong(): void;
|
|
@@ -31,21 +31,11 @@ export declare class ClientTransport<TIncoming extends MethodMap, TService exten
|
|
|
31
31
|
set pingTimeoutMs(value: number);
|
|
32
32
|
private resetReconnect;
|
|
33
33
|
send(data: Buffer | string): Promise<void>;
|
|
34
|
-
setAuthorization(authToken: AuthToken): Promise<boolean>;
|
|
35
34
|
setAuthorization(signedAuthToken: string, authToken?: AuthToken): Promise<boolean>;
|
|
36
35
|
get status(): SocketStatus;
|
|
36
|
+
transmit(serviceAndMethod: [string, string] | string, arg?: unknown): Promise<void>;
|
|
37
37
|
private tryReconnect;
|
|
38
|
-
type: 'client';
|
|
39
38
|
get uri(): URL;
|
|
40
|
-
protected get webSocket(): ws.WebSocket
|
|
41
|
-
protected set webSocket(value: ws.WebSocket
|
|
42
|
-
transmit<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<void>;
|
|
43
|
-
transmit<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod], arg?: Parameters<TService[TServiceName][TMethod]>[0]): Promise<void>;
|
|
44
|
-
transmit<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(method: TMethod, arg?: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): Promise<void>;
|
|
45
|
-
invoke<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
|
|
46
|
-
invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod, (number | false)?], arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
|
|
47
|
-
invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: InvokeServiceOptions<TService, TServiceName, TMethod>, arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
|
|
48
|
-
invoke<TMethod extends keyof TOutgoing>(options: InvokeMethodOptions<TOutgoing, TMethod>, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
|
|
49
|
-
invoke<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(method: TMethod, arg: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): [Promise<FunctionReturnType<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>>, () => void];
|
|
50
|
-
invoke<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(options: InvokeMethodOptions<(TPrivateOutgoing & ServerPrivateMap), TMethod>, arg?: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): [Promise<FunctionReturnType<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>>, () => void];
|
|
39
|
+
protected get webSocket(): null | ws.WebSocket;
|
|
40
|
+
protected set webSocket(value: null | ws.WebSocket);
|
|
51
41
|
}
|
package/dist/client-transport.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { BaseSocketTransport, toError } from '@socket-mesh/core';
|
|
2
|
+
import { hydrateError, SocketClosedError, SocketProtocolErrorStatuses } from '@socket-mesh/errors';
|
|
3
|
+
import ws from 'isomorphic-ws';
|
|
4
|
+
import { isAuthEngine, LocalStorageAuthEngine } from './client-auth-engine.js';
|
|
5
|
+
import { parseAutoReconnectOptions } from './client-socket-options.js';
|
|
6
|
+
export class ClientTransport extends BaseSocketTransport {
|
|
7
|
+
_autoReconnect;
|
|
8
|
+
_connectAttempts;
|
|
9
|
+
_connectTimeoutRef = null;
|
|
10
|
+
_pendingReconnectTimeout;
|
|
11
|
+
_pingTimeoutMs;
|
|
12
|
+
_uri;
|
|
13
|
+
_wsOptions;
|
|
14
|
+
authEngine;
|
|
15
|
+
connectTimeoutMs;
|
|
16
|
+
isPingTimeoutDisabled;
|
|
17
|
+
type;
|
|
6
18
|
constructor(options) {
|
|
7
19
|
super(options);
|
|
8
20
|
this.type = 'client';
|
|
9
21
|
this._uri = typeof options.address === 'string' ? new URL(options.address) : options.address;
|
|
10
22
|
this.authEngine =
|
|
11
|
-
isAuthEngine(options.authEngine)
|
|
12
|
-
options.authEngine
|
|
13
|
-
new LocalStorageAuthEngine(Object.assign({ authTokenName: `socketmesh.authToken${this._uri.protocol}${this._uri.hostname}` }, options.authEngine));
|
|
23
|
+
isAuthEngine(options.authEngine)
|
|
24
|
+
? options.authEngine
|
|
25
|
+
: new LocalStorageAuthEngine(Object.assign({ authTokenName: `socketmesh.authToken${this._uri.protocol}${this._uri.hostname}` }, options.authEngine));
|
|
14
26
|
this.connectTimeoutMs = options.connectTimeoutMs ?? 20000;
|
|
15
27
|
this._pingTimeoutMs = this.connectTimeoutMs;
|
|
16
28
|
if (options.wsOptions) {
|
|
@@ -18,41 +30,31 @@ export class ClientTransport extends SocketTransport {
|
|
|
18
30
|
}
|
|
19
31
|
this._connectAttempts = 0;
|
|
20
32
|
this._pendingReconnectTimeout = null;
|
|
21
|
-
this.
|
|
33
|
+
this._autoReconnect = parseAutoReconnectOptions(options.autoReconnect);
|
|
22
34
|
this.isPingTimeoutDisabled = (options.isPingTimeoutDisabled === true);
|
|
23
35
|
}
|
|
24
36
|
get autoReconnect() {
|
|
25
37
|
return this._autoReconnect;
|
|
26
38
|
}
|
|
27
39
|
set autoReconnect(value) {
|
|
28
|
-
|
|
29
|
-
this._autoReconnect = Object.assign({
|
|
30
|
-
initialDelay: 10000,
|
|
31
|
-
randomness: 10000,
|
|
32
|
-
multiplier: 1.5,
|
|
33
|
-
maxDelayMs: 60000
|
|
34
|
-
}, value === true ? {} : value);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
this._autoReconnect = false;
|
|
38
|
-
}
|
|
40
|
+
this._autoReconnect = parseAutoReconnectOptions(value);
|
|
39
41
|
}
|
|
40
42
|
connect(options) {
|
|
41
43
|
let timeoutMs = this.connectTimeoutMs;
|
|
42
44
|
if (options) {
|
|
43
|
-
let
|
|
45
|
+
let didOptionsChange = false;
|
|
44
46
|
if (options.connectTimeoutMs) {
|
|
45
47
|
timeoutMs = options.connectTimeoutMs;
|
|
46
48
|
}
|
|
47
49
|
if (options.address) {
|
|
48
|
-
|
|
50
|
+
didOptionsChange = true;
|
|
49
51
|
this._uri = typeof options.address === 'string' ? new URL(options.address) : options.address;
|
|
50
52
|
}
|
|
51
53
|
if (options.wsOptions) {
|
|
52
|
-
|
|
54
|
+
didOptionsChange = true;
|
|
53
55
|
this._wsOptions = options.wsOptions;
|
|
54
56
|
}
|
|
55
|
-
if (
|
|
57
|
+
if (didOptionsChange && this.status !== 'closed') {
|
|
56
58
|
this.disconnect(1000, 'Socket was disconnected by the client to initiate a new connection');
|
|
57
59
|
}
|
|
58
60
|
}
|
|
@@ -84,9 +86,29 @@ export class ClientTransport extends SocketTransport {
|
|
|
84
86
|
}
|
|
85
87
|
return status;
|
|
86
88
|
}
|
|
89
|
+
invoke(methodOptions, arg) {
|
|
90
|
+
let wasAborted = false;
|
|
91
|
+
let abort = () => { wasAborted = true; };
|
|
92
|
+
const promise = Promise.resolve()
|
|
93
|
+
.then(() => {
|
|
94
|
+
if (this.status === 'closed') {
|
|
95
|
+
this.connect();
|
|
96
|
+
return this.socket.listen('connect').once();
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
.then(() => {
|
|
100
|
+
const result = super.invoke(methodOptions, arg);
|
|
101
|
+
abort = result[1];
|
|
102
|
+
if (wasAborted) {
|
|
103
|
+
abort();
|
|
104
|
+
}
|
|
105
|
+
return result[0];
|
|
106
|
+
});
|
|
107
|
+
return [promise, () => abort()];
|
|
108
|
+
}
|
|
87
109
|
onClose(code, reason) {
|
|
88
110
|
const status = this.status;
|
|
89
|
-
let
|
|
111
|
+
let isReconnecting = false;
|
|
90
112
|
super.onClose(code, reason);
|
|
91
113
|
// Try to reconnect
|
|
92
114
|
// on server ping timeout (4000)
|
|
@@ -101,30 +123,32 @@ export class ClientTransport extends SocketTransport {
|
|
|
101
123
|
// status, don't wait before trying to reconnect - These could happen
|
|
102
124
|
// if the client wakes up after a period of inactivity and in this case we
|
|
103
125
|
// want to re-establish the connection as soon as possible.
|
|
104
|
-
|
|
126
|
+
isReconnecting = !!this.autoReconnect;
|
|
105
127
|
this.tryReconnect(0);
|
|
106
128
|
// Codes 4500 and above will be treated as permanent disconnects.
|
|
107
129
|
// Socket will not try to auto-reconnect.
|
|
108
130
|
}
|
|
109
131
|
else if (code !== 1000 && code < 4500) {
|
|
110
|
-
|
|
132
|
+
isReconnecting = !!this.autoReconnect;
|
|
111
133
|
this.tryReconnect();
|
|
112
134
|
}
|
|
113
135
|
}
|
|
114
|
-
if (!
|
|
115
|
-
const strReason = reason?.toString() ||
|
|
136
|
+
if (!isReconnecting) {
|
|
137
|
+
const strReason = reason?.toString() || SocketProtocolErrorStatuses[code];
|
|
116
138
|
this.onDisconnect(status, code, strReason);
|
|
117
139
|
}
|
|
118
140
|
}
|
|
119
141
|
onOpen() {
|
|
120
142
|
super.onOpen();
|
|
121
|
-
|
|
122
|
-
|
|
143
|
+
if (this._connectTimeoutRef) {
|
|
144
|
+
clearTimeout(this._connectTimeoutRef);
|
|
145
|
+
this._connectTimeoutRef = null;
|
|
146
|
+
}
|
|
123
147
|
this.resetReconnect();
|
|
124
148
|
this.resetPingTimeout(this.isPingTimeoutDisabled ? false : this.pingTimeoutMs, 4000);
|
|
125
149
|
let authError;
|
|
126
150
|
this.handshake()
|
|
127
|
-
.then(status => {
|
|
151
|
+
.then((status) => {
|
|
128
152
|
this.id = status.id;
|
|
129
153
|
this.pingTimeoutMs = status.pingTimeoutMs;
|
|
130
154
|
if ('authToken' in status && status.authToken) {
|
|
@@ -138,12 +162,11 @@ export class ClientTransport extends SocketTransport {
|
|
|
138
162
|
.then(() => {
|
|
139
163
|
this.setReadyStatus(this.pingTimeoutMs, authError);
|
|
140
164
|
})
|
|
141
|
-
.catch(err => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.
|
|
146
|
-
this.disconnect(err.statusCode, err.toString());
|
|
165
|
+
.catch((err) => {
|
|
166
|
+
const error = toError(err);
|
|
167
|
+
const statusCode = (err != null && typeof err === 'object' && 'statusCode' in err) ? err.statusCode : 4003;
|
|
168
|
+
this.onError(error);
|
|
169
|
+
this.disconnect(statusCode, error.toString());
|
|
147
170
|
});
|
|
148
171
|
}
|
|
149
172
|
onPingPong() {
|
|
@@ -166,6 +189,9 @@ export class ClientTransport extends SocketTransport {
|
|
|
166
189
|
this._connectAttempts = 0;
|
|
167
190
|
}
|
|
168
191
|
async send(data) {
|
|
192
|
+
if (!this.webSocket) {
|
|
193
|
+
throw new SocketClosedError('Web socket is closed.');
|
|
194
|
+
}
|
|
169
195
|
this.webSocket.send(data);
|
|
170
196
|
}
|
|
171
197
|
async setAuthorization(signedAuthToken, authToken) {
|
|
@@ -174,8 +200,8 @@ export class ClientTransport extends SocketTransport {
|
|
|
174
200
|
if (changed) {
|
|
175
201
|
this.triggerAuthenticationEvents(false, wasAuthenticated);
|
|
176
202
|
// Even if saving the auth token failes we do NOT want to throw an exception.
|
|
177
|
-
this.authEngine.saveToken(
|
|
178
|
-
.catch(err => {
|
|
203
|
+
this.authEngine.saveToken(signedAuthToken)
|
|
204
|
+
.catch((err) => {
|
|
179
205
|
this.onError(err);
|
|
180
206
|
});
|
|
181
207
|
}
|
|
@@ -187,6 +213,13 @@ export class ClientTransport extends SocketTransport {
|
|
|
187
213
|
}
|
|
188
214
|
return super.status;
|
|
189
215
|
}
|
|
216
|
+
async transmit(serviceAndMethod, arg) {
|
|
217
|
+
if (this.status === 'closed') {
|
|
218
|
+
this.connect();
|
|
219
|
+
await this.socket.listen('connect').once();
|
|
220
|
+
}
|
|
221
|
+
await super.transmit(serviceAndMethod, arg);
|
|
222
|
+
}
|
|
190
223
|
tryReconnect(initialDelay) {
|
|
191
224
|
if (!this.autoReconnect) {
|
|
192
225
|
return;
|
|
@@ -221,7 +254,7 @@ export class ClientTransport extends SocketTransport {
|
|
|
221
254
|
}
|
|
222
255
|
}
|
|
223
256
|
super.webSocket = value;
|
|
224
|
-
if (this.webSocket
|
|
257
|
+
if (this.webSocket?.on) {
|
|
225
258
|
// WebSockets will throw an error if they are closed before they are completely open.
|
|
226
259
|
// We hook into these events to supress those errors and clean them up after a connection is established.
|
|
227
260
|
function onOpenCloseError() {
|
|
@@ -234,29 +267,4 @@ export class ClientTransport extends SocketTransport {
|
|
|
234
267
|
this.webSocket.on('error', onOpenCloseError);
|
|
235
268
|
}
|
|
236
269
|
}
|
|
237
|
-
async transmit(serviceAndMethod, arg) {
|
|
238
|
-
if (this.status === 'closed') {
|
|
239
|
-
this.connect();
|
|
240
|
-
await this.socket.listen('connect').once();
|
|
241
|
-
}
|
|
242
|
-
await super.transmit(serviceAndMethod, arg);
|
|
243
|
-
}
|
|
244
|
-
invoke(methodOptions, arg) {
|
|
245
|
-
let abort;
|
|
246
|
-
return [
|
|
247
|
-
Promise.resolve()
|
|
248
|
-
.then(() => {
|
|
249
|
-
if (this.status === 'closed') {
|
|
250
|
-
this.connect();
|
|
251
|
-
return this.socket.listen('connect').once();
|
|
252
|
-
}
|
|
253
|
-
})
|
|
254
|
-
.then(() => {
|
|
255
|
-
const result = super.invoke(methodOptions, arg);
|
|
256
|
-
abort = result[1];
|
|
257
|
-
return result[0];
|
|
258
|
-
}),
|
|
259
|
-
abort
|
|
260
|
-
];
|
|
261
|
-
}
|
|
262
270
|
}
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from './kickout.js';
|
|
2
|
+
export * from './publish.js';
|
|
3
|
+
export * from './remove-auth-token.js';
|
|
4
|
+
export * from './set-auth-token.js';
|
package/dist/handlers/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from './kickout.js';
|
|
2
|
+
export * from './publish.js';
|
|
3
|
+
export * from './remove-auth-token.js';
|
|
4
|
+
export * from './set-auth-token.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export declare function kickOutHandler({ socket, options }: RequestHandlerArgs<KickOutOptions, ClientPrivateMap, {}, ServerPrivateMap, {}, {}, ClientSocket<{}, ChannelMap>, ClientTransport<{}, {}, {}, {}, {}>>): Promise<void>;
|
|
1
|
+
import { ChannelMap } from '@socket-mesh/channels';
|
|
2
|
+
import { RequestHandlerArgs } from '@socket-mesh/core';
|
|
3
|
+
import { ClientSocket } from '../client-socket.js';
|
|
4
|
+
import { ClientTransport } from '../client-transport.js';
|
|
5
|
+
import { KickOutOptions } from '../maps/client-map.js';
|
|
6
|
+
export declare function kickOutHandler({ options, socket }: RequestHandlerArgs<KickOutOptions, {}, ClientSocket<{}, {}, ChannelMap>, ClientTransport<{}>>): Promise<void>;
|
package/dist/handlers/kickout.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { ChannelMap, PublishOptions } from
|
|
2
|
-
import { RequestHandlerArgs } from
|
|
3
|
-
import { ClientSocket } from
|
|
4
|
-
import { ClientTransport } from
|
|
5
|
-
|
|
6
|
-
import { ServerPrivateMap } from "../maps/server-map.js";
|
|
7
|
-
export declare function publishHandler({ socket, options }: RequestHandlerArgs<PublishOptions, ClientPrivateMap, {}, ServerPrivateMap, {}, {}, ClientSocket<{}, ChannelMap>, ClientTransport<{}, {}, {}, {}, {}>>): Promise<void>;
|
|
1
|
+
import { ChannelMap, PublishOptions } from '@socket-mesh/channels';
|
|
2
|
+
import { RequestHandlerArgs } from '@socket-mesh/core';
|
|
3
|
+
import { ClientSocket } from '../client-socket.js';
|
|
4
|
+
import { ClientTransport } from '../client-transport.js';
|
|
5
|
+
export declare function publishHandler({ options, socket }: RequestHandlerArgs<PublishOptions, {}, ClientSocket<{}, {}, ChannelMap>, ClientTransport<{}>>): Promise<void>;
|
package/dist/handlers/publish.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RequestHandlerArgs } from
|
|
1
|
+
import { RequestHandlerArgs } from '@socket-mesh/core';
|
|
2
2
|
export declare function removeAuthTokenHandler({ transport }: RequestHandlerArgs<void>): Promise<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SignedAuthToken } from
|
|
2
|
-
import { RequestHandlerArgs } from
|
|
3
|
-
export declare function setAuthTokenHandler({
|
|
1
|
+
import { SignedAuthToken } from '@socket-mesh/auth';
|
|
2
|
+
import { RequestHandlerArgs } from '@socket-mesh/core';
|
|
3
|
+
export declare function setAuthTokenHandler({ options, transport }: RequestHandlerArgs<SignedAuthToken>): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
1
|
+
export * from './client-auth-engine.js';
|
|
2
|
+
export * from './client-channels.js';
|
|
3
|
+
export * from './client-socket-options.js';
|
|
4
|
+
export * from './client-socket.js';
|
|
5
|
+
export * from './client-transport.js';
|
|
6
|
+
export * from './handlers/index.js';
|
|
7
|
+
export * from './maps/index.js';
|
|
8
|
+
export * from './plugins/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
1
|
+
export * from './client-auth-engine.js';
|
|
2
|
+
export * from './client-channels.js';
|
|
3
|
+
export * from './client-socket-options.js';
|
|
4
|
+
export * from './client-socket.js';
|
|
5
|
+
export * from './client-transport.js';
|
|
6
|
+
export * from './handlers/index.js';
|
|
7
|
+
export * from './maps/index.js';
|
|
8
|
+
export * from './plugins/index.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { SignedAuthToken } from
|
|
2
|
-
import { PublishOptions } from
|
|
3
|
-
export interface KickOutOptions {
|
|
4
|
-
channel: string;
|
|
5
|
-
message: string;
|
|
6
|
-
}
|
|
1
|
+
import { SignedAuthToken } from '@socket-mesh/auth';
|
|
2
|
+
import { PublishOptions } from '@socket-mesh/channels';
|
|
7
3
|
export type ClientPrivateMap = {
|
|
8
4
|
'#kickOut': (options: KickOutOptions) => void;
|
|
9
|
-
'#setAuthToken': (token: SignedAuthToken) => void;
|
|
10
|
-
'#removeAuthToken': () => void;
|
|
11
5
|
'#publish': (options: PublishOptions) => void;
|
|
6
|
+
'#removeAuthToken': () => void;
|
|
7
|
+
'#setAuthToken': (token: SignedAuthToken) => void;
|
|
12
8
|
};
|
|
9
|
+
export interface KickOutOptions {
|
|
10
|
+
channel: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
package/dist/maps/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './client-map.js';
|
|
2
|
+
export * from './server-map.js';
|
package/dist/maps/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './client-map.js';
|
|
2
|
+
export * from './server-map.js';
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import { SignedAuthToken } from
|
|
2
|
-
import { ChannelOptions, PublishOptions } from
|
|
3
|
-
export interface
|
|
1
|
+
import { SignedAuthToken } from '@socket-mesh/auth';
|
|
2
|
+
import { ChannelOptions, PublishOptions } from '@socket-mesh/channels';
|
|
3
|
+
export interface HandshakeAuthenticatedStatus {
|
|
4
4
|
authToken: SignedAuthToken;
|
|
5
|
-
}
|
|
6
|
-
export type HandshakeStatus = HandshakeErrorStatus | HandshakeAuthenticatedStatus;
|
|
7
|
-
export interface HandshakeErrorStatus {
|
|
8
5
|
id: string;
|
|
9
6
|
pingTimeoutMs: number;
|
|
10
|
-
authError: Error;
|
|
11
7
|
}
|
|
12
|
-
export interface
|
|
8
|
+
export interface HandshakeErrorStatus {
|
|
9
|
+
authError: Error;
|
|
13
10
|
id: string;
|
|
14
11
|
pingTimeoutMs: number;
|
|
15
|
-
authToken: SignedAuthToken;
|
|
16
12
|
}
|
|
17
|
-
export interface
|
|
18
|
-
|
|
13
|
+
export interface HandshakeOptions {
|
|
14
|
+
authToken: SignedAuthToken;
|
|
19
15
|
}
|
|
16
|
+
export type HandshakeStatus = HandshakeAuthenticatedStatus | HandshakeErrorStatus;
|
|
20
17
|
export type ServerPrivateMap = {
|
|
21
18
|
'#authenticate': (authToken: string) => void;
|
|
22
19
|
'#handshake': (options: HandshakeOptions) => HandshakeStatus;
|
|
@@ -25,3 +22,6 @@ export type ServerPrivateMap = {
|
|
|
25
22
|
'#subscribe': (options: SubscribeOptions) => void;
|
|
26
23
|
'#unsubscribe': (channelName: string) => void;
|
|
27
24
|
};
|
|
25
|
+
export interface SubscribeOptions extends ChannelOptions {
|
|
26
|
+
channel: string;
|
|
27
|
+
}
|
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export interface BatchingPluginOptions {
|
|
4
|
-
batchOnHandshakeDuration?: number | false;
|
|
1
|
+
import { Plugin, SendRequestPluginArgs, SendResponsePluginArgs } from '@socket-mesh/core';
|
|
2
|
+
export interface BatchingPluginOptions<TType = string> {
|
|
5
3
|
batchInterval?: number;
|
|
4
|
+
batchOnHandshakeDuration?: false | number;
|
|
5
|
+
type: TType;
|
|
6
6
|
}
|
|
7
|
-
export declare abstract class BatchingPlugin<
|
|
8
|
-
batchOnHandshakeDuration: number | boolean;
|
|
9
|
-
batchInterval: number;
|
|
7
|
+
export declare abstract class BatchingPlugin<TType extends string> implements Plugin {
|
|
10
8
|
private _batchingIntervalId;
|
|
11
9
|
private _handshakeTimeoutId;
|
|
12
10
|
private _isBatching;
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
batchInterval: number;
|
|
12
|
+
batchOnHandshakeDuration: boolean | number;
|
|
13
|
+
type: TType;
|
|
14
|
+
constructor(options: BatchingPluginOptions<TType>);
|
|
15
15
|
cancelBatching(): void;
|
|
16
16
|
protected abstract flush(): void;
|
|
17
17
|
get isBatching(): boolean;
|
|
18
|
-
onReady(): void;
|
|
19
18
|
onDisconnected(): void;
|
|
20
|
-
|
|
19
|
+
onReady(): void;
|
|
21
20
|
private start;
|
|
22
|
-
|
|
21
|
+
startBatching(): void;
|
|
23
22
|
private stop;
|
|
23
|
+
stopBatching(): void;
|
|
24
24
|
}
|
|
25
|
-
export declare class RequestBatchingPlugin
|
|
26
|
-
private _requests;
|
|
25
|
+
export declare class RequestBatchingPlugin extends BatchingPlugin<'requestBatching'> {
|
|
27
26
|
private _continue;
|
|
28
|
-
|
|
27
|
+
private _requests;
|
|
28
|
+
constructor(options?: Omit<BatchingPluginOptions, 'type'>);
|
|
29
29
|
cancelBatching(): void;
|
|
30
30
|
protected flush(): void;
|
|
31
|
-
sendRequest({
|
|
32
|
-
type: 'requestBatching';
|
|
31
|
+
sendRequest({ cont, requests }: SendRequestPluginArgs): void;
|
|
33
32
|
}
|
|
34
|
-
export declare class ResponseBatchingPlugin
|
|
35
|
-
private _responses;
|
|
33
|
+
export declare class ResponseBatchingPlugin extends BatchingPlugin<'responseBatching'> {
|
|
36
34
|
private _continue;
|
|
37
|
-
|
|
35
|
+
private _responses;
|
|
36
|
+
constructor(options?: Omit<BatchingPluginOptions, 'type'>);
|
|
38
37
|
protected flush(): void;
|
|
39
|
-
sendResponse({
|
|
40
|
-
type: 'responseBatching';
|
|
38
|
+
sendResponse({ cont, responses }: SendResponsePluginArgs): void;
|
|
41
39
|
}
|