@api.global/typedsocket 3.0.1 → 3.1.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * autocreated commitinfo by @pushrocks/commitinfo
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
3
  */
4
4
  export declare const commitinfo: {
5
5
  name: string;
@@ -1,9 +1,9 @@
1
1
  /**
2
- * autocreated commitinfo by @pushrocks/commitinfo
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@api.global/typedsocket',
6
- version: '3.0.1',
6
+ version: '3.1.1',
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,5 +1,16 @@
1
1
  import * as plugins from './typedsocket.plugins.js';
2
2
  export type TTypedSocketSide = 'server' | 'client';
3
+ /**
4
+ * Wrapper for SmartServe's IWebSocketPeer to provide tag compatibility
5
+ * SmartServe uses Set<string> for tags, while TypedSocket uses {id, payload} format
6
+ */
7
+ export interface ISmartServeConnectionWrapper {
8
+ peer: plugins.IWebSocketPeer;
9
+ getTagById(tagId: string): Promise<{
10
+ id: string;
11
+ payload: any;
12
+ } | undefined>;
13
+ }
3
14
  export declare class TypedSocket {
4
15
  /**
5
16
  * creates a typedsocket server
@@ -8,27 +19,63 @@ export declare class TypedSocket {
8
19
  static createServer(typedrouterArg: plugins.typedrequest.TypedRouter, smartexpressServerArg?: any): Promise<TypedSocket>;
9
20
  static createClient(typedrouterArg: plugins.typedrequest.TypedRouter, serverUrlArg: string, aliasArg?: string): Promise<TypedSocket>;
10
21
  static useWindowLocationOriginUrl: () => string;
22
+ /**
23
+ * Creates a TypedSocket server from an existing SmartServe instance.
24
+ * Use this when you want TypedSocket to work with SmartServe's WebSocket handling.
25
+ *
26
+ * @param smartServeArg - SmartServe instance with typedRouter configured in websocket options
27
+ * @param typedRouterArg - TypedRouter for handling requests (must match SmartServe's typedRouter)
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const typedRouter = new TypedRouter();
32
+ * const smartServe = new SmartServe({
33
+ * port: 3000,
34
+ * websocket: {
35
+ * typedRouter,
36
+ * onConnectionOpen: (peer) => peer.tags.add('client')
37
+ * }
38
+ * });
39
+ * await smartServe.start();
40
+ * const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
41
+ * ```
42
+ */
43
+ static fromSmartServe(smartServeArg: plugins.SmartServe, typedRouterArg: plugins.typedrequest.TypedRouter): TypedSocket;
11
44
  side: TTypedSocketSide;
12
45
  typedrouter: plugins.typedrequest.TypedRouter;
46
+ private smartServeRef?;
47
+ private smartServeConnectionWrappers;
13
48
  get eventSubject(): plugins.smartrx.rxjs.Subject<plugins.smartsocket.TConnectionStatus>;
14
49
  private postMethod;
15
50
  private socketServerOrClient;
16
51
  constructor(sideArg: TTypedSocketSide, typedrouterArg: plugins.typedrequest.TypedRouter, postMethodArg: plugins.typedrequest.IPostMethod, socketServerOrClientArg: plugins.smartsocket.Smartsocket | plugins.smartsocket.SmartsocketClient);
17
52
  addTag<T extends plugins.typedrequestInterfaces.ITag = any>(nameArg: T['name'], payloadArg: T['payload']): void;
18
- createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(methodName: T['method'], targetConnection?: plugins.smartsocket.SocketConnection): plugins.typedrequest.TypedRequest<T>;
53
+ createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(methodName: T['method'], targetConnection?: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper): plugins.typedrequest.TypedRequest<T>;
19
54
  /**
20
- * returns all matching target connection
21
- * @param asyncFindFuncArg
22
- * @returns
55
+ * returns all matching target connections
56
+ * Works with both Smartsocket and SmartServe backends
57
+ * @param asyncFindFuncArg - async filter function
58
+ * @returns array of matching connections
23
59
  */
24
- findAllTargetConnections(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>): Promise<plugins.smartsocket.SocketConnection[]>;
60
+ findAllTargetConnections(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]>;
25
61
  /**
26
62
  * returns a single target connection by returning the first one of all matching ones
27
63
  * @param asyncFindFuncArg
28
64
  * @returns
29
65
  */
30
- findTargetConnection(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>): Promise<plugins.smartsocket.SocketConnection>;
31
- findAllTargetConnectionsByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<plugins.smartsocket.SocketConnection[]>;
32
- findTargetConnectionByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<plugins.smartsocket.SocketConnection>;
66
+ findTargetConnection(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined>;
67
+ /**
68
+ * Find all connections that have a specific tag
69
+ * Works with both Smartsocket and SmartServe backends
70
+ */
71
+ findAllTargetConnectionsByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]>;
72
+ /**
73
+ * Find a single connection by tag
74
+ */
75
+ findTargetConnectionByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined>;
76
+ /**
77
+ * Stop the TypedSocket server/client
78
+ * Note: In SmartServe mode, SmartServe manages its own lifecycle
79
+ */
33
80
  stop(): Promise<void>;
34
81
  }
@@ -1,6 +1,22 @@
1
1
  import * as plugins from './typedsocket.plugins.js';
2
2
  const publicRoleName = 'publicRoleName';
3
3
  const publicRolePass = 'publicRolePass';
4
+ /**
5
+ * Creates a wrapper around IWebSocketPeer for tag compatibility
6
+ */
7
+ function wrapSmartServePeer(peer) {
8
+ const TAG_PREFIX = '__typedsocket_tag__';
9
+ return {
10
+ peer,
11
+ async getTagById(tagId) {
12
+ if (!peer.tags.has(tagId)) {
13
+ return undefined;
14
+ }
15
+ const payload = peer.data.get(`${TAG_PREFIX}${tagId}`);
16
+ return { id: tagId, payload };
17
+ },
18
+ };
19
+ }
4
20
  export class TypedSocket {
5
21
  // STATIC
6
22
  /**
@@ -68,10 +84,75 @@ export class TypedSocket {
68
84
  const windowLocationResult = plugins.smarturl.Smarturl.createFromUrl(globalThis.location.origin).toString();
69
85
  return windowLocationResult;
70
86
  }; }
87
+ /**
88
+ * Creates a TypedSocket server from an existing SmartServe instance.
89
+ * Use this when you want TypedSocket to work with SmartServe's WebSocket handling.
90
+ *
91
+ * @param smartServeArg - SmartServe instance with typedRouter configured in websocket options
92
+ * @param typedRouterArg - TypedRouter for handling requests (must match SmartServe's typedRouter)
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const typedRouter = new TypedRouter();
97
+ * const smartServe = new SmartServe({
98
+ * port: 3000,
99
+ * websocket: {
100
+ * typedRouter,
101
+ * onConnectionOpen: (peer) => peer.tags.add('client')
102
+ * }
103
+ * });
104
+ * await smartServe.start();
105
+ * const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
106
+ * ```
107
+ */
108
+ static fromSmartServe(smartServeArg, typedRouterArg) {
109
+ const connectionWrappers = new Map();
110
+ // Create the postMethod for server-initiated requests
111
+ const postMethod = async (dataArg, targetConnectionArg) => {
112
+ if (!targetConnectionArg) {
113
+ const allConnections = smartServeArg.getWebSocketConnections();
114
+ if (allConnections.length === 1) {
115
+ console.log('Since no targetConnection was supplied and there is only one active one present, choosing that one automatically');
116
+ const peer = allConnections[0];
117
+ let wrapper = connectionWrappers.get(peer.id);
118
+ if (!wrapper) {
119
+ wrapper = wrapSmartServePeer(peer);
120
+ connectionWrappers.set(peer.id, wrapper);
121
+ }
122
+ targetConnectionArg = wrapper;
123
+ }
124
+ else if (allConnections.length === 0) {
125
+ throw new Error('No WebSocket connections available');
126
+ }
127
+ else {
128
+ throw new Error('you need to specify the wanted targetConnection. Currently no target is selectable automatically.');
129
+ }
130
+ }
131
+ // Register interest for the response using correlation ID
132
+ const interest = await typedRouterArg.fireEventInterestMap.addInterest(dataArg.correlation.id, dataArg);
133
+ // Send the request to the client
134
+ targetConnectionArg.peer.send(plugins.smartjson.stringify(dataArg));
135
+ // Wait for the response (TypedRouter will fulfill via routeAndAddResponse when response arrives)
136
+ const response = await interest.interestFullfilled;
137
+ return response;
138
+ };
139
+ const typedSocket = new TypedSocket('server', typedRouterArg, postMethod, null // No smartsocket server/client when using SmartServe
140
+ );
141
+ typedSocket.smartServeRef = smartServeArg;
142
+ typedSocket.smartServeConnectionWrappers = connectionWrappers;
143
+ return typedSocket;
144
+ }
71
145
  get eventSubject() {
146
+ if (this.smartServeRef) {
147
+ // SmartServe doesn't provide an eventSubject, return a new Subject
148
+ // In SmartServe mode, connection events are handled via onConnectionOpen/onConnectionClose hooks
149
+ console.warn('eventSubject is not fully supported in SmartServe mode. Use SmartServe hooks instead.');
150
+ return new plugins.smartrx.rxjs.Subject();
151
+ }
72
152
  return this.socketServerOrClient.eventSubject;
73
153
  }
74
154
  constructor(sideArg, typedrouterArg, postMethodArg, socketServerOrClientArg) {
155
+ this.smartServeConnectionWrappers = new Map();
75
156
  this.side = sideArg;
76
157
  this.typedrouter = typedrouterArg;
77
158
  this.postMethod = postMethodArg;
@@ -99,11 +180,28 @@ export class TypedSocket {
99
180
  return typedrequest;
100
181
  }
101
182
  /**
102
- * returns all matching target connection
103
- * @param asyncFindFuncArg
104
- * @returns
183
+ * returns all matching target connections
184
+ * Works with both Smartsocket and SmartServe backends
185
+ * @param asyncFindFuncArg - async filter function
186
+ * @returns array of matching connections
105
187
  */
106
188
  async findAllTargetConnections(asyncFindFuncArg) {
189
+ // SmartServe mode
190
+ if (this.smartServeRef) {
191
+ const matchingConnections = [];
192
+ for (const peer of this.smartServeRef.getWebSocketConnections()) {
193
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
194
+ if (!wrapper) {
195
+ wrapper = wrapSmartServePeer(peer);
196
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
197
+ }
198
+ if (await asyncFindFuncArg(wrapper)) {
199
+ matchingConnections.push(wrapper);
200
+ }
201
+ }
202
+ return matchingConnections;
203
+ }
204
+ // Smartsocket mode
107
205
  if (this.socketServerOrClient instanceof plugins.smartsocket.Smartsocket) {
108
206
  const matchingSockets = [];
109
207
  for (const socketConnection of this.socketServerOrClient.socketConnections.getArray()) {
@@ -113,9 +211,7 @@ export class TypedSocket {
113
211
  }
114
212
  return matchingSockets;
115
213
  }
116
- else {
117
- throw new Error('this method >>findTargetConnection<< is only available from the server');
118
- }
214
+ throw new Error('this method >>findTargetConnection<< is only available from the server');
119
215
  }
120
216
  /**
121
217
  * returns a single target connection by returning the first one of all matching ones
@@ -126,7 +222,33 @@ export class TypedSocket {
126
222
  const allMatching = await this.findAllTargetConnections(asyncFindFuncArg);
127
223
  return allMatching[0];
128
224
  }
225
+ /**
226
+ * Find all connections that have a specific tag
227
+ * Works with both Smartsocket and SmartServe backends
228
+ */
129
229
  async findAllTargetConnectionsByTag(keyArg, payloadArg) {
230
+ // SmartServe mode - use native filtering for better performance
231
+ if (this.smartServeRef) {
232
+ const peers = this.smartServeRef.getWebSocketConnectionsByTag(keyArg);
233
+ const results = [];
234
+ for (const peer of peers) {
235
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
236
+ if (!wrapper) {
237
+ wrapper = wrapSmartServePeer(peer);
238
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
239
+ }
240
+ // If payload specified, also filter by payload stored in peer.data
241
+ if (payloadArg !== undefined) {
242
+ const tag = await wrapper.getTagById(keyArg);
243
+ if (plugins.smartjson.stringify(tag?.payload) !== plugins.smartjson.stringify(payloadArg)) {
244
+ continue;
245
+ }
246
+ }
247
+ results.push(wrapper);
248
+ }
249
+ return results;
250
+ }
251
+ // Smartsocket mode - use existing logic
130
252
  return this.findAllTargetConnections(async (socketConnectionArg) => {
131
253
  let result;
132
254
  if (!payloadArg) {
@@ -139,12 +261,25 @@ export class TypedSocket {
139
261
  return result;
140
262
  });
141
263
  }
264
+ /**
265
+ * Find a single connection by tag
266
+ */
142
267
  async findTargetConnectionByTag(keyArg, payloadArg) {
143
268
  const allResults = await this.findAllTargetConnectionsByTag(keyArg, payloadArg);
144
269
  return allResults[0];
145
270
  }
271
+ /**
272
+ * Stop the TypedSocket server/client
273
+ * Note: In SmartServe mode, SmartServe manages its own lifecycle
274
+ */
146
275
  async stop() {
276
+ if (this.smartServeRef) {
277
+ // SmartServe manages its own lifecycle
278
+ // Clear our connection wrappers
279
+ this.smartServeConnectionWrappers.clear();
280
+ return;
281
+ }
147
282
  await this.socketServerOrClient.stop();
148
283
  }
149
284
  }
150
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZWRzb2NrZXQuY2xhc3Nlcy50eXBlZHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4u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FBQztRQUNoRixPQUFPLFVBQVUsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN2QixDQUFDO0lBRUQ7OztPQUdHO0lBQ0ksS0FBSyxDQUFDLElBQUk7UUFDZixJQUFJLElBQUksQ0FBQyxhQUFhLEVBQUUsQ0FBQztZQUN2Qix1Q0FBdUM7WUFDdkMsZ0NBQWdDO1lBQ2hDLElBQUksQ0FBQyw0QkFBNEIsQ0FBQyxLQUFLLEVBQUUsQ0FBQztZQUMxQyxPQUFPO1FBQ1QsQ0FBQztRQUNELE1BQU0sSUFBSSxDQUFDLG9CQUFvQixDQUFDLElBQUksRUFBRSxDQUFDO0lBQ3pDLENBQUMifQ==
@@ -8,3 +8,4 @@ import * as smartsocket from '@push.rocks/smartsocket';
8
8
  import * as smartstring from '@push.rocks/smartstring';
9
9
  import * as smarturl from '@push.rocks/smarturl';
10
10
  export { isohash, smartjson, smartrx, smartsocket, smartstring, smarturl };
11
+ export type { SmartServe, IWebSocketPeer } from '@push.rocks/smartserve';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@api.global/typedsocket",
3
- "version": "3.0.1",
3
+ "version": "3.1.1",
4
4
  "private": false,
5
5
  "description": "A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.",
6
6
  "main": "dist_ts/index.js",
@@ -9,23 +9,32 @@
9
9
  "author": "Lossless GmbH",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
- "@git.zone/tsbuild": "^2.1.66",
13
- "@git.zone/tsbundle": "^2.0.8",
14
- "@git.zone/tsrun": "^1.2.44",
15
- "@git.zone/tstest": "^1.0.77",
16
- "@push.rocks/smartenv": "^5.0.12",
17
- "@push.rocks/tapbundle": "^5.0.23",
18
- "@types/node": "^20.12.7"
12
+ "@git.zone/tsbuild": "^3.1.2",
13
+ "@git.zone/tsbundle": "^2.6.2",
14
+ "@git.zone/tsrun": "^2.0.0",
15
+ "@git.zone/tstest": "^3.1.3",
16
+ "@push.rocks/smartenv": "^6.0.0",
17
+ "@push.rocks/smartserve": "^1.1.0",
18
+ "@push.rocks/tapbundle": "^6.0.3",
19
+ "@types/node": "^24.10.1"
19
20
  },
20
21
  "dependencies": {
21
- "@api.global/typedrequest": "^3.0.21",
22
- "@api.global/typedrequest-interfaces": "^3.0.18",
23
- "@push.rocks/isohash": "^2.0.0",
24
- "@push.rocks/smartjson": "^5.0.19",
25
- "@push.rocks/smartrx": "^3.0.7",
26
- "@push.rocks/smartsocket": "^2.0.25",
27
- "@push.rocks/smartstring": "^4.0.15",
28
- "@push.rocks/smarturl": "^3.0.5"
22
+ "@api.global/typedrequest": "^3.1.10",
23
+ "@api.global/typedrequest-interfaces": "^3.0.19",
24
+ "@push.rocks/isohash": "^2.0.1",
25
+ "@push.rocks/smartjson": "^5.2.0",
26
+ "@push.rocks/smartrx": "^3.0.10",
27
+ "@push.rocks/smartsocket": "^2.1.0",
28
+ "@push.rocks/smartstring": "^4.1.0",
29
+ "@push.rocks/smarturl": "^3.1.0"
30
+ },
31
+ "peerDependencies": {
32
+ "@push.rocks/smartserve": ">=1.0.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@push.rocks/smartserve": {
36
+ "optional": true
37
+ }
29
38
  },
30
39
  "browserslist": [
31
40
  "last 1 chrome versions"
package/readme.hints.md CHANGED
@@ -1 +1,21 @@
1
-
1
+ # TypedSocket Hints
2
+
3
+ ## SmartServe Integration (Added v3.1.0)
4
+
5
+ TypedSocket now supports SmartServe as an alternative WebSocket backend via `TypedSocket.fromSmartServe()`.
6
+
7
+ ### Key Differences from Smartsocket Mode
8
+
9
+ 1. **Tag System**: SmartServe uses `Set<string>` for tags, while Smartsocket uses `{id, payload}`. The wrapper stores payloads in `peer.data` with `__typedsocket_tag__` prefix.
10
+
11
+ 2. **Request/Response**: Uses TypedRouter's `fireEventInterestMap` for async correlation when sending server-initiated requests.
12
+
13
+ 3. **Lifecycle**: SmartServe manages WebSocket lifecycle. `typedSocket.stop()` only clears internal state.
14
+
15
+ 4. **eventSubject**: Not fully supported in SmartServe mode - use SmartServe's `onConnectionOpen`/`onConnectionClose` hooks instead.
16
+
17
+ ### Files Modified for SmartServe Support
18
+
19
+ - `ts/typedsocket.classes.typedsocket.ts` - Main implementation
20
+ - `ts/typedsocket.plugins.ts` - Type imports
21
+ - `package.json` - Optional peer dependency
package/readme.md CHANGED
@@ -1,159 +1,312 @@
1
1
  # @api.global/typedsocket
2
- a typedrequest extension supporting websockets
2
+
3
+ A TypeScript library for creating typed WebSocket connections with bi-directional communication support. Extends `@api.global/typedrequest` to bring type-safe request/response patterns to WebSocket connections.
4
+
5
+ ## Issue Reporting and Security
6
+
7
+ For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
8
+
9
+ ## Features
10
+
11
+ - 🔒 **Full Type Safety** - Leverages TypeScript for compile-time checking of all request/response payloads
12
+ - 🔄 **Bi-directional Communication** - Both server and client can initiate requests
13
+ - 🔌 **Auto-reconnect** - Client automatically reconnects on connection loss
14
+ - 🏷️ **Connection Tagging** - Tag and filter connections for targeted messaging
15
+ - 🌐 **Browser Compatible** - Works in both Node.js and browser environments
16
+ - 🔗 **SmartExpress Integration** - Optional integration with existing SmartExpress servers
17
+ - 🚀 **SmartServe Integration** - Native support for SmartServe's WebSocket handling
3
18
 
4
19
  ## Install
5
- To install `@api.global/typedsocket` in your project, run the following command using npm:
6
20
 
7
21
  ```bash
8
- npm install @api.global/typedsocket --save
22
+ npm install @api.global/typedsocket
9
23
  ```
10
24
 
11
- For Yarn users:
25
+ Or with pnpm:
12
26
 
13
27
  ```bash
14
- yarn add @api.global/typedsocket
28
+ pnpm add @api.global/typedsocket
15
29
  ```
16
30
 
17
31
  ## Usage
18
32
 
19
- To utilize `@api.global/typedsocket` effectively, let's explore how to integrate it into a project with TypeScript. This guide provides comprehensive usage scenarios, highlighting all features of the module. `@api.global/typedsocket` extends the capabilities of `typedrequest` by integrating websocket support, allowing for real-time, bidirectional communication between a client and server.
20
-
21
- ### Getting Started
33
+ ### Prerequisites
22
34
 
23
- #### Prerequisites
35
+ - TypeScript project setup
36
+ - Basic understanding of async/await patterns
37
+ - Familiarity with `@api.global/typedrequest` concepts
24
38
 
25
- Before diving into examples, ensure you have the following:
39
+ ### Define Your Request Interface
26
40
 
27
- - A basic understanding of TypeScript and Node.js.
28
- - An existing project set up with TypeScript.
29
- - `@api.global/typedrequest` and its dependencies installed in your project.
41
+ First, define the typed request interface that both client and server will use:
30
42
 
31
- #### Initialization
43
+ ```typescript
44
+ import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
32
45
 
33
- First, let's import the required modules and initialize our server and client instances.
46
+ interface IGreetingRequest extends typedrequestInterfaces.implementsTR<
47
+ typedrequestInterfaces.ITypedRequest,
48
+ IGreetingRequest
49
+ > {
50
+ method: 'greet';
51
+ request: {
52
+ name: string;
53
+ };
54
+ response: {
55
+ message: string;
56
+ };
57
+ }
58
+ ```
34
59
 
35
- **Server Side:**
60
+ ### Server Setup
36
61
 
37
- Within your server-side code, import and set up `TypedSocket` to create a websocket server.
62
+ Create a WebSocket server that handles typed requests:
38
63
 
39
64
  ```typescript
40
65
  import { TypedSocket } from '@api.global/typedsocket';
41
66
  import * as typedrequest from '@api.global/typedrequest';
42
67
 
43
- // Initialize your TypedRouter
68
+ // Create the router and add handlers
44
69
  const typedRouter = new typedrequest.TypedRouter();
45
70
 
46
- // Create the TypedSocket server
47
- const server = await TypedSocket.createServer(typedRouter);
71
+ typedRouter.addTypedHandler<IGreetingRequest>(
72
+ new typedrequest.TypedHandler('greet', async (requestData) => {
73
+ return {
74
+ message: `Hello, ${requestData.name}! 👋`,
75
+ };
76
+ })
77
+ );
48
78
 
49
- // Optionally, you can provide a smartexpressServerArg if you have an existing SmartExpress server
79
+ // Start the TypedSocket server (defaults to port 3000)
80
+ const server = await TypedSocket.createServer(typedRouter);
50
81
  ```
51
82
 
52
- **Client Side:**
83
+ #### Integration with SmartExpress
53
84
 
54
- On the client side, initialize `TypedSocket` to connect to the websocket server.
85
+ If you have an existing SmartExpress server, you can attach TypedSocket to it:
55
86
 
56
87
  ```typescript
57
88
  import { TypedSocket } from '@api.global/typedsocket';
89
+ import * as smartexpress from '@push.rocks/smartexpress';
58
90
 
59
- // Assuming server is at http://localhost:3000
60
- const client = await TypedSocket.createClient(typedRouter, 'http://localhost:3000');
91
+ const smartExpressServer = new smartexpress.Server({ port: 8080 });
92
+ await smartExpressServer.start();
93
+
94
+ const server = await TypedSocket.createServer(typedRouter, smartExpressServer);
61
95
  ```
62
96
 
63
- ### Defining Typed Requests
97
+ #### Integration with SmartServe
64
98
 
65
- `@api.global/typedsocket` leverages `typedrequest` for type-safe requests and responses. Here's how you can define and handle typed requests:
99
+ For SmartServe-based applications, use `fromSmartServe()` for native integration:
66
100
 
67
- **Defining a Typed Request Interface:**
101
+ ```typescript
102
+ import { TypedSocket } from '@api.global/typedsocket';
103
+ import { SmartServe } from '@push.rocks/smartserve';
104
+ import * as typedrequest from '@api.global/typedrequest';
68
105
 
69
- Define an interface for the request and its corresponding response.
106
+ const typedRouter = new typedrequest.TypedRouter();
70
107
 
71
- ```typescript
72
- interface ExampleRequest extends typedrequestInterfaces.ITypedRequest {
73
- method: 'exampleMethod';
74
- request: {
75
- message: string;
76
- };
77
- response: {
78
- reply: string;
79
- };
108
+ // Add handlers for client-to-server requests
109
+ typedRouter.addTypedHandler<IGreetingRequest>(
110
+ new typedrequest.TypedHandler('greet', async (requestData) => {
111
+ return { message: `Hello, ${requestData.name}!` };
112
+ })
113
+ );
114
+
115
+ // Create SmartServe with typedRouter in websocket options
116
+ const smartServe = new SmartServe({
117
+ port: 3000,
118
+ websocket: {
119
+ typedRouter,
120
+ onConnectionOpen: (peer) => {
121
+ // Tag connections for later filtering
122
+ peer.tags.add('client');
123
+ }
124
+ }
125
+ });
126
+
127
+ await smartServe.start();
128
+
129
+ // Create TypedSocket bound to SmartServe
130
+ const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
131
+
132
+ // Push notifications to tagged clients
133
+ const clients = await typedSocket.findAllTargetConnectionsByTag('client');
134
+ for (const client of clients) {
135
+ const request = typedSocket.createTypedRequest<INotifyRequest>('notify', client);
136
+ await request.fire({ message: 'Hello from server!' });
80
137
  }
81
138
  ```
82
139
 
83
- **Handling Requests on the Server:**
140
+ > **Note:** When using SmartServe, the WebSocket transport is managed by SmartServe. TypedSocket acts as a convenience layer for finding connections and sending server-initiated requests.
84
141
 
85
- Add a typed handler for the request in your `TypedRouter`.
142
+ ### Client Setup
143
+
144
+ Connect to the WebSocket server from a client:
86
145
 
87
146
  ```typescript
88
- typedRouter.addTypedHandler<ExampleRequest>(
89
- new typedrequest.TypedHandler('exampleMethod', async (requestData) => {
90
- return {
91
- reply: `Server received: ${requestData.message}`,
92
- };
93
- })
147
+ import { TypedSocket } from '@api.global/typedsocket';
148
+ import * as typedrequest from '@api.global/typedrequest';
149
+
150
+ // Create a router for handling server-initiated requests (if needed)
151
+ const clientRouter = new typedrequest.TypedRouter();
152
+
153
+ // Connect to the server
154
+ const client = await TypedSocket.createClient(
155
+ clientRouter,
156
+ 'http://localhost:3000'
94
157
  );
95
158
  ```
96
159
 
97
- ### Sending Requests from the Client
160
+ #### Using Window Location (Browser)
98
161
 
99
- Use the client instance to send a request to the server and await a response.
162
+ In browser environments, you can automatically use the current page's origin:
100
163
 
101
164
  ```typescript
102
- const exampleRequest = client.createTypedRequest<ExampleRequest>('exampleMethod');
103
- const response = await exampleRequest.fire({
104
- message: 'Hello from client!',
165
+ const client = await TypedSocket.createClient(
166
+ clientRouter,
167
+ TypedSocket.useWindowLocationOriginUrl()
168
+ );
169
+ ```
170
+
171
+ ### Sending Requests
172
+
173
+ #### Client to Server
174
+
175
+ ```typescript
176
+ const request = client.createTypedRequest<IGreetingRequest>('greet');
177
+ const response = await request.fire({
178
+ name: 'World',
105
179
  });
106
180
 
107
- console.log(response.reply); // "Server received: Hello from client!"
181
+ console.log(response.message); // "Hello, World! 👋"
108
182
  ```
109
183
 
110
- ### Advanced Usage
184
+ #### Server to Client
111
185
 
112
- #### Tagging Connections
186
+ The server can also initiate requests to connected clients:
113
187
 
114
- For more refined control, especially in scenarios with multiple clients, you can tag connections for targeted communication.
188
+ ```typescript
189
+ // When only one client is connected, it's automatically selected
190
+ const request = server.createTypedRequest<IGreetingRequest>('greet');
191
+ const response = await request.fire({
192
+ name: 'Client',
193
+ });
194
+
195
+ // For multiple clients, specify the target connection
196
+ const connection = await server.findTargetConnection(async (conn) => {
197
+ // Your filter logic here
198
+ return true;
199
+ });
200
+ const targetedRequest = server.createTypedRequest<IGreetingRequest>('greet', connection);
201
+ ```
202
+
203
+ ### Connection Tagging
204
+
205
+ Tag connections for organized, targeted communication:
206
+
207
+ ```typescript
208
+ // Client side: add a tag
209
+ interface IUserTag extends typedrequestInterfaces.ITag {
210
+ name: 'userRole';
211
+ payload: 'admin' | 'user' | 'guest';
212
+ }
213
+
214
+ client.addTag<IUserTag>('userRole', 'admin');
215
+ ```
115
216
 
116
217
  ```typescript
117
- // Add a tag to a client
118
- client.addTag('role', 'admin');
119
-
120
- // On the server, find connections with the tag
121
- const adminConnections = await server.findAllTargetConnectionsByTag('role', 'admin');
122
-
123
- // Send a message to all admin connections
124
- for (const adminConnection of adminConnections) {
125
- const request = server.createTypedRequest<ExampleRequest>('exampleMethod', adminConnection);
126
- await request.fire({
127
- message: 'Message to admins',
128
- });
218
+ // Server side: find connections by tag
219
+ const adminConnections = await server.findAllTargetConnectionsByTag<IUserTag>(
220
+ 'userRole',
221
+ 'admin'
222
+ );
223
+
224
+ // Send to all admins
225
+ for (const conn of adminConnections) {
226
+ const request = server.createTypedRequest<INotificationRequest>('notify', conn);
227
+ await request.fire({ message: 'Admin notification' });
129
228
  }
229
+
230
+ // Find a single connection
231
+ const firstAdmin = await server.findTargetConnectionByTag<IUserTag>('userRole', 'admin');
130
232
  ```
131
233
 
132
- #### Handling Reconnections
234
+ ### Event Handling
133
235
 
134
- `TypedSocket` automatically attempts to reconnect in the event of connection loss. Ensure your server and client logic accounts for reconnection, especially for maintaining state or re-subscribing to necessary events.
236
+ Subscribe to connection status events:
135
237
 
136
- ### Conclusion
238
+ ```typescript
239
+ client.eventSubject.subscribe((status) => {
240
+ console.log('Connection status:', status);
241
+ });
137
242
 
138
- Implementing `@api.global/typedsocket` provides a type-safe, real-time communication layer for your TypeScript applications, extending the functionality of `typedrequest` into the realm of websockets. This guide covered initialization, defining typed requests, sending requests, and advanced usage patterns like tagging connections and handling reconnections.
243
+ server.eventSubject.subscribe((status) => {
244
+ console.log('Server connection event:', status);
245
+ });
246
+ ```
247
+
248
+ ### Cleanup
139
249
 
140
- Integrating `@api.global/typedsocket` into your project harnesses the power of websockets with the benefits of type safety and structured request/response patterns, enabling more reliable and maintainable real-time applications.
250
+ Properly close connections when done:
251
+
252
+ ```typescript
253
+ // Client
254
+ await client.stop();
255
+
256
+ // Server
257
+ await server.stop();
258
+ ```
259
+
260
+ ## API Reference
261
+
262
+ ### TypedSocket
263
+
264
+ #### Static Methods
265
+
266
+ | Method | Description |
267
+ |--------|-------------|
268
+ | `createServer(router, smartExpressServer?)` | Creates a WebSocket server. Optionally attach to an existing SmartExpress server. |
269
+ | `createClient(router, serverUrl, alias?)` | Creates a WebSocket client that connects to the specified server URL. |
270
+ | `fromSmartServe(smartServe, router)` | Creates a TypedSocket bound to an existing SmartServe instance. |
271
+ | `useWindowLocationOriginUrl()` | Returns the current window location origin (browser only). |
272
+
273
+ #### Instance Properties
274
+
275
+ | Property | Description |
276
+ |----------|-------------|
277
+ | `side` | Whether this instance is a `'server'` or `'client'`. |
278
+ | `typedrouter` | The TypedRouter instance handling requests. |
279
+ | `eventSubject` | RxJS Subject for connection status events. |
280
+
281
+ #### Instance Methods
282
+
283
+ | Method | Description |
284
+ |--------|-------------|
285
+ | `createTypedRequest(method, targetConnection?)` | Creates a typed request for the specified method. |
286
+ | `addTag(name, payload)` | Adds a tag to the client connection (client-side only). |
287
+ | `findAllTargetConnections(filterFn)` | Finds all connections matching the filter (server-side only). |
288
+ | `findTargetConnection(filterFn)` | Finds the first connection matching the filter (server-side only). |
289
+ | `findAllTargetConnectionsByTag(key, payload?)` | Finds all connections with the specified tag. |
290
+ | `findTargetConnectionByTag(key, payload?)` | Finds the first connection with the specified tag. |
291
+ | `stop()` | Closes the WebSocket connection. |
141
292
 
142
293
  ## License and Legal Information
143
294
 
144
- This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
295
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
145
296
 
146
297
  **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
147
298
 
148
299
  ### Trademarks
149
300
 
150
- This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
301
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
302
+
303
+ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
151
304
 
152
305
  ### Company Information
153
306
 
154
- Task Venture Capital GmbH
155
- Registered at District court Bremen HRB 35230 HB, Germany
307
+ Task Venture Capital GmbH
308
+ Registered at District Court Bremen HRB 35230 HB, Germany
156
309
 
157
- For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
310
+ For any legal inquiries or further information, please contact us via email at hello@task.vc.
158
311
 
159
312
  By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -1,8 +1,8 @@
1
1
  /**
2
- * autocreated commitinfo by @pushrocks/commitinfo
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@api.global/typedsocket',
6
- version: '3.0.1',
6
+ version: '3.1.1',
7
7
  description: 'A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.'
8
8
  }
@@ -5,6 +5,32 @@ const publicRolePass = 'publicRolePass';
5
5
 
6
6
  export type TTypedSocketSide = 'server' | 'client';
7
7
 
8
+ /**
9
+ * Wrapper for SmartServe's IWebSocketPeer to provide tag compatibility
10
+ * SmartServe uses Set<string> for tags, while TypedSocket uses {id, payload} format
11
+ */
12
+ export interface ISmartServeConnectionWrapper {
13
+ peer: plugins.IWebSocketPeer;
14
+ getTagById(tagId: string): Promise<{ id: string; payload: any } | undefined>;
15
+ }
16
+
17
+ /**
18
+ * Creates a wrapper around IWebSocketPeer for tag compatibility
19
+ */
20
+ function wrapSmartServePeer(peer: plugins.IWebSocketPeer): ISmartServeConnectionWrapper {
21
+ const TAG_PREFIX = '__typedsocket_tag__';
22
+ return {
23
+ peer,
24
+ async getTagById(tagId: string): Promise<{ id: string; payload: any } | undefined> {
25
+ if (!peer.tags.has(tagId)) {
26
+ return undefined;
27
+ }
28
+ const payload = peer.data.get(`${TAG_PREFIX}${tagId}`);
29
+ return { id: tagId, payload };
30
+ },
31
+ };
32
+ }
33
+
8
34
  export class TypedSocket {
9
35
  // STATIC
10
36
  /**
@@ -110,16 +136,108 @@ export class TypedSocket {
110
136
  return windowLocationResult;
111
137
  }
112
138
 
139
+ /**
140
+ * Creates a TypedSocket server from an existing SmartServe instance.
141
+ * Use this when you want TypedSocket to work with SmartServe's WebSocket handling.
142
+ *
143
+ * @param smartServeArg - SmartServe instance with typedRouter configured in websocket options
144
+ * @param typedRouterArg - TypedRouter for handling requests (must match SmartServe's typedRouter)
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const typedRouter = new TypedRouter();
149
+ * const smartServe = new SmartServe({
150
+ * port: 3000,
151
+ * websocket: {
152
+ * typedRouter,
153
+ * onConnectionOpen: (peer) => peer.tags.add('client')
154
+ * }
155
+ * });
156
+ * await smartServe.start();
157
+ * const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
158
+ * ```
159
+ */
160
+ public static fromSmartServe(
161
+ smartServeArg: plugins.SmartServe,
162
+ typedRouterArg: plugins.typedrequest.TypedRouter
163
+ ): TypedSocket {
164
+ const connectionWrappers = new Map<string, ISmartServeConnectionWrapper>();
165
+
166
+ // Create the postMethod for server-initiated requests
167
+ const postMethod = async <T extends plugins.typedrequestInterfaces.ITypedRequest>(
168
+ dataArg: T,
169
+ targetConnectionArg?: ISmartServeConnectionWrapper
170
+ ): Promise<T> => {
171
+ if (!targetConnectionArg) {
172
+ const allConnections = smartServeArg.getWebSocketConnections();
173
+ if (allConnections.length === 1) {
174
+ console.log(
175
+ 'Since no targetConnection was supplied and there is only one active one present, choosing that one automatically'
176
+ );
177
+ const peer = allConnections[0];
178
+ let wrapper = connectionWrappers.get(peer.id);
179
+ if (!wrapper) {
180
+ wrapper = wrapSmartServePeer(peer);
181
+ connectionWrappers.set(peer.id, wrapper);
182
+ }
183
+ targetConnectionArg = wrapper;
184
+ } else if (allConnections.length === 0) {
185
+ throw new Error('No WebSocket connections available');
186
+ } else {
187
+ throw new Error(
188
+ 'you need to specify the wanted targetConnection. Currently no target is selectable automatically.'
189
+ );
190
+ }
191
+ }
192
+
193
+ // Register interest for the response using correlation ID
194
+ const interest = await typedRouterArg.fireEventInterestMap.addInterest(
195
+ dataArg.correlation.id,
196
+ dataArg
197
+ );
198
+
199
+ // Send the request to the client
200
+ targetConnectionArg.peer.send(plugins.smartjson.stringify(dataArg));
201
+
202
+ // Wait for the response (TypedRouter will fulfill via routeAndAddResponse when response arrives)
203
+ const response = await interest.interestFullfilled as T;
204
+ return response;
205
+ };
206
+
207
+ const typedSocket = new TypedSocket(
208
+ 'server',
209
+ typedRouterArg,
210
+ postMethod as any,
211
+ null as any // No smartsocket server/client when using SmartServe
212
+ );
213
+
214
+ typedSocket.smartServeRef = smartServeArg;
215
+ typedSocket.smartServeConnectionWrappers = connectionWrappers;
216
+
217
+ return typedSocket;
218
+ }
219
+
113
220
  // INSTANCE
114
221
  public side: TTypedSocketSide;
115
222
  public typedrouter: plugins.typedrequest.TypedRouter;
223
+
224
+ // SmartServe mode properties
225
+ private smartServeRef?: plugins.SmartServe;
226
+ private smartServeConnectionWrappers: Map<string, ISmartServeConnectionWrapper> = new Map();
227
+
116
228
  public get eventSubject(): plugins.smartrx.rxjs.Subject<plugins.smartsocket.TConnectionStatus> {
229
+ if (this.smartServeRef) {
230
+ // SmartServe doesn't provide an eventSubject, return a new Subject
231
+ // In SmartServe mode, connection events are handled via onConnectionOpen/onConnectionClose hooks
232
+ console.warn('eventSubject is not fully supported in SmartServe mode. Use SmartServe hooks instead.');
233
+ return new plugins.smartrx.rxjs.Subject();
234
+ }
117
235
  return this.socketServerOrClient.eventSubject;
118
236
  }
119
237
  private postMethod: plugins.typedrequest.IPostMethod &
120
238
  ((
121
239
  typedRequestPostObject: plugins.typedrequestInterfaces.ITypedRequest,
122
- socketConnectionArg?: plugins.smartsocket.SocketConnection
240
+ socketConnectionArg?: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper
123
241
  ) => Promise<plugins.typedrequestInterfaces.ITypedRequest>);
124
242
  private socketServerOrClient:
125
243
  | plugins.smartsocket.Smartsocket
@@ -155,12 +273,12 @@ export class TypedSocket {
155
273
 
156
274
  public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
157
275
  methodName: T['method'],
158
- targetConnection?: plugins.smartsocket.SocketConnection
276
+ targetConnection?: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper
159
277
  ): plugins.typedrequest.TypedRequest<T> {
160
278
  const typedrequest = new plugins.typedrequest.TypedRequest<T>(
161
279
  new plugins.typedrequest.TypedTarget({
162
280
  postMethod: async (requestDataArg) => {
163
- const result = await this.postMethod(requestDataArg, targetConnection);
281
+ const result = await this.postMethod(requestDataArg, targetConnection as any);
164
282
  return result;
165
283
  },
166
284
  }),
@@ -170,13 +288,31 @@ export class TypedSocket {
170
288
  }
171
289
 
172
290
  /**
173
- * returns all matching target connection
174
- * @param asyncFindFuncArg
175
- * @returns
291
+ * returns all matching target connections
292
+ * Works with both Smartsocket and SmartServe backends
293
+ * @param asyncFindFuncArg - async filter function
294
+ * @returns array of matching connections
176
295
  */
177
296
  public async findAllTargetConnections(
178
- asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
179
- ) {
297
+ asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>
298
+ ): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]> {
299
+ // SmartServe mode
300
+ if (this.smartServeRef) {
301
+ const matchingConnections: ISmartServeConnectionWrapper[] = [];
302
+ for (const peer of this.smartServeRef.getWebSocketConnections()) {
303
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
304
+ if (!wrapper) {
305
+ wrapper = wrapSmartServePeer(peer);
306
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
307
+ }
308
+ if (await asyncFindFuncArg(wrapper)) {
309
+ matchingConnections.push(wrapper);
310
+ }
311
+ }
312
+ return matchingConnections;
313
+ }
314
+
315
+ // Smartsocket mode
180
316
  if (this.socketServerOrClient instanceof plugins.smartsocket.Smartsocket) {
181
317
  const matchingSockets: plugins.smartsocket.SocketConnection[] = [];
182
318
  for (const socketConnection of this.socketServerOrClient.socketConnections.getArray()) {
@@ -185,9 +321,9 @@ export class TypedSocket {
185
321
  }
186
322
  }
187
323
  return matchingSockets;
188
- } else {
189
- throw new Error('this method >>findTargetConnection<< is only available from the server');
190
324
  }
325
+
326
+ throw new Error('this method >>findTargetConnection<< is only available from the server');
191
327
  }
192
328
 
193
329
  /**
@@ -196,22 +332,51 @@ export class TypedSocket {
196
332
  * @returns
197
333
  */
198
334
  public async findTargetConnection(
199
- asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
200
- ) {
335
+ asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>
336
+ ): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined> {
201
337
  const allMatching = await this.findAllTargetConnections(asyncFindFuncArg);
202
338
  return allMatching[0];
203
339
  }
204
340
 
341
+ /**
342
+ * Find all connections that have a specific tag
343
+ * Works with both Smartsocket and SmartServe backends
344
+ */
205
345
  public async findAllTargetConnectionsByTag<
206
346
  TTag extends plugins.typedrequestInterfaces.ITag = any
207
- >(keyArg: TTag['name'], payloadArg?: TTag['payload']) {
347
+ >(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]> {
348
+ // SmartServe mode - use native filtering for better performance
349
+ if (this.smartServeRef) {
350
+ const peers = this.smartServeRef.getWebSocketConnectionsByTag(keyArg);
351
+ const results: ISmartServeConnectionWrapper[] = [];
352
+
353
+ for (const peer of peers) {
354
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
355
+ if (!wrapper) {
356
+ wrapper = wrapSmartServePeer(peer);
357
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
358
+ }
359
+
360
+ // If payload specified, also filter by payload stored in peer.data
361
+ if (payloadArg !== undefined) {
362
+ const tag = await wrapper.getTagById(keyArg);
363
+ if (plugins.smartjson.stringify(tag?.payload) !== plugins.smartjson.stringify(payloadArg)) {
364
+ continue;
365
+ }
366
+ }
367
+ results.push(wrapper);
368
+ }
369
+ return results;
370
+ }
371
+
372
+ // Smartsocket mode - use existing logic
208
373
  return this.findAllTargetConnections(async (socketConnectionArg) => {
209
374
  let result: boolean;
210
375
  if (!payloadArg) {
211
- result = !!(await socketConnectionArg.getTagById(keyArg));
376
+ result = !!(await (socketConnectionArg as plugins.smartsocket.SocketConnection).getTagById(keyArg));
212
377
  } else {
213
378
  result = !!(
214
- plugins.smartjson.stringify((await socketConnectionArg.getTagById(keyArg))?.payload) ===
379
+ plugins.smartjson.stringify((await (socketConnectionArg as plugins.smartsocket.SocketConnection).getTagById(keyArg))?.payload) ===
215
380
  plugins.smartjson.stringify(payloadArg)
216
381
  );
217
382
  }
@@ -219,15 +384,28 @@ export class TypedSocket {
219
384
  });
220
385
  }
221
386
 
387
+ /**
388
+ * Find a single connection by tag
389
+ */
222
390
  public async findTargetConnectionByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(
223
391
  keyArg: TTag['name'],
224
392
  payloadArg?: TTag['payload']
225
- ) {
393
+ ): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined> {
226
394
  const allResults = await this.findAllTargetConnectionsByTag(keyArg, payloadArg);
227
395
  return allResults[0];
228
396
  }
229
397
 
398
+ /**
399
+ * Stop the TypedSocket server/client
400
+ * Note: In SmartServe mode, SmartServe manages its own lifecycle
401
+ */
230
402
  public async stop() {
403
+ if (this.smartServeRef) {
404
+ // SmartServe manages its own lifecycle
405
+ // Clear our connection wrappers
406
+ this.smartServeConnectionWrappers.clear();
407
+ return;
408
+ }
231
409
  await this.socketServerOrClient.stop();
232
410
  }
233
411
  }
@@ -13,3 +13,6 @@ import * as smartstring from '@push.rocks/smartstring';
13
13
  import * as smarturl from '@push.rocks/smarturl';
14
14
 
15
15
  export { isohash, smartjson, smartrx, smartsocket, smartstring, smarturl };
16
+
17
+ // Optional SmartServe support (type-only imports for optional peer dependency)
18
+ export type { SmartServe, IWebSocketPeer } from '@push.rocks/smartserve';