MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / startPinging

Function startPinging

src/shared/utils/ws.ts:12–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10 */
11export function attachPing(socket: ws.WebSocket, pingInterval = 15000) {
12 const startPinging = () => {
13 const timer = setInterval(() => {
14 if (socket.readyState === ws.WebSocket.OPEN) {
15 try {
16 socket.ping();
17 } catch {
18 clear();
19 }
20 } else {
21 clear();
22 }
23 }, pingInterval).unref();
24
25 const clear = () => {
26 clearInterval(timer);
27 socket.removeListener("close", clear);
28 socket.removeListener("error", clear);
29 };
30
31 socket.on("close", clear);
32 socket.on("error", clear);
33 };
34
35 if (socket.readyState === ws.WebSocket.OPEN) {
36 startPinging();

Callers 1

attachPingFunction · 0.85

Calls 2

clearFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected