socket-function 1.1.12 → 1.1.13

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/index.d.ts CHANGED
@@ -492,6 +492,7 @@ declare module "socket-function/src/CallFactory" {
492
492
  }
493
493
  type InitializeState = {
494
494
  supportsLZ4?: boolean;
495
+ ownReconnectionUrl?: string;
495
496
  };
496
497
  export declare function harvestFailedCallCount(): number;
497
498
  export declare function getPendingCallCount(): number;
@@ -500,6 +501,7 @@ declare module "socket-function/src/CallFactory" {
500
501
  end: number;
501
502
  }[];
502
503
  export declare function createCallFactory(webSocketBase: SenderInterface | undefined, nodeId: string, localNodeId?: string): Promise<CallFactory>;
504
+ export declare function registerOwnReconnectionUrl(url: string): void;
503
505
  export {};
504
506
 
505
507
  }
@@ -1066,6 +1068,11 @@ declare module "socket-function/src/nodeCache" {
1066
1068
  export declare function getNodeIdDomain(nodeId: string): string;
1067
1069
  export declare function getNodeIdDomainMaybeUndefined(nodeId: string): string | undefined;
1068
1070
  export declare function registerNodeClient(callFactory: CallFactory): void;
1071
+ export declare function changeNodeId(config: {
1072
+ originalNodeId: string;
1073
+ newNodeId: string;
1074
+ callFactory: CallFactory;
1075
+ }): void;
1069
1076
  export declare function getCreateCallFactory(nodeId: string): MaybePromise<CallFactory>;
1070
1077
  export declare function getCallFactory(nodeId: string): MaybePromise<CallFactory | undefined>;
1071
1078
  export declare function debugGetAllCallFactories(): CallFactory[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -31,6 +31,7 @@ export interface SenderInterface {
31
31
  }
32
32
  type InitializeState = {
33
33
  supportsLZ4?: boolean;
34
+ ownReconnectionUrl?: string;
34
35
  };
35
36
  export declare function harvestFailedCallCount(): number;
36
37
  export declare function getPendingCallCount(): number;
@@ -39,4 +40,5 @@ export declare function harvestCallTimes(): {
39
40
  end: number;
40
41
  }[];
41
42
  export declare function createCallFactory(webSocketBase: SenderInterface | undefined, nodeId: string, localNodeId?: string): Promise<CallFactory>;
43
+ export declare function registerOwnReconnectionUrl(url: string): void;
42
44
  export {};
@@ -5,7 +5,7 @@ import { convertErrorStackToError, formatNumberSuffixed, isBufferType, isNode, l
5
5
  import { createWebsocketFactory, getTLSSocket } from "./websocketFactory";
6
6
  import { SocketFunction } from "../SocketFunction";
7
7
  import * as tls from "tls";
8
- import { getClientNodeId, getNodeIdLocation, registerNodeClient } from "./nodeCache";
8
+ import { changeNodeId, getClientNodeId, getNodeIdLocation, registerNodeClient } from "./nodeCache";
9
9
  import debugbreak from "debugbreak";
10
10
  import { lazy } from "./caching";
11
11
  import { blue, green, red, yellow } from "./formatting/logColors";
@@ -74,6 +74,7 @@ export interface SenderInterface {
74
74
 
75
75
  type InitializeState = {
76
76
  supportsLZ4?: boolean;
77
+ ownReconnectionUrl?: string;
77
78
  };
78
79
 
79
80
  const INITIALIZE_STATE_SEQ_NUM = -1;
@@ -114,7 +115,7 @@ export async function createCallFactory(
114
115
  const createWebsocket = createWebsocketFactory();
115
116
  const registerOnce = lazy(() => registerNodeClient(callFactory));
116
117
 
117
- const canReconnect = !!getNodeIdLocation(nodeId);
118
+ let canReconnect = !!getNodeIdLocation(nodeId);
118
119
 
119
120
  let pendingCalls: Map<number, {
120
121
  data: Buffer[];
@@ -547,6 +548,20 @@ export async function createCallFactory(
547
548
  if (call.isReturn) {
548
549
  if (!SocketFunction.LEGACY_INITIALIZE && call.seqNum === INITIALIZE_STATE_SEQ_NUM) {
549
550
  callFactory.receivedInitializeState = call.result as InitializeState;
551
+ let otherReconnectionUrl = callFactory.receivedInitializeState.ownReconnectionUrl;
552
+ if (otherReconnectionUrl && !canReconnect && !!getNodeIdLocation(otherReconnectionUrl)) {
553
+ changeNodeId({
554
+ originalNodeId: nodeId,
555
+ newNodeId: otherReconnectionUrl,
556
+ callFactory,
557
+ });
558
+ nodeId = otherReconnectionUrl;
559
+ niceConnectionName = otherReconnectionUrl;
560
+ callerContext.nodeId = nodeId;
561
+ canReconnect = !!getNodeIdLocation(nodeId);
562
+ callFactory.nodeId = nodeId;
563
+ callFactory.connectionId.nodeId = nodeId;
564
+ }
550
565
  return;
551
566
  }
552
567
  let callbackObj = pendingCalls.get(call.seqNum);
@@ -759,6 +774,7 @@ export async function createCallFactory(
759
774
  if (!SocketFunction.LEGACY_INITIALIZE) {
760
775
  let initState: InitializeState = {
761
776
  supportsLZ4: true,
777
+ ownReconnectionUrl,
762
778
  };
763
779
  let initReturn: InternalReturnType = {
764
780
  isReturn: true,
@@ -772,6 +788,10 @@ export async function createCallFactory(
772
788
  return callFactory;
773
789
  }
774
790
 
791
+ let ownReconnectionUrl: string | undefined;
792
+ export function registerOwnReconnectionUrl(url: string) {
793
+ ownReconnectionUrl = url;
794
+ }
775
795
 
776
796
 
777
797
  let uncompressedSent = 0;
@@ -18,6 +18,11 @@ export declare function getNodeIdLocation(nodeId: string): {
18
18
  export declare function getNodeIdDomain(nodeId: string): string;
19
19
  export declare function getNodeIdDomainMaybeUndefined(nodeId: string): string | undefined;
20
20
  export declare function registerNodeClient(callFactory: CallFactory): void;
21
+ export declare function changeNodeId(config: {
22
+ originalNodeId: string;
23
+ newNodeId: string;
24
+ callFactory: CallFactory;
25
+ }): void;
21
26
  export declare function getCreateCallFactory(nodeId: string): MaybePromise<CallFactory>;
22
27
  export declare function getCallFactory(nodeId: string): MaybePromise<CallFactory | undefined>;
23
28
  export declare function debugGetAllCallFactories(): CallFactory[];
package/src/nodeCache.ts CHANGED
@@ -77,6 +77,16 @@ export function registerNodeClient(callFactory: CallFactory) {
77
77
  startCleanupLoop();
78
78
  }
79
79
 
80
+ export function changeNodeId(config: {
81
+ originalNodeId: string;
82
+ newNodeId: string;
83
+ callFactory: CallFactory;
84
+ }) {
85
+ if (nodeCache.has(config.newNodeId)) return;
86
+ nodeCache.delete(config.originalNodeId);
87
+ nodeCache.set(config.newNodeId, config.callFactory);
88
+ }
89
+
80
90
  export function getCreateCallFactory(nodeId: string): MaybePromise<CallFactory> {
81
91
  let callFactory = nodeCache.get(nodeId);
82
92
  if (callFactory === undefined) {