(opts: WsConnectionOptions)
| 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; |
nothing calls this directly
no test coverage detected