socket-function 1.1.16 → 1.1.18
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 +1 -0
- package/package.json +1 -1
- package/src/CallFactory.d.ts +1 -0
- package/src/CallFactory.ts +18 -1
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/CallFactory.d.ts
CHANGED
package/src/CallFactory.ts
CHANGED
|
@@ -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,18 +561,25 @@ 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} (for ${nodeId}) at ${Date.now()}`));
|
|
567
|
+
}
|
|
560
568
|
if (otherReconnectionUrl && !canReconnect && !!getNodeIdLocation(otherReconnectionUrl) && otherReconnectionUrl !== ownReconnectionUrl) {
|
|
561
569
|
if (changeNodeId({
|
|
562
570
|
originalNodeId: nodeId,
|
|
563
571
|
newNodeId: otherReconnectionUrl,
|
|
564
572
|
callFactory,
|
|
565
573
|
})) {
|
|
574
|
+
if (SocketFunction.logMessages) {
|
|
575
|
+
console.log(green(`Changed node id from ${nodeId} to ${otherReconnectionUrl}`));
|
|
576
|
+
}
|
|
566
577
|
nodeId = otherReconnectionUrl;
|
|
567
578
|
niceConnectionName = otherReconnectionUrl;
|
|
568
579
|
callerContext.nodeId = nodeId;
|
|
569
580
|
canReconnect = !!getNodeIdLocation(nodeId);
|
|
570
581
|
callFactory.nodeId = nodeId;
|
|
571
|
-
callFactory.connectionId
|
|
582
|
+
callFactory.connectionId = { nodeId };
|
|
572
583
|
}
|
|
573
584
|
}
|
|
574
585
|
return;
|
|
@@ -790,8 +801,14 @@ export async function createCallFactory(
|
|
|
790
801
|
result: initState,
|
|
791
802
|
seqNum: INITIALIZE_STATE_SEQ_NUM,
|
|
792
803
|
};
|
|
804
|
+
if (SocketFunction.logMessages) {
|
|
805
|
+
console.log(`Sending initialize state to ${nodeId}`);
|
|
806
|
+
}
|
|
793
807
|
let data = await SocketFunction.WIRE_SERIALIZER.serialize(initReturn);
|
|
794
808
|
await send(data);
|
|
809
|
+
if (SocketFunction.logMessages) {
|
|
810
|
+
console.log(`Sent initialize state to ${nodeId}`);
|
|
811
|
+
}
|
|
795
812
|
}
|
|
796
813
|
|
|
797
814
|
return callFactory;
|