MCPcopy Create free account
hub / github.com/apitable/apitable / socketGuard

Function socketGuard

packages/core/src/utils/socket_guard.ts:19–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17 */
18
19export const socketGuard = () => {
20 return function(
21 _target: any,
22 _propertyKey: string | symbol,
23 descriptor: PropertyDescriptor,
24 ): PropertyDescriptor {
25 const originalMethod = descriptor.value;
26 let ignoreSocketError = false;
27 let timeout: NodeJS.Timeout;
28 const socketErrCodes = [50000, 50001];
29 descriptor.value = function(this: any, ...arg: any[]): any {
30 if (!this.io.socket.connected) {
31 return (() => {})();
32 }
33 if (socketErrCodes.includes(arg[0]?.code)) {
34 if (ignoreSocketError) {
35 ignoreSocketError = false;
36 timeout && clearTimeout(timeout);
37 return originalMethod.apply(this, [...arg, false]);
38 }
39 ignoreSocketError = true;
40 timeout = setTimeout(() => {
41 ignoreSocketError = false;
42 }, 15 * 1000);
43 return;
44 }
45
46 return originalMethod.apply(this, arg);
47 };
48 return descriptor;
49 };
50};

Callers 1

RoomServiceClass · 0.90

Calls 2

clearTimeoutFunction · 0.85
applyMethod · 0.45

Tested by

no test coverage detected