RoomClient: transportKind property

Available since @irtio/client 5.0BrowsersNode

The transportKind read-only property of the RoomClient interface says what carries the client’s current connection.

Value

"webtransport", "websocket" or undefined. It’s undefined until the first connection is dialled, and when a custom dial returns a transport that doesn’t say its kind.

Description

The client dials WebTransport at the room’s URL first. When the platform has no WebTransport, as Node doesn’t, or it doesn’t connect within 3 seconds, the client uses WebSocket, and stays on WebSocket for later reconnects. Over WebTransport, unreliable messages go as datagrams; over WebSocket they go in order with the reliable ones.

A custom dial, passed to connect() in a DevConnectInit, sets it from its transport’s kind. A dial that wraps dialWebSocket() keeps the inner transport’s.

Examples

Reporting the transport with a bug report

A bug report includes the room, the transport the client connected over and the connection’s timing.

// bug-report.ts
import type { RoomClient } from "@irtio/client";

export function connectionReport(room: RoomClient): string {
  return [
    `room ${room.id}, protocol ${room.protocol}`,
    `transport ${room.transportKind ?? "custom"}`,
    `rtt ${Math.round(room.rtt)} ms, jitter ${Math.round(room.jitter)} ms`,
  ].join("\n");
}

See also

Runtime availability

BrowsersNode
transportKind5.05.0