peerix - v0.8.0
    Preparing search index...

    Class Addon<T>

    Base class for Peerix addons.

    Pass an event map to type the addon's events:

    class Presence extends Addon<{ online: [id: string] }> {}
    const presence = new Presence();
    presence.on("online", (id) => console.log(id));

    Type Parameters

    • T extends { [K in keyof T]: any[] } = Record<string, any[]>

      Map of event names to their handler arguments.

    Index
    • Creates a new Addon instance.

      Type Parameters

      • T extends { [K in string | number | symbol]: any[] } = Record<string, any[]>

        Map of event names to their handler arguments.

      Returns Addon<T>

    • Attaches the addon to a Room instance. This method is called when the addon is added using room.attach(addon).

      Parameters

      • room: Room<any>

        The Room instance to attach to.

      Returns Promise<void>

    • Detaches the addon from a Room instance. This method is called when the addon is removed using room.detach(addon).

      Parameters

      • room: Room<any>

        The Room instance to detach from.

      Returns Promise<void>

    • Emits an event from the addon.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K

        Event name.

      • ...args: T[K]

        Arguments to pass to the event handlers.

      Returns void

    • Unsubscribes from an event emitted by the addon.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K

        Event name.

      • Optionalhandler: (...args: T[K]) => void

        Optional event handler to remove, with every subscription it was registered with. If not provided, all handlers for the event will be removed.

      Returns void

    • Subscribes to an event emitted by the addon.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K

        Event name.

      • handler: (...args: T[K]) => void

        Event handler.

      • Optionaloptions: ListenerOptions

        Listener options, such as an AbortSignal that removes the handler.

      Returns () => void

      A function that removes the handler.

    • Subscribes to an event emitted by the addon for a single invocation.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K

        Event name.

      • handler: (...args: T[K]) => void

        Event handler.

      • Optionaloptions: ListenerOptions

        Listener options, such as an AbortSignal that removes the handler.

      Returns () => void

      A function that removes the handler.