@api.global/typedsocket 4.0.0 → 4.1.2
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_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/typedsocket.classes.typedsocket.d.ts +114 -31
- package/dist_ts/typedsocket.classes.typedsocket.js +372 -191
- package/dist_ts/typedsocket.plugins.d.ts +3 -2
- package/dist_ts/typedsocket.plugins.js +4 -3
- package/npmextra.json +13 -7
- package/package.json +14 -17
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/typedsocket.classes.typedsocket.ts +491 -279
- package/ts/typedsocket.plugins.ts +4 -3
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@api.global/typedsocket',
|
|
6
|
-
version: '4.
|
|
6
|
+
version: '4.1.2',
|
|
7
7
|
description: 'A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx5QkFBeUI7SUFDL0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLCtHQUErRztDQUM3SCxDQUFBIn0=
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import * as plugins from './typedsocket.plugins.js';
|
|
2
2
|
export type TTypedSocketSide = 'server' | 'client';
|
|
3
|
+
export type TConnectionStatus = 'new' | 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
|
|
4
|
+
/**
|
|
5
|
+
* Options for creating a TypedSocket client
|
|
6
|
+
*/
|
|
7
|
+
export interface ITypedSocketClientOptions {
|
|
8
|
+
autoReconnect?: boolean;
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
initialBackoffMs?: number;
|
|
11
|
+
maxBackoffMs?: number;
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Wrapper for SmartServe's IWebSocketPeer to provide tag compatibility
|
|
5
|
-
* SmartServe uses Set<string> for tags, while TypedSocket uses {id, payload} format
|
|
6
15
|
*/
|
|
7
16
|
export interface ISmartServeConnectionWrapper {
|
|
8
17
|
peer: plugins.IWebSocketPeer;
|
|
@@ -13,15 +22,32 @@ export interface ISmartServeConnectionWrapper {
|
|
|
13
22
|
}
|
|
14
23
|
export declare class TypedSocket {
|
|
15
24
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
25
|
+
* Creates a TypedSocket client using native WebSocket.
|
|
26
|
+
* Works in both browser and Node.js environments.
|
|
27
|
+
*
|
|
28
|
+
* @param typedrouterArg - TypedRouter for handling server-initiated requests
|
|
29
|
+
* @param serverUrlArg - Server URL (e.g., 'http://localhost:3000' or 'wss://example.com')
|
|
30
|
+
* @param options - Connection options
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const typedRouter = new TypedRouter();
|
|
35
|
+
* const client = await TypedSocket.createClient(
|
|
36
|
+
* typedRouter,
|
|
37
|
+
* 'http://localhost:3000',
|
|
38
|
+
* { autoReconnect: true }
|
|
39
|
+
* );
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static createClient(typedrouterArg: plugins.typedrequest.TypedRouter, serverUrlArg: string, options?: ITypedSocketClientOptions): Promise<TypedSocket>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the current window location origin URL.
|
|
45
|
+
* Useful in browser environments for connecting to the same origin.
|
|
18
46
|
*/
|
|
19
|
-
static createServer(typedrouterArg: plugins.typedrequest.TypedRouter): Promise<TypedSocket>;
|
|
20
|
-
static createClient(typedrouterArg: plugins.typedrequest.TypedRouter, serverUrlArg: string, aliasArg?: string): Promise<TypedSocket>;
|
|
21
47
|
static useWindowLocationOriginUrl: () => string;
|
|
22
48
|
/**
|
|
23
49
|
* Creates a TypedSocket server from an existing SmartServe instance.
|
|
24
|
-
*
|
|
50
|
+
* This is the only way to create a server-side TypedSocket.
|
|
25
51
|
*
|
|
26
52
|
* @param smartServeArg - SmartServe instance with typedRouter configured in websocket options
|
|
27
53
|
* @param typedRouterArg - TypedRouter for handling requests (must match SmartServe's typedRouter)
|
|
@@ -41,41 +67,98 @@ export declare class TypedSocket {
|
|
|
41
67
|
* ```
|
|
42
68
|
*/
|
|
43
69
|
static fromSmartServe(smartServeArg: plugins.SmartServe, typedRouterArg: plugins.typedrequest.TypedRouter): TypedSocket;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Registers built-in TypedHandlers for tag management
|
|
72
|
+
*/
|
|
73
|
+
private static registerTagHandlers;
|
|
74
|
+
readonly side: TTypedSocketSide;
|
|
75
|
+
readonly typedrouter: plugins.typedrequest.TypedRouter;
|
|
76
|
+
statusSubject: plugins.smartrx.rxjs.Subject<TConnectionStatus>;
|
|
77
|
+
private connectionStatus;
|
|
78
|
+
private websocket;
|
|
79
|
+
private clientOptions;
|
|
80
|
+
private serverUrl;
|
|
81
|
+
private retryCount;
|
|
82
|
+
private currentBackoff;
|
|
83
|
+
private pendingRequests;
|
|
84
|
+
private smartServeRef;
|
|
47
85
|
private smartServeConnectionWrappers;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
86
|
+
private constructor();
|
|
87
|
+
/**
|
|
88
|
+
* Connects the client to the server using native WebSocket
|
|
89
|
+
*/
|
|
90
|
+
private connect;
|
|
91
|
+
/**
|
|
92
|
+
* Converts an HTTP(S) URL to a WebSocket URL
|
|
93
|
+
*/
|
|
94
|
+
private toWebSocketUrl;
|
|
95
|
+
/**
|
|
96
|
+
* Handles incoming WebSocket messages
|
|
97
|
+
*/
|
|
98
|
+
private handleMessage;
|
|
54
99
|
/**
|
|
55
|
-
*
|
|
56
|
-
* Works with both Smartsocket and SmartServe backends
|
|
57
|
-
* @param asyncFindFuncArg - async filter function
|
|
58
|
-
* @returns array of matching connections
|
|
100
|
+
* Handles WebSocket disconnection
|
|
59
101
|
*/
|
|
60
|
-
|
|
102
|
+
private handleDisconnect;
|
|
61
103
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @param asyncFindFuncArg
|
|
64
|
-
* @returns
|
|
104
|
+
* Schedules a reconnection attempt with exponential backoff
|
|
65
105
|
*/
|
|
66
|
-
|
|
106
|
+
private scheduleReconnect;
|
|
67
107
|
/**
|
|
68
|
-
*
|
|
69
|
-
* Works with both Smartsocket and SmartServe backends
|
|
108
|
+
* Updates connection status and notifies subscribers
|
|
70
109
|
*/
|
|
71
|
-
|
|
110
|
+
private updateStatus;
|
|
72
111
|
/**
|
|
73
|
-
*
|
|
112
|
+
* Sends a request to the server and waits for response (client-side)
|
|
74
113
|
*/
|
|
75
|
-
|
|
114
|
+
private sendRequest;
|
|
76
115
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
116
|
+
* Creates a TypedRequest for the specified method.
|
|
117
|
+
* On clients, sends to the server.
|
|
118
|
+
* On servers, sends to the specified target connection.
|
|
119
|
+
*/
|
|
120
|
+
createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(methodName: T['method'], targetConnection?: ISmartServeConnectionWrapper): plugins.typedrequest.TypedRequest<T>;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the current connection status
|
|
123
|
+
*/
|
|
124
|
+
getStatus(): TConnectionStatus;
|
|
125
|
+
/**
|
|
126
|
+
* Stops the TypedSocket client or cleans up server state
|
|
79
127
|
*/
|
|
80
128
|
stop(): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Sets a tag on this client connection.
|
|
131
|
+
* Tags are stored on the server and can be used for filtering.
|
|
132
|
+
* @client-only
|
|
133
|
+
*/
|
|
134
|
+
setTag<T extends plugins.typedrequestInterfaces.ITag>(name: T['name'], payload: T['payload']): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Removes a tag from this client connection.
|
|
137
|
+
* @client-only
|
|
138
|
+
*/
|
|
139
|
+
removeTag(name: string): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Gets or creates a connection wrapper for a peer
|
|
142
|
+
*/
|
|
143
|
+
private getOrCreateWrapper;
|
|
144
|
+
/**
|
|
145
|
+
* Finds all connections matching the filter function.
|
|
146
|
+
* @server-only
|
|
147
|
+
*/
|
|
148
|
+
findAllTargetConnections(asyncFindFuncArg: (connectionArg: ISmartServeConnectionWrapper) => Promise<boolean>): Promise<ISmartServeConnectionWrapper[]>;
|
|
149
|
+
/**
|
|
150
|
+
* Finds the first connection matching the filter function.
|
|
151
|
+
* @server-only
|
|
152
|
+
*/
|
|
153
|
+
findTargetConnection(asyncFindFuncArg: (connectionArg: ISmartServeConnectionWrapper) => Promise<boolean>): Promise<ISmartServeConnectionWrapper | undefined>;
|
|
154
|
+
/**
|
|
155
|
+
* Finds all connections with the specified tag.
|
|
156
|
+
* @server-only
|
|
157
|
+
*/
|
|
158
|
+
findAllTargetConnectionsByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<ISmartServeConnectionWrapper[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Finds the first connection with the specified tag.
|
|
161
|
+
* @server-only
|
|
162
|
+
*/
|
|
163
|
+
findTargetConnectionByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<ISmartServeConnectionWrapper | undefined>;
|
|
81
164
|
}
|