MCPcopy Create free account
hub / github.com/Streamerbot/client / handshake

Method handshake

packages/client/src/ws/StreamerbotClient.ts:269–318  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

267 this._explicitlyClosed = true;
268 this._connectController.abort();
269 if (this._reconnectTimeout) clearTimeout(this._reconnectTimeout);
270 if (!this.socket || this.socket.readyState === this.socket.CLOSED) return;
271
272 const controller = new AbortController();
273 const signal = controller.signal;
274
275 this._connectController.signal.addEventListener('abort', () => controller.abort(), {
276 once: true,
277 signal,
278 });
279
280 return await withTimeout(
281 new Promise<void>((res, rej) => {
282 if (!this.socket) return;
283
284 this.socket.addEventListener(
285 'close',
286 () => {
287 this.logger?.debug('Disconnected from Streamer.bot WebSocket server');
288 res();
289 },
290 { signal },
291 );
292
293 if (this.socket.readyState !== this.socket.CLOSING) {
294 try {
295 this.socket?.close(code);
296 } catch (error) {
297 rej(error);
298 }
299 }
300 }),
301 {
302 timeout,
303 message: 'Timeout exceeded while closing connection',
304 controller,
305 signal: this._connectController.signal,
306 },
307 );
308 }
309
310 private async handshake(): Promise<void> {
311 if (!this.socket) throw new Error('WebSocket not initialized');
312
313 const controller = new AbortController();
314 const { signal } = controller;
315
316 this._connectController.signal.addEventListener('abort', () => controller.abort(), {
317 once: true,
318 signal,
319 });
320
321 const response = await withTimeout(

Callers 1

onOpenMethod · 0.95

Calls 4

authenticateMethod · 0.95
withTimeoutFunction · 0.90
debugMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected