Skip to content

Participants

Updated

Participants tells a script who is attending the experience: each person’s name, whether it is you, whether their hand is raised and whether they are speaking. Use it for a roster panel, a “3 people here” counter, a speaker highlight or a raise-hand button. It reads attendance only; it does not depend on which scenes people have loaded, on avatars or on media streams.

  • You know what a room is. See the Multiplayer overview.
  • You can show text in a UI Label. See UI.
  • The difference with Network.peers: Network lists the peers sharing objects in the room; Participants describes the people attending, with their names and status.
Member What it does
Participants.getSnapshot() The current snapshot: an unchanging picture of the roster at this moment.
Participants.subscribe(listener) Call listener(snapshot) right away and again each time the roster changes. Returns a function that stops it; it also stops when the script is released.
Participants.setLocalHandRaised(raised) Raise (true) or lower (false) your own hand. Resolves { status }.

A snapshot never changes after you get it: to see changes, read a new one or subscribe.

Field What it is
participants The people attending, as a list of participants.
count How many participants there are.
completeness 'complete' when the roster is known to be the full list, 'partial' when it may be missing people.
raisedHandCount How many hands are raised, when every hand is known; undefined otherwise.
localHandRaised Whether your own hand is shown raised.
revision A number that grows with each new snapshot.

Completeness, plainly. The roster is 'complete' while this peer is connected to the room and knows everyone in it. It becomes 'partial' when the connection is lost or not yet made: the list is then emptied or out of date. Show the count as exact only when the roster is complete.

Field What it is
id A unique id for this attendance. Each browser tab is its own participant, even for the same account.
displayName The person’s name, when known. Names are for display, not identification: two people may share one.
isLocal Whether this participant is you.
handRaised Whether their hand is raised; undefined when unknown.
speaking Whether they are speaking now; undefined when their voice connection is unknown.
role 'host' or 'guest', when the room gives roles.
profile Extra profile data, such as profile.thumbnail, a picture URL, when there is one.
world.state Their membership of the room: 'connected', 'absent' or 'unknown'.
media.state Their voice and video connection: 'connected', 'absent' or 'unknown'.

A person who leaves the room leaves the roster, even if their voice connection lingers.

setLocalHandRaised(raised) changes your own hand only. It resolves an object whose status is:

Status Meaning
'confirmed' The room confirmed the change, or, while not connected, the change was made locally.
'unavailable' The room does not support raised hands.
'busy' Another change is still in progress.
'failed' The change did not go through.

While connected, the room confirms the flag and every participant sees it through handRaised. While disconnected, the change is local and only affects localHandRaised; it is not sent later. It works in play only.

PeopleCount.jx
#pragma lifecycle(startup)
function startup() {
const count = findEntity('Count').getComponent(UILabelComponent);
const first = Participants.getSnapshot();
log(`${first.count} people when the script started`);
Participants.subscribe((snapshot) => {
const approx = snapshot.completeness === 'complete' ? '' : ' (updating)';
count.setProps({ text: `${snapshot.count} here${approx}` });
});
}
  • getSnapshot reads the roster once, at this moment.
  • subscribe calls the listener at once, so the label is filled immediately and then kept up to date.
  • When the roster is partial, the text says so rather than showing a wrong number as fact.
Roster.jx
#pragma lifecycle(startup)
// Scene: a "Roster" UI Label with maxWidth set, inside a UI Panel.
let roster;
function line(person) {
const marks = [];
if (person.isLocal) marks.push('you');
if (person.role === 'host') marks.push('host');
if (person.handRaised) marks.push('✋');
if (person.speaking) marks.push('speaking');
const name = person.displayName ?? 'Guest';
return marks.length ? `${name} (${marks.join(', ')})` : name;
}
function startup() {
roster = findEntity('Roster').getComponent(UILabelComponent);
Participants.subscribe((snapshot) => {
const lines = snapshot.participants
.filter((person) => person.world.state === 'connected')
.map(line);
const hands = snapshot.raisedHandCount !== undefined ? `, ${snapshot.raisedHandCount} hands up` : '';
roster.setProps({ text: `${snapshot.count} people${hands}\n${lines.join('\n')}` });
});
}
  • Each line is built from the participant’s fields; displayName can be missing, so a fallback is used.
  • raisedHandCount is shown only when it is known.
  • Because speaking changes are part of the snapshot, the roster also highlights who is talking.
RaiseHand.jx
#pragma lifecycle(startup)
// Scene: a "Hand" UI Toggle Button with a Signal Emitter on 'hand/toggle'.
let toggle;
let busy = false;
let syncing = false;
// Show a state on the button without treating it as a press.
function showRaised(raised) {
if (toggle.isChecked() === raised) return;
syncing = true;
toggle.setChecked(raised);
syncing = false;
}
function startup() {
toggle = findEntity('Hand').getComponent(UIToggleButtonComponent);
// Keep the button in step with the confirmed state, also when a host lowers our hand.
Participants.subscribe((snapshot) => {
if (!busy) showRaised(snapshot.localHandRaised === true);
});
on('hand/toggle', async (event) => {
if (event.eventType !== EventType.UIToggleButton.Change || busy || syncing) return;
busy = true;
const result = await Participants.setLocalHandRaised(event.data.checked);
busy = false;
if (result.status !== 'confirmed') {
log('Hand change not applied:', result.status);
showRaised(Participants.getSnapshot().localHandRaised === true);
}
});
}
  • The toggle asks for the change; the subscription keeps it matching what the room confirmed.
  • setChecked sends its own change event. The syncing flag marks those, so showing a state never sends a new request.
  • busy keeps the subscription from flipping the button back while a request is in flight.
  • If the room refuses, the button returns to the confirmed state.
  • Using names as ids. Two people can share a name, and one person can attend twice. Use id to tell participants apart.
  • Trusting count while partial. Check completeness first.
  • Keeping an old snapshot. A snapshot is a picture of one moment; subscribe to stay current.
  • Treating undefined as false. handRaised and speaking are undefined when unknown; test with === true when that matters.