edgeport - v1.0.3
    Preparing search index...

    Function connectWebSocket

    • Connects to an MQTT broker over WebSocket (subprotocol mqtt) and returns a live session.

      Opens the WebSocket with the mqtt subprotocol, wraps it in a binary-frame packet transport, and runs the same CONNECT/CONNACK handshake and read pump as the TCP path. The WS carries the identical MQTT control packets as binary frames. Use this for brokers fronted by a WebSocket listener, or set transport: 'ws' with a url on connect.

      Parameters

      • url: string

        The ws:// or wss:// broker endpoint.

      • opts: Omit<MqttConnectOptions, "hostname" | "transport" | "url"> = {}

        Connection and credential options (the hostname field is unused here).

      Returns Promise<MqttSession>

      The live session.

      If the broker rejects the credentials.

      If the WebSocket upgrade fails.

      If the broker speaks the protocol incorrectly.

      1.0.0

      import { connectWebSocket } from 'edgeport/mqtt';

      await using mqtt = await connectWebSocket('wss://broker.example.com/mqtt', { hostname: 'broker' });
      await mqtt.publish('a/b', 'hello');