@socket-mesh/core 2.0.0 → 2.1.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.
@@ -37,13 +37,13 @@ export declare class BaseSocketTransport<TState extends object = {}> {
37
37
  private _authToken;
38
38
  private readonly _callbackMap;
39
39
  private readonly _callIdGenerator;
40
- private readonly _handlers;
41
40
  private _inboundProcessedMessageCount;
42
41
  private _inboundReceivedMessageCount;
43
42
  private _isReady;
44
43
  private _outboundPreparedMessageCount;
45
44
  private _outboundSentMessageCount;
46
45
  private _pingTimeoutRef;
46
+ private readonly _serviceHandlers;
47
47
  private _signedAuthToken;
48
48
  private _socket;
49
49
  private _webSocket;
@@ -11,13 +11,13 @@ export class BaseSocketTransport {
11
11
  _authToken;
12
12
  _callbackMap;
13
13
  _callIdGenerator;
14
- _handlers;
15
14
  _inboundProcessedMessageCount;
16
15
  _inboundReceivedMessageCount;
17
16
  _isReady;
18
17
  _outboundPreparedMessageCount;
19
18
  _outboundSentMessageCount;
20
19
  _pingTimeoutRef;
20
+ _serviceHandlers;
21
21
  _signedAuthToken;
22
22
  _socket;
23
23
  _webSocket;
@@ -38,13 +38,24 @@ export class BaseSocketTransport {
38
38
  });
39
39
  this._callbackMap = {};
40
40
  this.codecEngine = options?.codecEngine || defaultCodec;
41
- this._handlers = options?.handlers || {};
42
41
  this.id = null;
43
42
  this._inboundProcessedMessageCount = 0;
44
43
  this._inboundReceivedMessageCount = 0;
45
44
  this._outboundPreparedMessageCount = 0;
46
45
  this._outboundSentMessageCount = 0;
47
46
  this._pingTimeoutRef = null;
47
+ this._serviceHandlers = options?.serviceHandlers || {};
48
+ // Flat (non-service) handlers live under the empty-string service key
49
+ // so dispatch only has to consult one map. We merge `options.handlers`
50
+ // into that slot without cloning the top-level map, so dynamic mutations
51
+ // to the caller's serviceHandlers reference (e.g. Server.addHandlers)
52
+ // still propagate to this transport.
53
+ if (options?.handlers) {
54
+ this._serviceHandlers[''] = {
55
+ ...this._serviceHandlers[''],
56
+ ...options.handlers
57
+ };
58
+ }
48
59
  this.plugins = options?.plugins || [];
49
60
  this.streamCleanupMode = options?.streamCleanupMode || 'kill';
50
61
  }
@@ -325,7 +336,8 @@ export class BaseSocketTransport {
325
336
  }
326
337
  }
327
338
  else {
328
- const handler = this._handlers[packet.method];
339
+ const service = 'service' in packet ? packet.service : '';
340
+ const handler = this._serviceHandlers[service]?.[packet.method];
329
341
  if (handler) {
330
342
  wasHandled = true;
331
343
  try {
package/dist/socket.d.ts CHANGED
@@ -14,6 +14,9 @@ export interface BaseSocketOptions<TState extends object = {}> {
14
14
  handlers?: LooseHandlerMap;
15
15
  isPingTimeoutDisabled?: boolean;
16
16
  plugins?: AnyPlugin[];
17
+ serviceHandlers?: {
18
+ [service: string]: LooseHandlerMap;
19
+ };
17
20
  state?: Partial<TState>;
18
21
  streamCleanupMode?: StreamCleanupMode;
19
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socket-mesh/core",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Core module for SocketMesh Server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",