RoomMessageEvent: unreliable property

Available since @irtio/client 5.0BrowsersNode

The unreliable read-only property of the RoomMessageEvent interface says whether the room sent the message unreliably.

Value

A boolean. true when the room sent the message with unreliable: true, as a WebTransport datagram or over WebSocket with stale ones dropped. false for a reliable message.

Description

Reliable messages arrive in the order the room sent them. An unreliable message can be lost or overtaken, so treat each as the latest value of something, such as a position, rather than as an event the game must not miss.

The client holds reliable messages that arrive before the first message listener, but drops unreliable ones.

Examples

Ignoring a stale position

A room sends positions unreliably with a sequence number. The client skips any that arrive after a newer one.

// latest-position.ts
import { connect } from "@irtio/client";

const room = await connect("https://rooms.irt.io/my-game/arena");
let latest = 0;

room.addEventListener("message", (event) => {
  if (!event.unreliable) return;
  // This room sends only positions unreliably; check the shape if yours sends more
  const position = event.data as { seq: number; x: number; y: number };
  if (position.seq <= latest) return;
  latest = position.seq;
  console.log(`ball at ${position.x}, ${position.y}`);
});

See also

Runtime availability

BrowsersNode
unreliable5.05.0