RoomClient: voice property
Available since
@irtio/client 5.0BrowsersNodeThe voice read-only property of the RoomClient interface is what the client needs to join the project’s voice server: the server’s URL and the connection’s token.
Value
An object with these properties, or undefined when the project doesn’t use voice:
url- A string: the voice server’s URL.
token- A string: the token that admits this connection to the voice server.
It’s also undefined after each reconnect, until the router grants voice again.
Description
The router grants voice to each connection of a project that uses it, and the voice event fires when it does. joinVoice(), from @irtio/client/voice, uses it to join the voice server, so a game rarely reads it itself.
Examples
Showing the voice button once voice is granted
A game shows its voice button only while the room grants the player voice, checking again on each grant and reconnect.
// voice-button.ts
import type { RoomClient } from "@irtio/client";
export function voiceButton(room: RoomClient, button: HTMLButtonElement): void {
const show = () => {
button.hidden = room.voice === undefined;
};
room.addEventListener("voice", show);
room.addEventListener("open", show);
show();
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
voice | 5.0 | 5.0 |