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

Method on

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

* Helper method to handle custom event subscriptions * * This method allows you to subscribe to a specific event, source, or all events * and provides a listener callback that will be invoked when the event occurs. * * @param event - The event name to subscribe to. Can be a specific e

(
    event: TEvent extends StreamerbotEventName ? TEvent : StreamerbotEventName | '*',
    listener: (data: StreamerbotEventPayload<TEvent extends StreamerbotEventName ? TEvent : StreamerbotEventName>) => void
  )

Source from the content-addressed store, hash-verified

610
611 if (!id) id = generateId();
612
613 const controller = new AbortController();
614 const signal = controller.signal;
615
616 this._connectController.signal.addEventListener('abort', () => controller.abort(), {
617 once: true,
618 signal,
619 });
620
621 const response = await withTimeout(
622 new Promise<T>((res, rej) => {
623 if (!this.socket) return;
624
625 this.socket.addEventListener(
626 'message',
627 (event: any) => {
628 if (!('data' in event) || !event.data || typeof event.data !== 'string') {
629 this.logger?.debug('Unknown message received', event.data);
630 return;
631 }
632
633 try {
634 const payload = JSON.parse(event?.data);
635 if (payload?.id === id) {
636 this.logger?.verbose(`RECV :: ${request.request}`, payload);
637 return res(payload);
638 }
639 } catch (e) {

Callers 6

useGlobalVariableFunction · 0.80
onConnectFunction · 0.80
script.jsFile · 0.80
index.jsFile · 0.80

Calls 4

subscribeMethod · 0.95
debugMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected