@socket-mesh/server 17.3.7 → 18.0.1
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/action.d.ts +34 -34
- package/action.js +4 -8
- package/auth-engine.d.ts +5 -5
- package/inbound-packet.d.ts +11 -11
- package/index.d.ts +12 -11
- package/index.js +5 -4
- package/middleware-stream.d.ts +2 -2
- package/outbound-packet.d.ts +8 -8
- package/package.json +56 -58
- package/request.d.ts +4 -4
- package/server-options.d.ts +2 -2
- package/server.d.ts +52 -52
- package/server.js +88 -126
- package/serversocket-procedure.d.ts +6 -6
- package/serversocket.d.ts +20 -21
- package/serversocket.js +659 -723
package/action.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { AuthState, AuthToken, SignedAuthToken } from "@socket-mesh/auth";
|
|
|
5
5
|
import { IncomingMessage } from 'http';
|
|
6
6
|
import { DataPacket } from "@socket-mesh/simple-broker";
|
|
7
7
|
import { ChannelOptions } from "@socket-mesh/channel";
|
|
8
|
-
import { ServerSocket } from "./serversocket";
|
|
9
|
-
import { HandshakeRequest } from "./request";
|
|
8
|
+
import { ServerSocket } from "./serversocket.js";
|
|
9
|
+
import { HandshakeRequest } from "./request.js";
|
|
10
10
|
export declare enum ActionType {
|
|
11
11
|
HANDSHAKE_WS = "handshakeWS",
|
|
12
12
|
HANDSHAKE_SC = "handshakeSC",
|
|
@@ -35,9 +35,9 @@ export declare abstract class Action<T, U extends ActionType = ActionType> {
|
|
|
35
35
|
allow: (packet?: ActionResult<T>) => void;
|
|
36
36
|
block: (error: Error) => void;
|
|
37
37
|
}
|
|
38
|
-
export type MiddlewareAction
|
|
39
|
-
export type InboundAction
|
|
40
|
-
export type HandshakeAction
|
|
38
|
+
export type MiddlewareAction = ActionTransmit | ActionInvoke | ActionPublishIn | ActionPublishOut | ActionSubscribe | ActionHandshakeSC | ActionHandshakeWS | ActionAuthenticate | ActionMessage;
|
|
39
|
+
export type InboundAction = ActionAuthenticate | ActionTransmit | ActionInvoke | ActionPublishIn | ActionSubscribe;
|
|
40
|
+
export type HandshakeAction = ActionHandshakeSC | ActionHandshakeWS;
|
|
41
41
|
export declare class ActionHandshakeWS extends Action<undefined, ActionType.HANDSHAKE_WS> {
|
|
42
42
|
constructor(request: IncomingMessage);
|
|
43
43
|
request: IncomingMessage;
|
|
@@ -53,54 +53,54 @@ export type AuthInfo = {
|
|
|
53
53
|
authToken: AuthToken;
|
|
54
54
|
authState: AuthState;
|
|
55
55
|
};
|
|
56
|
-
export declare class ActionHandshakeSC
|
|
57
|
-
constructor(socket: ServerSocket
|
|
56
|
+
export declare class ActionHandshakeSC extends Action<AuthInfo, ActionType.HANDSHAKE_SC> {
|
|
57
|
+
constructor(socket: ServerSocket, request: HandshakeRequest, data: AuthInfo);
|
|
58
58
|
request: HandshakeRequest;
|
|
59
|
-
socket: ServerSocket
|
|
59
|
+
socket: ServerSocket;
|
|
60
60
|
data: AuthInfo;
|
|
61
61
|
}
|
|
62
|
-
export declare class ActionMessage
|
|
63
|
-
constructor(socket: ServerSocket
|
|
64
|
-
socket: ServerSocket
|
|
62
|
+
export declare class ActionMessage extends Action<string | ArrayBuffer | Buffer[], ActionType.MESSAGE> {
|
|
63
|
+
constructor(socket: ServerSocket, data: string | ArrayBuffer | Buffer[]);
|
|
64
|
+
socket: ServerSocket;
|
|
65
65
|
data: string | ArrayBuffer | Buffer[];
|
|
66
66
|
}
|
|
67
|
-
export declare class ActionTransmit
|
|
68
|
-
constructor(socket: ServerSocket
|
|
69
|
-
socket: ServerSocket
|
|
67
|
+
export declare class ActionTransmit extends Action<any, ActionType.TRANSMIT> {
|
|
68
|
+
constructor(socket: ServerSocket, receiver: string, packet: DataPacket<any>);
|
|
69
|
+
socket: ServerSocket;
|
|
70
70
|
authTokenExpiredError?: AuthTokenExpiredError;
|
|
71
71
|
receiver: string;
|
|
72
|
-
data?: DataPacket<
|
|
72
|
+
data?: DataPacket<any>;
|
|
73
73
|
}
|
|
74
|
-
export declare class ActionInvoke
|
|
75
|
-
constructor(socket: ServerSocket
|
|
76
|
-
socket: ServerSocket
|
|
74
|
+
export declare class ActionInvoke extends Action<any, ActionType.INVOKE> {
|
|
75
|
+
constructor(socket: ServerSocket, procedure: string, packet?: DataPacket<any>);
|
|
76
|
+
socket: ServerSocket;
|
|
77
77
|
authTokenExpiredError?: AuthTokenExpiredError;
|
|
78
78
|
procedure: string;
|
|
79
|
-
data?: DataPacket<
|
|
79
|
+
data?: DataPacket<any>;
|
|
80
80
|
}
|
|
81
|
-
export declare class ActionSubscribe
|
|
82
|
-
constructor(socket: ServerSocket
|
|
83
|
-
socket: ServerSocket
|
|
81
|
+
export declare class ActionSubscribe extends Action<ChannelOptions, ActionType.SUBSCRIBE> {
|
|
82
|
+
constructor(socket: ServerSocket, packet?: DataPacket<ChannelOptions>);
|
|
83
|
+
socket: ServerSocket;
|
|
84
84
|
authTokenExpiredError?: AuthTokenExpiredError;
|
|
85
85
|
channel: string;
|
|
86
86
|
data?: ChannelOptions;
|
|
87
87
|
}
|
|
88
|
-
export declare class ActionPublishIn
|
|
89
|
-
constructor(socket: ServerSocket
|
|
90
|
-
socket: ServerSocket
|
|
88
|
+
export declare class ActionPublishIn extends Action<any, ActionType.PUBLISH_IN> {
|
|
89
|
+
constructor(socket: ServerSocket, packet: Partial<DataPacket<any>>);
|
|
90
|
+
socket: ServerSocket;
|
|
91
91
|
authTokenExpiredError?: AuthTokenExpiredError;
|
|
92
|
-
channel
|
|
93
|
-
data?:
|
|
92
|
+
channel: string;
|
|
93
|
+
data?: any;
|
|
94
94
|
}
|
|
95
|
-
export declare class ActionPublishOut
|
|
96
|
-
constructor(socket: ServerSocket
|
|
97
|
-
socket: ServerSocket
|
|
95
|
+
export declare class ActionPublishOut extends Action<any, ActionType.PUBLISH_OUT> {
|
|
96
|
+
constructor(socket: ServerSocket);
|
|
97
|
+
socket: ServerSocket;
|
|
98
98
|
channel?: string;
|
|
99
|
-
data?:
|
|
99
|
+
data?: any;
|
|
100
100
|
}
|
|
101
|
-
export declare class ActionAuthenticate
|
|
102
|
-
constructor(socket: ServerSocket
|
|
103
|
-
socket: ServerSocket
|
|
101
|
+
export declare class ActionAuthenticate extends Action<undefined, ActionType.AUTHENTICATE> {
|
|
102
|
+
constructor(socket: ServerSocket, authToken: AuthToken, signedAuthToken: SignedAuthToken);
|
|
103
|
+
socket: ServerSocket;
|
|
104
104
|
authToken: AuthToken;
|
|
105
105
|
signedAuthToken: string;
|
|
106
106
|
}
|
package/action.js
CHANGED
|
@@ -80,20 +80,16 @@ export class ActionSubscribe extends Action {
|
|
|
80
80
|
constructor(socket, packet) {
|
|
81
81
|
super(ActionType.SUBSCRIBE);
|
|
82
82
|
this.socket = socket;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.data = packet.data;
|
|
86
|
-
}
|
|
83
|
+
this.channel = packet.channel;
|
|
84
|
+
this.data = packet.data;
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
export class ActionPublishIn extends Action {
|
|
90
88
|
constructor(socket, packet) {
|
|
91
89
|
super(ActionType.PUBLISH_IN);
|
|
92
90
|
this.socket = socket;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.data = packet.data;
|
|
96
|
-
}
|
|
91
|
+
this.channel = packet.channel;
|
|
92
|
+
this.data = packet.data;
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
95
|
export class ActionPublishOut extends Action {
|
package/auth-engine.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import jwt from 'jsonwebtoken';
|
|
3
|
-
import { ServerSocket } from './serversocket';
|
|
3
|
+
import { ServerSocket } from './serversocket.js';
|
|
4
4
|
export interface AuthTokenOptions extends jwt.SignOptions {
|
|
5
5
|
rejectOnFailedDelivery?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export interface VerifyOptions
|
|
8
|
-
socket: ServerSocket
|
|
7
|
+
export interface VerifyOptions extends jwt.VerifyOptions {
|
|
8
|
+
socket: ServerSocket;
|
|
9
9
|
}
|
|
10
|
-
export declare class AuthEngine
|
|
11
|
-
verifyToken(signedToken: string, key: jwt.Secret | jwt.GetPublicKeyOrSecret, options: VerifyOptions
|
|
10
|
+
export declare class AuthEngine {
|
|
11
|
+
verifyToken(signedToken: string, key: jwt.Secret | jwt.GetPublicKeyOrSecret, options: VerifyOptions): Promise<jwt.JwtPayload>;
|
|
12
12
|
signToken(token: string | object | Buffer, key: jwt.Secret, options: jwt.SignOptions): Promise<string>;
|
|
13
13
|
}
|
package/inbound-packet.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SignedAuthToken } from "@socket-mesh/auth";
|
|
2
2
|
import { ChannelOptions } from "@socket-mesh/channel";
|
|
3
3
|
import { DataPacket } from "@socket-mesh/simple-broker";
|
|
4
|
-
export type InboundPacket
|
|
4
|
+
export type InboundPacket = InboundHandshakePacket | InboundDataPacket | InboundPublishPacket | InboundSubscribePacket | InboundUnsubscribePacket | InboundAuthenticatePacket | InboundRemoveAuthTokenPacket;
|
|
5
5
|
export interface InboundHandshakePacket {
|
|
6
6
|
event: '#handshake';
|
|
7
7
|
cid: number;
|
|
@@ -19,10 +19,10 @@ export interface InboundUnsubscribePacket {
|
|
|
19
19
|
cid?: number;
|
|
20
20
|
data: string;
|
|
21
21
|
}
|
|
22
|
-
export interface InboundPublishPacket
|
|
22
|
+
export interface InboundPublishPacket {
|
|
23
23
|
event: '#publish';
|
|
24
24
|
cid?: number;
|
|
25
|
-
data?: Partial<DataPacket<
|
|
25
|
+
data?: Partial<DataPacket<any>>;
|
|
26
26
|
}
|
|
27
27
|
export interface InboundAuthenticatePacket {
|
|
28
28
|
event: '#authenticate';
|
|
@@ -33,16 +33,16 @@ export interface InboundRemoveAuthTokenPacket {
|
|
|
33
33
|
event: '#removeAuthToken';
|
|
34
34
|
data: undefined;
|
|
35
35
|
}
|
|
36
|
-
export interface InboundDataPacket
|
|
36
|
+
export interface InboundDataPacket {
|
|
37
37
|
event: string | null;
|
|
38
38
|
rid: number | null;
|
|
39
39
|
cid?: number | null;
|
|
40
|
-
data: DataPacket<
|
|
40
|
+
data: DataPacket<any>;
|
|
41
41
|
error: any;
|
|
42
42
|
}
|
|
43
|
-
export declare function isHandshakePacket
|
|
44
|
-
export declare function isSubscribePacket
|
|
45
|
-
export declare function isUnsubscribePacket
|
|
46
|
-
export declare function isPublishPacket
|
|
47
|
-
export declare function isAuthenticatePacket
|
|
48
|
-
export declare function isRemoveAuthTokenPacket
|
|
43
|
+
export declare function isHandshakePacket(packet: InboundPacket): packet is InboundHandshakePacket;
|
|
44
|
+
export declare function isSubscribePacket(packet: InboundPacket): packet is InboundSubscribePacket;
|
|
45
|
+
export declare function isUnsubscribePacket(packet: InboundPacket): packet is InboundUnsubscribePacket;
|
|
46
|
+
export declare function isPublishPacket(packet: InboundPacket): packet is InboundPublishPacket;
|
|
47
|
+
export declare function isAuthenticatePacket(packet: InboundPacket): packet is InboundAuthenticatePacket;
|
|
48
|
+
export declare function isRemoveAuthTokenPacket(packet: InboundPacket): packet is InboundRemoveAuthTokenPacket;
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import http from "http";
|
|
3
|
-
import { Server } from "./server";
|
|
4
|
-
import { ServerOptions } from "./server-options";
|
|
5
|
-
export { Server } from "./server";
|
|
6
|
-
export { ServerSocket } from "./serversocket";
|
|
7
|
-
export { ServerOptions } from "./server-options";
|
|
8
|
-
export { MiddlewareType } from "./middleware-type";
|
|
3
|
+
import { Server } from "./server.js";
|
|
4
|
+
import { ServerOptions } from "./server-options.js";
|
|
5
|
+
export { Server } from "./server.js";
|
|
6
|
+
export { ServerSocket } from "./serversocket.js";
|
|
7
|
+
export { ServerOptions } from "./server-options.js";
|
|
8
|
+
export { MiddlewareType } from "./middleware-type.js";
|
|
9
|
+
export * from "./action.js";
|
|
9
10
|
/**
|
|
10
11
|
* Creates an http.Server exclusively used for WS upgrades.
|
|
11
12
|
*
|
|
@@ -15,10 +16,10 @@ export { MiddlewareType } from "./middleware-type";
|
|
|
15
16
|
* @return {AGServer} websocket cluster server
|
|
16
17
|
* @api public
|
|
17
18
|
*/
|
|
18
|
-
export declare function listen
|
|
19
|
-
export declare function listen
|
|
20
|
-
export declare function listen
|
|
21
|
-
export declare function listen
|
|
19
|
+
export declare function listen(): Server;
|
|
20
|
+
export declare function listen(port: number, fn: () => void): Server;
|
|
21
|
+
export declare function listen(port: number, options: ServerOptions): Server;
|
|
22
|
+
export declare function listen(port: number, options: ServerOptions, fn: () => void): Server;
|
|
22
23
|
/**
|
|
23
24
|
* Captures upgrade requests for a http.Server.
|
|
24
25
|
*
|
|
@@ -27,4 +28,4 @@ export declare function listen<T>(port: number, options: ServerOptions, fn: () =
|
|
|
27
28
|
* @return {AGServer} websocket cluster server
|
|
28
29
|
* @api public
|
|
29
30
|
*/
|
|
30
|
-
export declare function attach
|
|
31
|
+
export declare function attach(server: http.Server, options?: ServerOptions): Server;
|
package/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import http from "http";
|
|
2
|
-
import { Server } from "./server";
|
|
3
|
-
export { Server } from "./server";
|
|
4
|
-
export { ServerSocket } from "./serversocket";
|
|
5
|
-
export { MiddlewareType } from "./middleware-type";
|
|
2
|
+
import { Server } from "./server.js";
|
|
3
|
+
export { Server } from "./server.js";
|
|
4
|
+
export { ServerSocket } from "./serversocket.js";
|
|
5
|
+
export { MiddlewareType } from "./middleware-type.js";
|
|
6
|
+
export * from "./action.js";
|
|
6
7
|
export function listen(port, options, fn) {
|
|
7
8
|
if (typeof options === 'function') {
|
|
8
9
|
fn = options;
|
package/middleware-stream.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WritableConsumableStream } from "@socket-mesh/writable-consumable-stream";
|
|
2
|
-
import { MiddlewareType } from "./middleware-type";
|
|
3
|
-
import { Action, ActionType } from "./action";
|
|
2
|
+
import { MiddlewareType } from "./middleware-type.js";
|
|
3
|
+
import { Action, ActionType } from "./action.js";
|
|
4
4
|
export declare class MiddlewareStream<T extends Action<any, ActionType>> extends WritableConsumableStream<T> {
|
|
5
5
|
readonly type: MiddlewareType;
|
|
6
6
|
constructor(type: MiddlewareType);
|
package/outbound-packet.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { DataPacket } from "@socket-mesh/simple-broker";
|
|
2
|
-
export type OutboundPacket
|
|
3
|
-
export interface OutboundPublishPacket
|
|
2
|
+
export type OutboundPacket = OutboundPublishPacket | OutboundTransmitPacket | OutboundInvokePacket;
|
|
3
|
+
export interface OutboundPublishPacket {
|
|
4
4
|
event: '#publish';
|
|
5
|
-
data: DataPacket<
|
|
5
|
+
data: DataPacket<any>;
|
|
6
6
|
options?: OutboundPacketOptions;
|
|
7
7
|
}
|
|
8
|
-
export interface OutboundTransmitPacket
|
|
8
|
+
export interface OutboundTransmitPacket {
|
|
9
9
|
event: string;
|
|
10
|
-
data:
|
|
10
|
+
data: any;
|
|
11
11
|
options?: OutboundPacketOptions;
|
|
12
12
|
}
|
|
13
|
-
export interface OutboundInvokePacket
|
|
13
|
+
export interface OutboundInvokePacket {
|
|
14
14
|
event: string;
|
|
15
|
-
data:
|
|
15
|
+
data: any;
|
|
16
16
|
options?: OutboundPacketOptions;
|
|
17
17
|
resolve: (value: any) => void;
|
|
18
18
|
reject: (err: Error) => void;
|
|
@@ -22,4 +22,4 @@ export interface OutboundPacketOptions {
|
|
|
22
22
|
useCache?: boolean;
|
|
23
23
|
stringifiedData?: string;
|
|
24
24
|
}
|
|
25
|
-
export declare function isPublishOutPacket
|
|
25
|
+
export declare function isPublishOutPacket(packet: OutboundPacket): packet is OutboundPublishPacket;
|
package/package.json
CHANGED
|
@@ -1,60 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"@socket-mesh/consumable-stream": "3.2.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"@socket-mesh/channel": "6.0.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"@socket-mesh/client": "^
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
],
|
|
59
|
-
"license": "MIT"
|
|
2
|
+
"name": "@socket-mesh/server",
|
|
3
|
+
"version": "18.0.1",
|
|
4
|
+
"description": "Server module for SocketMesh",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git://github.com/socket-mesh/server.git"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@socket-mesh/async-stream-emitter": "^7.0.2",
|
|
13
|
+
"@socket-mesh/consumable-stream": "3.2.1",
|
|
14
|
+
"@socket-mesh/auth": "^2.1.6",
|
|
15
|
+
"@socket-mesh/errors": "^3.0.8",
|
|
16
|
+
"@socket-mesh/formatter": "^4.0.5",
|
|
17
|
+
"@socket-mesh/request": "^2.0.9",
|
|
18
|
+
"@socket-mesh/simple-broker": "^6.0.0",
|
|
19
|
+
"@socket-mesh/stream-demux": "^10.0.1",
|
|
20
|
+
"@socket-mesh/writable-consumable-stream": "^4.2.9",
|
|
21
|
+
"@socket-mesh/channel": "6.0.25",
|
|
22
|
+
"base64id": "^2.0.0",
|
|
23
|
+
"clone-deep": "^4.0.1",
|
|
24
|
+
"jsonwebtoken": "^9.0.2",
|
|
25
|
+
"ws": "^8.14.2"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@socket-mesh/client": "^18.0.3",
|
|
29
|
+
"@socket-mesh/local-storage": "^1.0.2",
|
|
30
|
+
"@types/base64id": "^2.0.1",
|
|
31
|
+
"@types/clone-deep": "^4.0.3",
|
|
32
|
+
"@types/jsonwebtoken": "^9.0.4",
|
|
33
|
+
"@types/ws": "^8.5.8",
|
|
34
|
+
"cross-env": "^7.0.3",
|
|
35
|
+
"ts-node": "^10.9.1",
|
|
36
|
+
"typescript": "^5.2.2"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "node ./scripts/build.mjs && tsc",
|
|
40
|
+
"deploy": "cd dist && npm publish --access public",
|
|
41
|
+
"test": "cross-env node --test --loader ts-node/esm test/test.ts"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"websocket",
|
|
45
|
+
"realtime",
|
|
46
|
+
"socketcluster",
|
|
47
|
+
"socketmesh"
|
|
48
|
+
],
|
|
49
|
+
"author": "Jonathan Gros-Dubois <grosjona@yahoo.com.au>",
|
|
50
|
+
"contributors": [
|
|
51
|
+
"Greg Kimmy",
|
|
52
|
+
{
|
|
53
|
+
"name": "Jonathan Gros-Dubois",
|
|
54
|
+
"email": "grosjona@yahoo.com.au"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"license": "MIT"
|
|
60
58
|
}
|
package/request.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Request, RequestSocket, RequestWithResponse } from "@socket-mesh/request";
|
|
2
|
-
import { Connected } from "./events";
|
|
2
|
+
import { Connected } from "./events.js";
|
|
3
3
|
import { DataPacket } from "@socket-mesh/simple-broker";
|
|
4
4
|
import { ChannelOptions } from "@socket-mesh/channel";
|
|
5
|
-
export type InboundRequest
|
|
5
|
+
export type InboundRequest = HandshakeRequest | SubscribeRequest | UnsubscribeRequest | AuthenticateRequest | PublishRequest | InvokeRequest<any, any>;
|
|
6
6
|
export interface HandshakeData {
|
|
7
7
|
authToken: string;
|
|
8
8
|
}
|
|
9
9
|
export declare class HandshakeRequest extends RequestWithResponse<HandshakeData, Connected> {
|
|
10
10
|
constructor(socket: RequestSocket, id: number, procedureName: '#handshake', data: HandshakeData);
|
|
11
11
|
}
|
|
12
|
-
export type InvokeRequest<T, U
|
|
12
|
+
export type InvokeRequest<T, U> = RequestWithResponse<T, U>;
|
|
13
13
|
export type SubscribeRequest = Request<Partial<DataPacket<ChannelOptions>>>;
|
|
14
|
-
export type PublishRequest
|
|
14
|
+
export type PublishRequest = Request<Partial<DataPacket<any>>>;
|
|
15
15
|
export declare class UnsubscribeRequest extends Request<string> {
|
|
16
16
|
constructor(socket: RequestSocket, id: number, procedureName: '#unsubscribe', data: string);
|
|
17
17
|
}
|
package/server-options.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CodecEngine } from "@socket-mesh/formatter";
|
|
|
3
3
|
import ws from "ws";
|
|
4
4
|
import jwt from "jsonwebtoken";
|
|
5
5
|
import { Server as HttpServer } from 'http';
|
|
6
|
-
import { AuthEngine } from "./auth-engine";
|
|
6
|
+
import { AuthEngine } from "./auth-engine.js";
|
|
7
7
|
export type ProtocolVersions = 1 | 2;
|
|
8
8
|
export interface ServerOptions {
|
|
9
9
|
httpServer?: HttpServer;
|
|
@@ -30,7 +30,7 @@ export interface ServerOptions {
|
|
|
30
30
|
batchInterval?: number;
|
|
31
31
|
socketStreamCleanupMode?: 'kill' | 'close' | 'none';
|
|
32
32
|
authVerifyAlgorithms?: jwt.Algorithm[];
|
|
33
|
-
authEngine?: AuthEngine
|
|
33
|
+
authEngine?: AuthEngine;
|
|
34
34
|
codecEngine?: CodecEngine;
|
|
35
35
|
cloneData?: boolean;
|
|
36
36
|
strictHandshake?: boolean;
|
package/server.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { AuthEngine } from "./auth-engine";
|
|
3
|
+
import { AuthEngine } from "./auth-engine.js";
|
|
4
4
|
import { CodecEngine } from "@socket-mesh/formatter";
|
|
5
5
|
import { Broker, Packet } from "@socket-mesh/simple-broker";
|
|
6
6
|
import { AsyncStreamEmitter } from "@socket-mesh/async-stream-emitter";
|
|
7
|
-
import { MiddlewareType } from "./middleware-type";
|
|
8
|
-
import { MiddlewareStream } from "./middleware-stream";
|
|
9
|
-
import { ActionAuthenticate, ActionHandshakeSC, ActionHandshakeWS, ActionMessage, ActionPublishOut, ActionResult, ActionSubscribe, AuthInfo, HandshakeAction, InboundAction, MiddlewareAction } from "./action";
|
|
10
|
-
import { ProtocolVersions, ServerOptions } from "./server-options";
|
|
7
|
+
import { MiddlewareType } from "./middleware-type.js";
|
|
8
|
+
import { MiddlewareStream } from "./middleware-stream.js";
|
|
9
|
+
import { ActionAuthenticate, ActionHandshakeSC, ActionHandshakeWS, ActionMessage, ActionPublishOut, ActionResult, ActionSubscribe, AuthInfo, HandshakeAction, InboundAction, MiddlewareAction } from "./action.js";
|
|
10
|
+
import { ProtocolVersions, ServerOptions } from "./server-options.js";
|
|
11
11
|
import { PerMessageDeflateOptions, WebSocketServer } from 'ws';
|
|
12
12
|
import jwt from "jsonwebtoken";
|
|
13
13
|
import { Server as HttpServer } from 'http';
|
|
14
|
-
import { ServerSocket } from "./serversocket";
|
|
14
|
+
import { ServerSocket } from "./serversocket.js";
|
|
15
15
|
import { ChannelOptions, Client } from "@socket-mesh/channel";
|
|
16
|
-
import { AuthStateChanged, Authenticated, BadAuthToken, Closed, ConnectAborted, Connected, Deauthenticated, Disconnected, ErrorOccurred, ServerSocketEvents, Subscribed, Unsubscribed, WarningOccurred } from "./events";
|
|
16
|
+
import { AuthStateChanged, Authenticated, BadAuthToken, Closed, ConnectAborted, Connected, Deauthenticated, Disconnected, ErrorOccurred, ServerSocketEvents, Subscribed, Unsubscribed, WarningOccurred } from "./events.js";
|
|
17
17
|
import { DemuxedConsumableStream } from "@socket-mesh/stream-demux";
|
|
18
|
-
export type ServerEvent<T
|
|
19
|
-
socket: ServerSocket
|
|
20
|
-
} &
|
|
21
|
-
type ServerEvents
|
|
22
|
-
export declare class Server
|
|
18
|
+
export type ServerEvent<T extends ServerSocketEvents | {}> = {
|
|
19
|
+
socket: ServerSocket;
|
|
20
|
+
} & T;
|
|
21
|
+
type ServerEvents = ServerEvent<Connected> | ServerEvent<ConnectAborted> | ServerEvent<Disconnected> | ServerEvent<Closed> | {} | ServerEvent<BadAuthToken> | ServerEvent<Authenticated> | ServerEvent<AuthStateChanged> | ServerEvent<Deauthenticated> | ServerEvent<{}> | ErrorOccurred | WarningOccurred | ServerEvent<Subscribed> | ServerEvent<Unsubscribed>;
|
|
22
|
+
export declare class Server extends AsyncStreamEmitter<ServerEvents> {
|
|
23
23
|
allowClientPublish: boolean;
|
|
24
|
-
auth: AuthEngine
|
|
24
|
+
auth: AuthEngine;
|
|
25
25
|
clientsCount: number;
|
|
26
26
|
codec: CodecEngine;
|
|
27
27
|
defaultVerificationOptions: jwt.VerifyOptions;
|
|
@@ -45,69 +45,69 @@ export declare class Server<T> extends AsyncStreamEmitter<ServerEvents<T>> {
|
|
|
45
45
|
socketChannelLimit?: number;
|
|
46
46
|
verificationKey: jwt.Secret;
|
|
47
47
|
readonly clients: {
|
|
48
|
-
[id: string]: ServerSocket
|
|
48
|
+
[id: string]: ServerSocket;
|
|
49
49
|
};
|
|
50
50
|
readonly pendingClients: {
|
|
51
|
-
[id: string]: ServerSocket
|
|
51
|
+
[id: string]: ServerSocket;
|
|
52
52
|
};
|
|
53
|
-
readonly brokerEngine: Broker<
|
|
54
|
-
readonly exchange: Client<Packet<
|
|
53
|
+
readonly brokerEngine: Broker<any>;
|
|
54
|
+
readonly exchange: Client<Packet<any>>;
|
|
55
55
|
readonly wsServer: WebSocketServer;
|
|
56
56
|
private readonly _allowAllOrigins;
|
|
57
57
|
private readonly _path;
|
|
58
58
|
private readonly _middleware;
|
|
59
59
|
constructor(options: ServerOptions);
|
|
60
|
-
setAuthEngine(authEngine: AuthEngine
|
|
60
|
+
setAuthEngine(authEngine: AuthEngine): void;
|
|
61
61
|
setCodecEngine(codecEngine: CodecEngine): void;
|
|
62
62
|
emitError(error: Error): void;
|
|
63
63
|
emitWarning(warning: Error): void;
|
|
64
64
|
private _handleServerError;
|
|
65
65
|
private _handleSocketConnection;
|
|
66
|
-
emit(eventName: 'connection', data: ServerEvent<
|
|
67
|
-
emit(eventName: 'connectionAbort', data: ServerEvent<
|
|
68
|
-
emit(eventName: 'disconnection', data: ServerEvent<
|
|
69
|
-
emit(eventName: 'closure', data: ServerEvent<
|
|
66
|
+
emit(eventName: 'connection', data: ServerEvent<Connected>): void;
|
|
67
|
+
emit(eventName: 'connectionAbort', data: ServerEvent<ConnectAborted>): void;
|
|
68
|
+
emit(eventName: 'disconnection', data: ServerEvent<Disconnected>): void;
|
|
69
|
+
emit(eventName: 'closure', data: ServerEvent<Closed>): void;
|
|
70
70
|
emit(eventName: 'ready', data: {}): void;
|
|
71
|
-
emit(eventName: 'authentication', data: ServerEvent<
|
|
72
|
-
emit(eventName: 'badSocketAuthToken', data: ServerEvent<
|
|
71
|
+
emit(eventName: 'authentication', data: ServerEvent<Authenticated>): void;
|
|
72
|
+
emit(eventName: 'badSocketAuthToken', data: ServerEvent<BadAuthToken>): void;
|
|
73
73
|
emit(eventName: 'error', data: ErrorOccurred): void;
|
|
74
|
-
emit(eventName: 'handshake', data: ServerEvent<
|
|
74
|
+
emit(eventName: 'handshake', data: ServerEvent<{}>): void;
|
|
75
75
|
emit(eventName: 'warning', data: WarningOccurred): void;
|
|
76
|
-
emit(eventName: 'subscription', data: ServerEvent<
|
|
77
|
-
emit(eventName: 'unsubscription', data: ServerEvent<
|
|
78
|
-
emit(eventName: 'authenticationStateChange', data: ServerEvent<
|
|
79
|
-
emit(eventName: 'deauthentication', data: ServerEvent<
|
|
80
|
-
listen(eventName: 'connection'): DemuxedConsumableStream<ServerEvent<
|
|
81
|
-
listen(eventName: 'connectionAbort'): DemuxedConsumableStream<ServerEvent<
|
|
82
|
-
listen(eventName: 'disconnection'): DemuxedConsumableStream<ServerEvent<
|
|
83
|
-
listen(eventName: 'closure'): DemuxedConsumableStream<ServerEvent<
|
|
76
|
+
emit(eventName: 'subscription', data: ServerEvent<Subscribed>): void;
|
|
77
|
+
emit(eventName: 'unsubscription', data: ServerEvent<Unsubscribed>): void;
|
|
78
|
+
emit(eventName: 'authenticationStateChange', data: ServerEvent<AuthStateChanged>): void;
|
|
79
|
+
emit(eventName: 'deauthentication', data: ServerEvent<Deauthenticated>): void;
|
|
80
|
+
listen(eventName: 'connection'): DemuxedConsumableStream<ServerEvent<Connected>>;
|
|
81
|
+
listen(eventName: 'connectionAbort'): DemuxedConsumableStream<ServerEvent<ConnectAborted>>;
|
|
82
|
+
listen(eventName: 'disconnection'): DemuxedConsumableStream<ServerEvent<Disconnected>>;
|
|
83
|
+
listen(eventName: 'closure'): DemuxedConsumableStream<ServerEvent<Closed>>;
|
|
84
84
|
listen(eventName: 'ready'): DemuxedConsumableStream<{}>;
|
|
85
|
-
listen(eventName: 'authentication'): DemuxedConsumableStream<ServerEvent<
|
|
86
|
-
listen(eventName: 'badSocketAuthToken'): DemuxedConsumableStream<ServerEvent<
|
|
85
|
+
listen(eventName: 'authentication'): DemuxedConsumableStream<ServerEvent<Authenticated>>;
|
|
86
|
+
listen(eventName: 'badSocketAuthToken'): DemuxedConsumableStream<ServerEvent<BadAuthToken>>;
|
|
87
87
|
listen(eventName: 'error'): DemuxedConsumableStream<ErrorOccurred>;
|
|
88
|
-
listen(eventName: 'handshake'): DemuxedConsumableStream<ServerEvent<
|
|
88
|
+
listen(eventName: 'handshake'): DemuxedConsumableStream<ServerEvent<{}>>;
|
|
89
89
|
listen(eventName: 'warning'): DemuxedConsumableStream<WarningOccurred>;
|
|
90
|
-
listen(eventName: 'subscription'): DemuxedConsumableStream<ServerEvent<
|
|
91
|
-
listen(eventName: 'unsubscription'): DemuxedConsumableStream<ServerEvent<
|
|
92
|
-
listen(eventName: 'authenticationStateChange'): DemuxedConsumableStream<ServerEvent<
|
|
93
|
-
listen(eventName: 'deauthentication'): DemuxedConsumableStream<ServerEvent<
|
|
90
|
+
listen(eventName: 'subscription'): DemuxedConsumableStream<ServerEvent<Subscribed>>;
|
|
91
|
+
listen(eventName: 'unsubscription'): DemuxedConsumableStream<ServerEvent<Unsubscribed>>;
|
|
92
|
+
listen(eventName: 'authenticationStateChange'): DemuxedConsumableStream<ServerEvent<AuthStateChanged>>;
|
|
93
|
+
listen(eventName: 'deauthentication'): DemuxedConsumableStream<ServerEvent<Deauthenticated>>;
|
|
94
94
|
close(keepSocketsOpen?: boolean): Promise<void>;
|
|
95
95
|
getPath(): string;
|
|
96
96
|
generateId(): string;
|
|
97
|
-
setMiddleware(type: MiddlewareType.MIDDLEWARE_HANDSHAKE, middleware: (stream: MiddlewareStream<HandshakeAction
|
|
98
|
-
setMiddleware(type: MiddlewareType.MIDDLEWARE_INBOUND_RAW, middleware: (stream: MiddlewareStream<ActionMessage
|
|
99
|
-
setMiddleware(type: MiddlewareType.MIDDLEWARE_INBOUND, middleware: (stream: MiddlewareStream<InboundAction
|
|
100
|
-
setMiddleware(type: MiddlewareType.MIDDLEWARE_OUTBOUND, middleware: (stream: MiddlewareStream<ActionPublishOut
|
|
97
|
+
setMiddleware(type: MiddlewareType.MIDDLEWARE_HANDSHAKE, middleware: (stream: MiddlewareStream<HandshakeAction>) => void): void;
|
|
98
|
+
setMiddleware(type: MiddlewareType.MIDDLEWARE_INBOUND_RAW, middleware: (stream: MiddlewareStream<ActionMessage>) => void): void;
|
|
99
|
+
setMiddleware(type: MiddlewareType.MIDDLEWARE_INBOUND, middleware: (stream: MiddlewareStream<InboundAction>) => void): void;
|
|
100
|
+
setMiddleware(type: MiddlewareType.MIDDLEWARE_OUTBOUND, middleware: (stream: MiddlewareStream<ActionPublishOut>) => void): void;
|
|
101
101
|
removeMiddleware(type: MiddlewareType): void;
|
|
102
102
|
hasMiddleware(type: MiddlewareType): boolean;
|
|
103
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<InboundAction
|
|
104
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionAuthenticate
|
|
105
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionPublishOut
|
|
106
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionSubscribe
|
|
107
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionHandshakeWS>, action: ActionHandshakeWS, socket?: ServerSocket
|
|
108
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionHandshakeSC
|
|
109
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionMessage
|
|
110
|
-
_processMiddlewareAction(middlewareStream: MiddlewareStream<MiddlewareAction
|
|
103
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<InboundAction>, action: InboundAction, socket?: ServerSocket): Promise<ActionResult<any>>;
|
|
104
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionAuthenticate>, action: ActionAuthenticate, socket?: ServerSocket): Promise<ActionResult<void>>;
|
|
105
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionPublishOut>, action: ActionPublishOut, socket?: ServerSocket): Promise<ActionResult<any>>;
|
|
106
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionSubscribe>, action: ActionSubscribe, socket?: ServerSocket): Promise<ActionResult<ChannelOptions>>;
|
|
107
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionHandshakeWS>, action: ActionHandshakeWS, socket?: ServerSocket): Promise<ActionResult<void>>;
|
|
108
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionHandshakeSC>, action: ActionHandshakeSC, socket?: ServerSocket): Promise<ActionResult<void>>;
|
|
109
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<ActionMessage>, action: ActionMessage, socket?: ServerSocket): Promise<ActionResult<string | ArrayBuffer | Buffer[]>>;
|
|
110
|
+
_processMiddlewareAction(middlewareStream: MiddlewareStream<MiddlewareAction>, action: MiddlewareAction, socket?: ServerSocket): Promise<ActionResult<any | ChannelOptions | AuthInfo | string | ArrayBuffer | Buffer[] | void>>;
|
|
111
111
|
private _verifyHandshake;
|
|
112
112
|
}
|
|
113
113
|
export {};
|