MCPcopy Create free account
hub / github.com/CopilotKit/aimock / close

Method close

src/ws-framing.ts:58–78  ·  view source on GitHub ↗
(code = 1000, reason = "")

Source from the content-addressed store, hash-verified

56 }
57
58 close(code = 1000, reason = ""): void {
59 if (this.closed) return;
60 this.closed = true;
61
62 const reasonBuf = Buffer.from(reason, "utf-8");
63 const payload = Buffer.alloc(2 + reasonBuf.length);
64 payload.writeUInt16BE(code, 0);
65 reasonBuf.copy(payload, 2);
66 this.writeFrame(OP_CLOSE, payload);
67
68 // Give the client a moment to receive the close frame before destroying.
69 // If writeFrame failed (socket already destroyed), this is a no-op.
70 setTimeout(() => {
71 if (!this.socket.destroyed) {
72 this.socket.destroy();
73 }
74 // Emit close event for server-initiated closes so listeners
75 // (e.g. activeConnections.delete) always fire.
76 this.emit("close", code, reason);
77 }, 100);
78 }
79
80 destroy(): void {
81 if (this.closed) return;

Callers

nothing calls this directly

Calls 2

writeFrameMethod · 0.95
destroyMethod · 0.45

Tested by

no test coverage detected