socket-function 1.1.16 → 1.1.17

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
@@ -467,6 +467,7 @@ declare module "socket-function/src/CallFactory" {
467
467
  import * as tls from "tls";
468
468
  export interface CallFactory {
469
469
  nodeId: string;
470
+ realNodeId?: string;
470
471
  lastClosed: number;
471
472
  closedForever?: boolean;
472
473
  isConnected?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -6,6 +6,7 @@ import * as ws from "ws";
6
6
  import * as tls from "tls";
7
7
  export interface CallFactory {
8
8
  nodeId: string;
9
+ realNodeId?: string;
9
10
  lastClosed: number;
10
11
  closedForever?: boolean;
11
12
  isConnected?: boolean;
@@ -44,6 +44,7 @@ type InternalReturnType = {
44
44
 
45
45
  export interface CallFactory {
46
46
  nodeId: string;
47
+ realNodeId?: string;
47
48
  lastClosed: number;
48
49
  closedForever?: boolean;
49
50
  isConnected?: boolean;
@@ -53,6 +54,7 @@ export interface CallFactory {
53
54
  performCall(call: CallType): Promise<unknown>;
54
55
  onNextDisconnect(callback: () => void): void;
55
56
  disconnect(): void;
57
+ // If we change the node ID we need to recreate this object, essentially this object should be immutable. I forget why we wanted this. I think it's because we didn't know for sure if node ID would be unique, but it will be.
56
58
  connectionId: { nodeId: string };
57
59
  }
58
60
 
@@ -161,6 +163,8 @@ export async function createCallFactory(
161
163
  receivedInitializeState: undefined,
162
164
  onNextDisconnect,
163
165
  disconnect() {
166
+ canReconnect = false;
167
+ callFactory.closedForever = true;
164
168
  if (webSocketPromise) {
165
169
  webSocketPromise.then(ws => ws.close()).catch(() => { });
166
170
  }
@@ -557,6 +561,10 @@ export async function createCallFactory(
557
561
  if (!SocketFunction.LEGACY_INITIALIZE && call.seqNum === INITIALIZE_STATE_SEQ_NUM) {
558
562
  callFactory.receivedInitializeState = call.result as InitializeState;
559
563
  let otherReconnectionUrl = callFactory.receivedInitializeState.ownReconnectionUrl;
564
+ callFactory.realNodeId = otherReconnectionUrl;
565
+ if (SocketFunction.logMessages) {
566
+ console.log(green(`Received initialize state from ${callFactory.realNodeId} at ${Date.now()}`));
567
+ }
560
568
  if (otherReconnectionUrl && !canReconnect && !!getNodeIdLocation(otherReconnectionUrl) && otherReconnectionUrl !== ownReconnectionUrl) {
561
569
  if (changeNodeId({
562
570
  originalNodeId: nodeId,
@@ -568,7 +576,7 @@ export async function createCallFactory(
568
576
  callerContext.nodeId = nodeId;
569
577
  canReconnect = !!getNodeIdLocation(nodeId);
570
578
  callFactory.nodeId = nodeId;
571
- callFactory.connectionId.nodeId = nodeId;
579
+ callFactory.connectionId = { nodeId };
572
580
  }
573
581
  }
574
582
  return;
@@ -790,8 +798,14 @@ export async function createCallFactory(
790
798
  result: initState,
791
799
  seqNum: INITIALIZE_STATE_SEQ_NUM,
792
800
  };
801
+ if (SocketFunction.logMessages) {
802
+ console.log(`Sending initialize state to ${nodeId}`);
803
+ }
793
804
  let data = await SocketFunction.WIRE_SERIALIZER.serialize(initReturn);
794
805
  await send(data);
806
+ if (SocketFunction.logMessages) {
807
+ console.log(`Sent initialize state to ${nodeId}`);
808
+ }
795
809
  }
796
810
 
797
811
  return callFactory;