peerix - v0.6.0
    Preparing search index...

    Class MqttDriver

    MQTT-based signaling driver.

    This driver uses MQTT as the underlying messaging system, allowing signaling messages to be exchanged through an MQTT broker such as Mosquitto.

    For testing, you can use the public server at wss://broker.emqx.io:8084/mqtt.

    This driver requires the mqtt module in the browser.

    import { connect } from "mqtt";

    // connect to an MQTT server (e.g., the local server)
    const client = connect("ws://localhost:9001/mqtt");

    // create a new driver instance
    const driver = new MqttDriver({ client });

    Running a local MQTT broker with WebSocket support for testing:

    cat << EOF > /tmp/mosquitto.conf
    listener 9001
    protocol websockets
    allow_anonymous true
    EOF

    docker run --rm -p 1883:1883 -p 9001:9001 \
    -v /tmp/mosquitto.conf:/mosquitto.conf \
    eclipse-mosquitto:latest \
    mosquitto -c /mosquitto.conf

    Hierarchy (View Summary)

    Index
    • Creates a new instance of the driver.

      Parameters

      • options: { client: MqttClient; prefix?: string }

        Optional configuration for the driver.

        • client: MqttClient

          The MQTT client instance.

        • Optionalprefix?: string

          Optional prefix for MQTT topics.

      Returns MqttDriver

    • 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

    • Publishes a signaling message to the specified namespace.

      Parameters

      • namespace: string

        The namespace to publish the message to.

      • data: number[]

        The message data to publish.

      Returns Promise<void>

      Nothing directly; resolves once the message is delivered (async drivers may return a promise).

    • Subscribes to signaling messages for the specified namespace.

      Parameters

      • namespace: string

        The namespace to subscribe to.

      • handler: (data: number[]) => void

        The handler function to call when a message is received.

      Returns Promise<void>

      Nothing directly; resolves once the subscription is established (async drivers may return a promise).

    • Unsubscribes from signaling messages for the specified namespace.

      Parameters

      • namespace: string

        The namespace to unsubscribe from.

      • handler: (data: number[]) => void

        The handler function to remove.

      Returns Promise<void>

      Nothing directly; resolves once the unsubscription is confirmed (async drivers may return a promise).