HandoffFailed
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe HandoffFailed class of the Room API is the error room.handoff() rejects with when the handoff couldn’t be made. Nobody moves. It extends Error.
Instance properties
HandoffFailed.reason- Why it failed, one of the reasons below. Read only.
HandoffFailed.players- For
limit, the player IDs of the people moved too often, so a retry can leave them out; empty otherwise. Read only. HandoffFailed.name"HandoffFailed".
Description
reason is one of:
players- None of the people was still connected.
limit- The project is at its room limit, a person in the handoff was handed off 6 times in the last minute, or people from one client address 30 times.
spending- The project is over its spending limit.
unavailable- The new room couldn’t be made, or the router didn’t answer within 15 seconds.
invalid- The request was refused; check the players and
to.type.
room.handoff() rejects with a plain Error instead, sending nothing, for a bot, a player who isn’t connected, or one whose client is too old.
Examples
Retrying without the people moved too often
// matchmaker.ts
import { defineRoom, HandoffFailed, isBot } from "@irtio/room";
export default defineRoom({
async onMessage(room, _connection, message) {
if (message !== "start") return;
const people = [...room.presence].filter((p) => p.connected && !isBot(p.player)).map((p) => p.player);
try {
await room.handoff({ players: people, to: { type: "match" } });
} catch (e) {
if (!(e instanceof HandoffFailed) || e.reason !== "limit" || e.players.length === 0) throw e;
const rest = people.filter((p) => !e.players.includes(p));
if (rest.length > 0) await room.handoff({ players: rest, to: { type: "match" } });
}
},
});
See also
- From your own room code, in the lobbies guide
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
HandoffFailed | 0.1 | 0.1 | 0.1 | 0.1 |