socket-function 1.1.30 → 1.1.32
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/SocketFunction.d.ts +4 -2
- package/SocketFunction.ts +13 -3
- package/index.d.ts +4 -2
- package/package.json +1 -1
- package/src/CallFactory.ts +1 -0
package/SocketFunction.d.ts
CHANGED
|
@@ -63,8 +63,10 @@ export declare class SocketFunction {
|
|
|
63
63
|
private static socketCache;
|
|
64
64
|
static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
|
|
65
65
|
private static callFromGuid;
|
|
66
|
-
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback).
|
|
67
|
-
|
|
66
|
+
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback).
|
|
67
|
+
IMPORTANT! Client node ids will NEVER reconnect, so this can full cleanup. However full nodeIds might if we try to use that nodeId again, so this cannot fully clean them up.
|
|
68
|
+
*/
|
|
69
|
+
static onNextDisconnect(nodeId: string, callback: () => void, noServerNodeIdWarning?: "iKnowThatServerNodeIdsMayReconnect_andIHandleReconnections"): void;
|
|
68
70
|
static getLastDisconnectTime(nodeId: string): number | undefined;
|
|
69
71
|
static isNodeConnected(nodeId: string): boolean;
|
|
70
72
|
/** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
|
package/SocketFunction.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { SocketExposedInterface, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, CallerContext, FullCallType, CallType, FncType, SocketRegisterType } from "./SocketFunctionTypes";
|
|
4
4
|
import { exposeClass, registerClass, registerGlobalClientHook, registerGlobalHook, runClientHooks } from "./src/callManager";
|
|
5
5
|
import { SocketServerConfig, startSocketServer } from "./src/webSocketServer";
|
|
6
|
-
import { getCallFactory, getCreateCallFactory, getNodeId, getNodeIdLocation } from "./src/nodeCache";
|
|
6
|
+
import { getCallFactory, getCreateCallFactory, getNodeId, getNodeIdLocation, isClientNodeId } from "./src/nodeCache";
|
|
7
7
|
import { getCallProxy } from "./src/nodeProxy";
|
|
8
8
|
import { Args, MaybePromise } from "./src/types";
|
|
9
9
|
import { setDefaultHTTPCall } from "./src/callHTTPHandler";
|
|
@@ -287,8 +287,18 @@ export class SocketFunction {
|
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback).
|
|
291
|
-
|
|
290
|
+
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback).
|
|
291
|
+
IMPORTANT! Client node ids will NEVER reconnect, so this can full cleanup. However full nodeIds might if we try to use that nodeId again, so this cannot fully clean them up.
|
|
292
|
+
*/
|
|
293
|
+
public static onNextDisconnect(
|
|
294
|
+
nodeId: string,
|
|
295
|
+
callback: () => void,
|
|
296
|
+
// NOTE: It's important to know that unlike client ids, server ids (a nodeId YOU connect to, instead of connecting to you), might be alive again, and so you need some kind of logic to try it again or in some way reconnect. For clients you don't need to, as it's their job to reconnect to you, and they will reconnect with a NEW nodeId.
|
|
297
|
+
noServerNodeIdWarning?: "iKnowThatServerNodeIdsMayReconnect_andIHandleReconnections"
|
|
298
|
+
) {
|
|
299
|
+
if (!isClientNodeId(nodeId) && !noServerNodeIdWarning) {
|
|
300
|
+
console.warn(`Watching for disconnections of ${nodeId}. This is a server nodeId and may be alive again after disconnection. Please set the noServerNodeIdWarning flag in this argument to confirm you are handling reconnecting if the server becomes available again.`);
|
|
301
|
+
}
|
|
292
302
|
(async () => {
|
|
293
303
|
let factory = await getCallFactory(nodeId);
|
|
294
304
|
if (!factory) {
|
package/index.d.ts
CHANGED
|
@@ -72,8 +72,10 @@ declare module "socket-function/SocketFunction" {
|
|
|
72
72
|
private static socketCache;
|
|
73
73
|
static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
|
|
74
74
|
private static callFromGuid;
|
|
75
|
-
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback).
|
|
76
|
-
|
|
75
|
+
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback).
|
|
76
|
+
IMPORTANT! Client node ids will NEVER reconnect, so this can full cleanup. However full nodeIds might if we try to use that nodeId again, so this cannot fully clean them up.
|
|
77
|
+
*/
|
|
78
|
+
static onNextDisconnect(nodeId: string, callback: () => void, noServerNodeIdWarning?: "iKnowThatServerNodeIdsMayReconnect_andIHandleReconnections"): void;
|
|
77
79
|
static getLastDisconnectTime(nodeId: string): number | undefined;
|
|
78
80
|
static isNodeConnected(nodeId: string): boolean;
|
|
79
81
|
/** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
|
package/package.json
CHANGED
package/src/CallFactory.ts
CHANGED
|
@@ -474,6 +474,7 @@ export async function createCallFactory(
|
|
|
474
474
|
...data,
|
|
475
475
|
]);
|
|
476
476
|
}
|
|
477
|
+
// IMPORTANT! NEVER allow for reconnection of client ids. A lot of code depends on the fact that clients will reconnect with a new client node id when they disconnect!
|
|
477
478
|
async function tryToReconnect(): Promise<SenderInterface> {
|
|
478
479
|
// Don't try to reconnect too often!
|
|
479
480
|
let timeSinceLastAttempt = Date.now() - lastConnectionAttempt;
|