Interface EventSubscriber

interface EventSubscriber {
    off<E>(type: E, listener: ((data: EventOfType<E>) => void)): EventSubscriber;
    on<E>(type: E, listener: ((data: EventOfType<E>) => void)): EventSubscriber;
}

Hierarchy (view full)

Methods

Methods

  • Removes the specified listener function from the list of functions to call when the given event is observed.

    Type Parameters

    • E extends
          | "unknown"
          | "connect"
          | "disconnect"
          | "close"
          | "end"
          | "accept"
          | "accept:error"
          | "bind"
          | "bind:error"
          | "connect:delay"
          | "connect:retry"
          | "close:error"
          | "handshake"
          | "handshake:error:protocol"
          | "handshake:error:auth"
          | "handshake:error:other"

    Parameters

    • type: E

      The type of event that the listener was listening for.

    • listener: ((data: EventOfType<E>) => void)

      The previously registered listener function.

    Returns EventSubscriber

  • Adds a listener function which will be invoked when the given event type is observed. Calling this method will convert the Observer to event emitter mode, which will make it impossible to call Observer.receive() at the same time.

    socket.events.on("bind", event => {
    console.log(`Socket bound to ${event.address}`)
    // ...
    })

    Type Parameters

    • E extends
          | "unknown"
          | "connect"
          | "disconnect"
          | "close"
          | "end"
          | "accept"
          | "accept:error"
          | "bind"
          | "bind:error"
          | "connect:delay"
          | "connect:retry"
          | "close:error"
          | "handshake"
          | "handshake:error:protocol"
          | "handshake:error:auth"
          | "handshake:error:other"

    Parameters

    • type: E

      The type of event to listen for.

    • listener: ((data: EventOfType<E>) => void)

      The listener function that will be called with all event data when the event is observed.

    Returns EventSubscriber