MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / constructor

Method constructor

packages/server/src/ws/connection.ts:163–194  ·  view source on GitHub ↗
(opts: WsConnectionOptions)

Source from the content-addressed store, hash-verified

161 private gotClientHello = false;
162
163 constructor(opts: WsConnectionOptions) {
164 this.id = `conn_${ulid()}`;
165 this.connectedAt = new Date().toISOString();
166 this.remoteAddress = opts.remoteAddress ?? null;
167 this.userAgent = opts.userAgent ?? null;
168 this.socket = opts.socket;
169 this.logger = opts.logger.child({ connId: this.id });
170 this.sessionClients = opts.sessionClients;
171 this.wsBroadcast = opts.wsBroadcast;
172 this.abortHandler = opts.abortHandler;
173 this.fsWatchHandler = opts.fsWatchHandler;
174 this.terminalHandler = opts.terminalHandler;
175 this.pingIntervalMs = opts.pingIntervalMs ?? DEFAULT_PING_INTERVAL_MS;
176 this.pongTimeoutMs = opts.pongTimeoutMs ?? DEFAULT_PONG_TIMEOUT_MS;
177 this.maxEventBufferSize = opts.maxEventBufferSize ?? DEFAULT_MAX_EVENT_BUFFER;
178
179 this.send(
180 buildServerHello({
181 ws_connection_id: this.id,
182 protocol_version: WS_PROTOCOL_VERSION,
183 heartbeat_ms: this.pingIntervalMs,
184 max_event_buffer_size: this.maxEventBufferSize,
185 capabilities: { event_batching: false, compression: false },
186 }),
187 );
188
189 this.socket.on('message', (data) => this.onMessage(data));
190 this.socket.on('close', (code, reason) => this.onClose(code, String(reason)));
191 this.socket.on('error', (err) => this.logger.warn({ err: String(err) }, 'ws socket error'));
192
193 this.startPingTimer();
194 }
195
196 private onMessage(data: RawData): void {
197 if (this.closed) return;

Callers

nothing calls this directly

Calls 9

sendMethod · 0.95
onMessageMethod · 0.95
onCloseMethod · 0.95
startPingTimerMethod · 0.95
buildServerHelloFunction · 0.90
ulidFunction · 0.85
childMethod · 0.65
onMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected