Skip to content

Room and eventsRoom

Chat

Talk to players as the host, and send styled announcements.

All chat is literal text. HTML, CSS and markup are shown as typed, and player messages can't look like announcements. Each player's own display settings, such as chat position and sounds, stay under their control.

sendChat()

method
room.sendChat(text: string, targetId?: number | null): Promise<void>

Sends a chat message as the host player. It requires a host player: with noPlayer: true it rejects with sendChat requires a host player; use sendAnnouncement. A targeted message goes to that player's chat log only; a message to an unknown or departed player is dropped. Your own messages do not trigger onPlayerChat.

Parameters

textstringrequired
Up to 200 characters. Whitespace-only text is dropped.
targetIdnumber | null
A player ID to send only to that player, or null to send to everyone.

Returns

Promise<void>

JavaScript
await room.sendChat('Good game, everyone!');
await room.sendChat(
  'You are next in goal.',
  player.id,
);

sendAnnouncement()

method
room.sendAnnouncement(text: string, targetId?: number | null, color?: number | null, style?: AnnouncementStyle | null, sound?: number | null): Promise<void>

Literal text, up to 1,000 characters. RGB color 0x000000–0xffffff; null target broadcasts. Sound 0/1/2 is subject to recipient preferences.

Posts a host notice that stands apart from player chat. Works in rooms without a host player.

Parameters

textstringrequired
Up to 1,000 characters.
targetIdnumber | null
A player ID, or null to announce to everyone.
colornumber | null
Text color as an RGB integer from 0x000000 to 0xffffff, or null for the reader’s default. Pick colors that read well on a dark chat.
styleAnnouncementStyle | null
One of normal, bold, italic, small, small-bold or small-italic. Defaults to normal.
soundnumber | null
0 silent, 1 normal or 2 alert. Defaults to 1. Each reader’s sound settings still apply.

Returns

Promise<void>

JavaScript
await room.sendAnnouncement(
  'Welcome to the room',
  null,
  0xb9e8d0,
  'bold',
  0,
);
await room.sendAnnouncement(
  'Your request was accepted',
  player.id,
  0xefc88e,
  'small',
  1,
);