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

Method request

packages/client/src/ws/StreamerbotClient.ts:534–599  ·  view source on GitHub ↗

* Make a request to the Streamer.bot WebSocket, * wait for the response, and return the response data

(
    request: StreamerbotRequest,
    id: string = '',
    timeout: number = 10_000
  )

Source from the content-addressed store, hash-verified

532 if (this.options.onData) this?.options?.onData(payload);
533 } catch (e) {
534 this.logger?.warn('Error occurred within user-provided onData callback', e);
535 }
536
537 // any listeners called from `.on`
538 if (payload?.event?.source && payload?.event?.type) {
539 for (const listener of this.listeners) {
540 if (!listener.events?.length) continue;
541 if (
542 !listener.events.find((event) => {
543 return (
544 event === '*' ||
545 event === `${payload?.event?.source}.${payload?.event?.type}` ||
546 (event.split('.', 2)?.[1] === '*' &&
547 event.split('.', 2)?.[0] === payload?.event?.source)
548 );
549 })
550 )
551 continue;
552
553 try {
554 listener.callback(payload);
555 } catch (e) {
556 this.logger?.warn(
557 `Error occurred within user-provided event callback (${listener.events})`,
558 e,
559 );
560 }
561 }
562 }
563 }
564
565 protected onError(event: Event): void {
566 this.logger?.debug('WebSocket onError', event);
567 if (!!this.socket && this.socket.readyState !== this.socket.OPEN) {
568 this._connectController.abort();
569 }
570 try {
571 this?.options?.onError?.(new Error('WebSocket Error'));
572 } catch (e) {
573 this.logger?.warn('Error occurred within user-provided onError callback', e);
574 }
575 }
576
577 protected cleanup(): void {
578 if (this.socket) {
579 this.socket.onopen = null;
580 this.socket.onclose = null;
581 this.socket.onerror = null;
582 this.socket.onmessage = null;
583 this.socket = undefined;
584 }
585 this.listeners = [];
586 this._retried = 0;
587 this._connectController.abort();
588 if (this._reconnectTimeout) clearTimeout(this._reconnectTimeout);
589 }
590
591 /**

Callers 2

authenticateMethod · 0.95
sendMessageMethod · 0.95

Calls 6

sendMethod · 0.95
generateIdFunction · 0.90
withTimeoutFunction · 0.90
debugMethod · 0.80
verboseMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected