Room: send() method
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe 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
Uint8Arrayis sent as a binary message, and anything else as JSON. optionsOptional-
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 tofalse.
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
Room.broadcast()- Calls, for a message that needs a reply
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
send() | 0.1 | 0.1 | 0.1 | 0.1 |