peerix - v0.1.0
    Preparing search index...

    Class NatsDriver

    NATS-based signaling driver for inter-process communication.

    This driver uses NATS as the underlying messaging system, allowing for distributed signaling across multiple browsers and devices.

    This driver requires the nats.ws library for WebSocket-based NATS connections directly in the browser.

    import { connect } from 'https://esm.sh/nats.ws';

    // connect to a NATS server (e.g. the public demo server)
    const nc = await connect({ servers: ['wss://demo.nats.io:8443'] });

    // create a new driver instance and start it
    const driver = new NatsDriver({ nc, prefix: 'peerix' });
    driver.start();

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new instance of the driver.

      Parameters

      • options: { nc: any; prefix?: string }

        Configuration options for the driver.

        • nc: any

          A NATS connection instance.

        • Optionalprefix?: string

          An optional prefix for NATS subjects.

      Returns NatsDriver

    Accessors

    • get active(): boolean

      Indicates whether the driver is currently active.

      Returns boolean

    • set active(value: boolean): void

      Sets the active state of the driver and emits corresponding events.

      Parameters

      • value: boolean

      Returns void

    Methods

    • Dispatches a signaling message to the specified namespace.

      Parameters

      • namespace: string[]

        The namespace to dispatch the message to.

      • message: Uint8Array

        The message to dispatch.

      Returns Promise<void>

    • Starts the driver and begins tracking NATS connection status.

      Returns Promise<void>

    • Subscribes to signaling messages for the specified namespace.

      Parameters

      • namespace: string[]

        The namespace to subscribe to.

      • handler: (message: Uint8Array) => void

        The handler function to call when a message is received.

      Returns Promise<void>

    • Unsubscribes from signaling messages for the specified namespace.

      Parameters

      • namespace: string[]

        The namespace to unsubscribe from.

      • handler: (message: Uint8Array) => void

        The handler function to remove.

      Returns Promise<void>