RoomClient: connection property

Available since @irtio/client 5.0BrowsersNode

The connection read-only property of the RoomClient interface is the ID of the client’s current connection to the room.

Value

A number, the connection’s id in the room. It’s 0 until the router accepts the first connection.

Description

The ID belongs to the connection, not to the player. After a reconnect, and when a sleeping room wakes, the client has a new connection with a new ID. To name the player across connections, use player.

Examples

Tagging log lines with the connection

When the room logs connection IDs, a client that tags its own logs the same way can be matched with them.

// log.ts
import type { RoomClient } from "@irtio/client";

export function log(room: RoomClient, line: string): void {
  console.log(`[${room.id}#${room.connection}] ${line}`);
}

See also

Runtime availability

BrowsersNode
connection5.05.0