socket-function 1.1.8 → 1.1.10

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.
@@ -64,6 +64,7 @@ export declare class SocketFunction {
64
64
  private static socketCache;
65
65
  static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
66
66
  private static callFromGuid;
67
+ /** 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
68
  static onNextDisconnect(nodeId: string, callback: () => void): void;
68
69
  static getLastDisconnectTime(nodeId: string): number | undefined;
69
70
  static isNodeConnected(nodeId: string): boolean;
package/SocketFunction.ts CHANGED
@@ -289,6 +289,7 @@ export class SocketFunction {
289
289
  }
290
290
  }
291
291
 
292
+ /** 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). */
292
293
  public static onNextDisconnect(nodeId: string, callback: () => void) {
293
294
  (async () => {
294
295
  let factory = await getCallFactory(nodeId);
package/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare module "socket-function/SocketFunction" {
73
73
  private static socketCache;
74
74
  static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
75
75
  private static callFromGuid;
76
+ /** 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
77
  static onNextDisconnect(nodeId: string, callback: () => void): void;
77
78
  static getLastDisconnectTime(nodeId: string): number | undefined;
78
79
  static isNodeConnected(nodeId: string): boolean;
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
7
  "@types/pako": "^2.0.3",
8
8
  "@types/ws": "^8.5.3",
9
9
  "cbor-x": "^1.6.0",
10
- "lmdb": "^3.5.1",
11
10
  "mobx": "^6.6.2",
12
11
  "pako": "^2.1.0",
13
12
  "preact": "10.24.3",
@@ -15,6 +14,9 @@
15
14
  "typenode": "^6.0.1",
16
15
  "ws": "^8.17.1"
17
16
  },
17
+ "optionalDependencies": {
18
+ "lmdb": "^3.5.1"
19
+ },
18
20
  "types": "index.d.ts",
19
21
  "scripts": {
20
22
  "test": "yarn typenode ./test.ts",
@@ -145,9 +145,9 @@ export async function createCallFactory(
145
145
  localNodeId
146
146
  };
147
147
 
148
- let disconnectCallbacks: (() => void)[] = [];
148
+ let disconnectCallbacks = new Set<() => void>();
149
149
  function onNextDisconnect(callback: () => void): void {
150
- disconnectCallbacks.push(callback);
150
+ disconnectCallbacks.add(callback);
151
151
  }
152
152
 
153
153
  let callFactory: CallFactory = {
@@ -315,7 +315,7 @@ export async function createCallFactory(
315
315
  }
316
316
 
317
317
  let callbacks = disconnectCallbacks;
318
- disconnectCallbacks = [];
318
+ disconnectCallbacks = new Set();
319
319
  for (let callback of callbacks) {
320
320
  try {
321
321
  callback();
@@ -720,12 +720,13 @@ export async function createCallFactory(
720
720
  if (!pendingCall) {
721
721
  throw new Error(`Received data without size ${message.byteLength}B, first 100 bytes: ${message.slice(0, 100).toString("hex")}`);
722
722
  }
723
- if (message.byteLength > 1000 * 1000 * 10 || pendingCall.bufferCount > 1000 && (pendingCall.buffers.length % 100 === 0)) {
723
+ let totalSize = message.byteLength + pendingCall.buffers.reduce((a, b) => a + b.length, 0);
724
+ if (totalSize > 1000 * 1000 * 10 || pendingCall.bufferCount > 1000 && (pendingCall.buffers.length % 100 === 0)) {
724
725
  if (pendingCall.buffers.length === 0) {
725
- console.log(`Received large/many packets ${formatNumber(message.byteLength)}B (${pendingCall.buffers.length} / ${pendingCall.bufferCount}) at ${Date.now()}`);
726
+ console.log(`Received large/many packets ${formatNumber(totalSize)}B (${pendingCall.buffers.length} / ${pendingCall.bufferCount}) at ${Date.now()}`);
726
727
  } else {
727
728
  let elapsed = Date.now() - (pendingCall.firstReceivedTime || 0);
728
- console.log(`Received large/many packets ${formatNumber(message.byteLength)}B (${pendingCall.buffers.length} / ${pendingCall.bufferCount}) after ${formatTime(elapsed)}`);
729
+ console.log(`Received large/many packets ${formatNumber(totalSize)}B (${pendingCall.buffers.length} / ${pendingCall.bufferCount}) after ${formatTime(elapsed)}`);
729
730
  }
730
731
  }
731
732
  if (pendingCall.buffers.length === 0) {