socket-function 1.2.29 → 1.2.31
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/SocketFunctionTypes.d.ts +4 -0
- package/SocketFunctionTypes.ts +4 -0
- package/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/CallFactory.ts +5 -5
- package/src/callManager.ts +6 -2
- package/src/misc.ts +5 -1
package/SocketFunctionTypes.d.ts
CHANGED
|
@@ -62,6 +62,10 @@ export type ClientHookContext = {
|
|
|
62
62
|
};
|
|
63
63
|
export interface SocketFunctionClientHook {
|
|
64
64
|
(config: ClientHookContext): MaybePromise<void>;
|
|
65
|
+
/** Set on hooks which are called so frequently (or are so trivial) that the measurement overhead
|
|
66
|
+
* and profiling noise outweighs the value of measuring them.
|
|
67
|
+
*/
|
|
68
|
+
noMeasure?: boolean;
|
|
65
69
|
}
|
|
66
70
|
export interface SocketRegisterType<ExposedType = any> {
|
|
67
71
|
_classGuid: string;
|
package/SocketFunctionTypes.ts
CHANGED
|
@@ -92,6 +92,10 @@ export type ClientHookContext = {
|
|
|
92
92
|
};
|
|
93
93
|
export interface SocketFunctionClientHook {
|
|
94
94
|
(config: ClientHookContext): MaybePromise<void>;
|
|
95
|
+
/** Set on hooks which are called so frequently (or are so trivial) that the measurement overhead
|
|
96
|
+
* and profiling noise outweighs the value of measuring them.
|
|
97
|
+
*/
|
|
98
|
+
noMeasure?: boolean;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
export interface SocketRegisterType<ExposedType = any> {
|
package/index.d.ts
CHANGED
|
@@ -194,6 +194,10 @@ declare module "socket-function/SocketFunctionTypes" {
|
|
|
194
194
|
};
|
|
195
195
|
export interface SocketFunctionClientHook {
|
|
196
196
|
(config: ClientHookContext): MaybePromise<void>;
|
|
197
|
+
/** Set on hooks which are called so frequently (or are so trivial) that the measurement overhead
|
|
198
|
+
* and profiling noise outweighs the value of measuring them.
|
|
199
|
+
*/
|
|
200
|
+
noMeasure?: boolean;
|
|
197
201
|
}
|
|
198
202
|
export interface SocketRegisterType<ExposedType = any> {
|
|
199
203
|
_classGuid: string;
|
package/package.json
CHANGED
package/src/CallFactory.ts
CHANGED
|
@@ -316,7 +316,7 @@ export async function createCallFactory(
|
|
|
316
316
|
registerOnce();
|
|
317
317
|
callFactory.receivedInitializeState = undefined;
|
|
318
318
|
|
|
319
|
-
function onClose(
|
|
319
|
+
function onClose(message: string) {
|
|
320
320
|
// We try various connections, and if they fail, we will just try other node IDs until we finally do connect, and then we stick with that nodeId, and when it disconnects we need to handle disconnections normally.
|
|
321
321
|
if (skipCloseHandling && !hasEverConnected) {
|
|
322
322
|
return;
|
|
@@ -335,7 +335,7 @@ export async function createCallFactory(
|
|
|
335
335
|
call.callback({
|
|
336
336
|
isReturn: true,
|
|
337
337
|
result: undefined,
|
|
338
|
-
error:
|
|
338
|
+
error: `Call failed for ${call.call.classGuid}.${call.call.functionName}: ${message}`,
|
|
339
339
|
seqNum: call.call.seqNum,
|
|
340
340
|
});
|
|
341
341
|
}
|
|
@@ -353,12 +353,12 @@ export async function createCallFactory(
|
|
|
353
353
|
// NOTE: No more logging, as we throw, so the caller should be logging the
|
|
354
354
|
// error (or swallowing it, if that is what it wants to do).
|
|
355
355
|
//console.log(`Websocket error for ${niceConnectionName}`, e.message);
|
|
356
|
-
onClose(
|
|
356
|
+
onClose(`Connection error for ${niceConnectionName}: ${e.message}`);
|
|
357
357
|
});
|
|
358
358
|
|
|
359
359
|
newWebSocket.addEventListener("close", async () => {
|
|
360
360
|
//console.log(`Websocket closed ${niceConnectionName}`);
|
|
361
|
-
onClose(
|
|
361
|
+
onClose(`Connection closed to ${niceConnectionName}`);
|
|
362
362
|
});
|
|
363
363
|
|
|
364
364
|
newWebSocket.addEventListener("message", onMessage);
|
|
@@ -381,7 +381,7 @@ export async function createCallFactory(
|
|
|
381
381
|
callFactory.isConnected = true;
|
|
382
382
|
hasEverConnected = true;
|
|
383
383
|
} else {
|
|
384
|
-
onClose(
|
|
384
|
+
onClose(`Websocket received in closed state`);
|
|
385
385
|
}
|
|
386
386
|
|
|
387
387
|
if (callFactory.lastClosed && callFactory.isConnected) {
|
package/src/callManager.ts
CHANGED
|
@@ -147,9 +147,13 @@ export const runClientHooks = measureWrap(async function runClientHooks(
|
|
|
147
147
|
}
|
|
148
148
|
for (let hook of clientHooks) {
|
|
149
149
|
let time = Date.now();
|
|
150
|
-
|
|
150
|
+
if (hook.noMeasure) {
|
|
151
151
|
await hook(context);
|
|
152
|
-
}
|
|
152
|
+
} else {
|
|
153
|
+
await measureBlock(async () => {
|
|
154
|
+
await hook(context);
|
|
155
|
+
}, `clientHook|${hook.name || hook.toString().slice(0, 100)}`);
|
|
156
|
+
}
|
|
153
157
|
let now = Date.now();
|
|
154
158
|
time = now - time;
|
|
155
159
|
if (time > 500 && now - startupTime > 60_000) {
|
package/src/misc.ts
CHANGED
|
@@ -15,7 +15,11 @@ export type Watchable<T> = (callback: (value: T) => void) => MaybePromise<void>;
|
|
|
15
15
|
export function convertErrorStackToError(error: string): Error {
|
|
16
16
|
let errorObj = new Error();
|
|
17
17
|
errorObj.stack = String(error);
|
|
18
|
-
|
|
18
|
+
let message = String(error).split("\n")[0];
|
|
19
|
+
if (message.startsWith("Error: ")) {
|
|
20
|
+
message = message.slice("Error: ".length);
|
|
21
|
+
}
|
|
22
|
+
errorObj.message = message;
|
|
19
23
|
return errorObj;
|
|
20
24
|
}
|
|
21
25
|
|