MqttX.Transport.WebSocket (MqttX v0.13.0)

Copy Markdown View Source

WebSocket transport adapter for MqttX.

This adapter uses Bandit + WebSockAdapter to serve MQTT over WebSocket (RFC 6455).

Usage

# ws://
MqttX.Server.start_link(MyHandler, handler_opts,
  transport: MqttX.Transport.WebSocket,
  port: 8083
)

# wss://
MqttX.Server.start_link(MyHandler, handler_opts,
  transport: MqttX.Transport.WebSocket,
  port: 8084,
  scheme: :https,
  transport_options: [certfile: "/etc/mqttx/cert.pem", keyfile: "/etc/mqttx/key.pem"]
)

Options

  • :port - Port to listen on (default: 8083)
  • :ip - IP address to bind to (default: {0, 0, 0, 0})
  • :path - WebSocket path (default: /mqtt)
  • :scheme - :http for ws:// (default) or :https for wss://
  • :transport_options - Socket options for Bandit's listener. With scheme: :https this is where the TLS configuration goes — at least :certfile and :keyfile; any :ssl server option is accepted — the same shape MqttX.Transport.ThousandIsland takes for transport_module: ThousandIsland.Transports.SSL
  • :read_timeout - Socket read timeout of the listener, in ms (default: :infinity; the MQTT Keep Alive and :max_idle_timeout close idle connections)
  • :max_frame_size - Largest WebSocket frame accepted, in bytes (default: the packet cap plus the 14-byte frame header)
  • :check_origin - Origins a browser may connect from, as a list of "scheme://host[:port]"; any other Origin is refused with 403. A request without an Origin header passes (default: false, no check)

All protocol-level options (:max_packet_size, :max_idle_timeout, :rate_limit, …) behave as documented in MqttX.Transport.ThousandIsland.