Room: send() method

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The send() method of the Room interface sends a message to one connection.

Syntax

send(connection, message)
send(connection, message, options)

Parameters

connection
The connection to send to.
message
The message to send. A Uint8Array is sent as a binary message, and anything else as JSON.
options Optional

An object with this property:

unreliable
A boolean. If true, the message is sent as a WebTransport datagram, or over WebSocket in order with stale ones dropped. Defaults to false.

Return value

None (undefined).

Exceptions

RangeError
Thrown if the message is larger than 64 KB.

Examples

Answering one player

// ping.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  onMessage(room, connection, message) {
    if (message === "ping") room.send(connection, "pong");
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
send()0.10.10.10.1