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

Method onClose

packages/client/src/ws/StreamerbotClient.ts:409–447  ·  view source on GitHub ↗
(event: CloseEvent)

Source from the content-addressed store, hash-verified

407 throw new Error('Authentication failed');
408 }
409 }
410
411 protected async onOpen(): Promise<void> {
412 this._retried = 0;
413 if (this._reconnectTimeout) clearTimeout(this._reconnectTimeout);
414
415 try {
416 // Force a getInfo call for backwards compat with Streamer.bot v0.2.4 and older
417 if (!this._authEnabled) {
418 void this.getInfo().catch(() =>
419 this.logger?.debug('Failed to fetch Streamer.bot instance info'),
420 );
421 }
422 await this.handshake();
423
424 if (this.version && this.info) {
425 this.logger?.debug(`Connected to Streamer.bot: v${this.version} (${this.info.name})`);
426 await this.updateSupportedEvents();
427 this?.options?.onConnect?.(this.info);
428 }
429 } catch (err) {
430 this.logger?.warn('Failed handshake with Streamer.bot', err);
431 this.options?.onError?.(
432 err instanceof Error ? err : new Error('Failed handshake with Streamer.bot'),
433 );
434 return await this.disconnect();
435 }
436
437 try {
438 // Subscribe to initial subscriptions requested in client options
439 if (
440 this.options.subscribe === '*' ||
441 (typeof this.options.subscribe === 'object' &&
442 !Array.isArray(this.options.subscribe) &&
443 Object.keys(this.options.subscribe ?? {}).length)
444 ) {
445 this.logger?.debug('Subscribing to initial events from options:', this.options.subscribe);
446 await this.subscribe(this.options.subscribe);
447 } else if (
448 typeof this.options.subscribe === 'string' ||
449 Array.isArray(this.options.subscribe)
450 ) {

Callers

nothing calls this directly

Calls 6

cleanupMethod · 0.95
connectMethod · 0.95
getCloseEventReasonFunction · 0.90
onErrorMethod · 0.80
warnMethod · 0.80
debugMethod · 0.80

Tested by

no test coverage detected