socket-function 1.1.7 → 1.1.9
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 +1 -0
- package/SocketFunction.ts +2 -0
- package/index.d.ts +1 -0
- package/package.json +4 -2
- package/src/CallFactory.ts +5 -3
package/SocketFunction.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare class SocketFunction {
|
|
|
25
25
|
static LEGACY_INITIALIZE: boolean;
|
|
26
26
|
static COEP: string;
|
|
27
27
|
static COOP: string;
|
|
28
|
+
static TOTAL_CALLS: number;
|
|
28
29
|
static readonly WIRE_SERIALIZER: {
|
|
29
30
|
serialize: (obj: unknown) => MaybePromise<Buffer[]>;
|
|
30
31
|
deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
|
package/SocketFunction.ts
CHANGED
|
@@ -69,6 +69,8 @@ export class SocketFunction {
|
|
|
69
69
|
// NOTE: This COOP and COEP defaults are required so window.crossOriginIsolated will be true.
|
|
70
70
|
public static COOP = "same-origin";
|
|
71
71
|
|
|
72
|
+
public static TOTAL_CALLS = 0;
|
|
73
|
+
|
|
72
74
|
// In retrospect... dynamically changing the wire serializer is a BAD idea. If any calls happen
|
|
73
75
|
// before it is changed, things just break. Also, it needs to be changed on both sides,
|
|
74
76
|
// or else things break. Also, it is very hard to detect when the issue is different serializers
|
package/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ declare module "socket-function/SocketFunction" {
|
|
|
34
34
|
static LEGACY_INITIALIZE: boolean;
|
|
35
35
|
static COEP: string;
|
|
36
36
|
static COOP: string;
|
|
37
|
+
static TOTAL_CALLS: number;
|
|
37
38
|
static readonly WIRE_SERIALIZER: {
|
|
38
39
|
serialize: (obj: unknown) => MaybePromise<Buffer[]>;
|
|
39
40
|
deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "socket-function",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
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",
|
package/src/CallFactory.ts
CHANGED
|
@@ -586,6 +586,7 @@ export async function createCallFactory(
|
|
|
586
586
|
|
|
587
587
|
let response: InternalReturnType;
|
|
588
588
|
try {
|
|
589
|
+
SocketFunction.TOTAL_CALLS++;
|
|
589
590
|
let result = await performLocalCall({ call, caller: callerContext });
|
|
590
591
|
response = {
|
|
591
592
|
isReturn: true,
|
|
@@ -719,12 +720,13 @@ export async function createCallFactory(
|
|
|
719
720
|
if (!pendingCall) {
|
|
720
721
|
throw new Error(`Received data without size ${message.byteLength}B, first 100 bytes: ${message.slice(0, 100).toString("hex")}`);
|
|
721
722
|
}
|
|
722
|
-
|
|
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)) {
|
|
723
725
|
if (pendingCall.buffers.length === 0) {
|
|
724
|
-
console.log(`Received large/many packets ${formatNumber(
|
|
726
|
+
console.log(`Received large/many packets ${formatNumber(totalSize)}B (${pendingCall.buffers.length} / ${pendingCall.bufferCount}) at ${Date.now()}`);
|
|
725
727
|
} else {
|
|
726
728
|
let elapsed = Date.now() - (pendingCall.firstReceivedTime || 0);
|
|
727
|
-
console.log(`Received large/many packets ${formatNumber(
|
|
729
|
+
console.log(`Received large/many packets ${formatNumber(totalSize)}B (${pendingCall.buffers.length} / ${pendingCall.bufferCount}) after ${formatTime(elapsed)}`);
|
|
728
730
|
}
|
|
729
731
|
}
|
|
730
732
|
if (pendingCall.buffers.length === 0) {
|