Skip to content

Commands

Updated

Every action a person takes in a room is a command: sending a reaction, raising a hand, locking the room, removing someone. A script runs a command with Network.command, and Arena checks it against the room’s rules before carrying it out: the rules decide who may run each command, so a guest cannot lock a room that only its host may lock. Some commands are relayed to the other peers, which react to them with Network.onCommand. Use commands to build moderation panels, reaction buttons and host tools.

  • You know what a room and a peer are. See the Multiplayer overview.
  • You know the session members of Network, such as Network.connected and Network.peers. See Network.
  • Commands return promises: call them from an async function and await them.
Member What it does
Network.command(name, args?, target?) Run the command name with args (an object), aimed at the peer target when the command acts on someone. Resolves the room’s result; rejects with an error that has a code when the room refuses.
Network.can(name) Whether the room’s rules let this peer run name now; false while not in a room.
Network.onCommand(name, handler) Call handler(args, from) for each command named name that another peer runs and that reaches this peer. from is that peer’s id. Returns a function that stops it; it also stops when the script is released.
  • Permissions change live. What a peer may do arrives when it joins and changes when the room’s rules or the peer’s roles change. Read can when you need it rather than once at startup.
  • can is a hint, not a guard. Arena checks every command again, so a refused command still rejects. Use can to show or hide buttons.
  • Commands the runtime sends itself. Registering, spawning, claiming and destroying objects are commands too. MIRA sends them for you when you replicate, spawn or take objects.

NetworkCommand names the commands, so you do not type strings. Each key is the command in PascalCase: NetworkCommand.RoomLock is 'room.lock', NetworkCommand.ParticipantHandRaise is 'participant.hand.raise', NetworkCommand.MediaStopScreen is 'media.stop-screen'.

Group Keys
Room RoomLock, RoomUnlock, RoomCapacitySet, RoomEnd, RoomReset, RoomPolicyRead, RoomPolicyUpdate, RoomHostClaim, RoomAnnounce, RoomFollowMe
Moderation ParticipantKick, ParticipantBan, ParticipantUnban, ParticipantHandLower, ParticipantHandLowerAll, ParticipantRename, ParticipantListIdentities, ParticipantRoleAssign, ParticipantRoleRevoke
Presence and social ParticipantHandRaise, ParticipantProfileRefresh, ParticipantsObserve, ChatAttend, ReactionSend, ParticipantSpotlight, ParticipantSummon, ParticipantTeleport
Media MediaMute, MediaUnmute, MediaMuteAll, MediaStopScreen
Objects ObjectRegister, ObjectSpawn, ObjectDestroy, ObjectDestroyAny, ObjectClaim, ObjectClaimLocked, ObjectRelease

A room can offer commands of its own beyond these; run them by name, such as Network.command('emoji.burst', { emoji: '🎉', count: 5 }).

Some commands reach the other peers, which hear them through onCommand: room.announce and reaction.send, for example. A few are requests for the receiving peer to carry out: media.mute, media.unmute, media.stop-screen, participant.summon, participant.teleport and room.follow-me. MIRA does not act on these by itself. If your scene should obey them, handle them with onCommand and do the work in your script.

A refused command rejects with an error whose code says why:

Code Meaning
400 Unknown command, or wrong arguments.
401 This peer is not in a room.
403 The room’s rules do not allow it, or the target ranks higher.
404 No such target.
409 A conflict, such as resetting a room while others are in it.
429 Sent too often.

Some mistakes throw a TypeError at once, before anything is sent: a missing name, args that are not an object, or an empty target. A handler passed to onCommand that throws is reported to its script, and the other handlers still run.

NetworkCommand.RoomReset empties the room: every object it holds or keeps. It runs only while the sender is alone in the room (409 otherwise), and rooms usually do not allow it. The peer that resets keeps its own objects and registers them again, so the scene it plays starts the room anew. MIRA never resets a room on its own.

ThumbsUp.jx
#pragma lifecycle(startup)
function startup() {
on('react/thumbs', async (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
if (!Network.connected) {
log('Reactions need a room');
return;
}
try {
await Network.command(NetworkCommand.ReactionSend, { reaction: '👍' });
} catch (error) {
if (error.code === 429) log('Slow down');
else log('Reaction refused:', error.code);
}
});
Network.onCommand(NetworkCommand.ReactionSend, (args, from) => {
log(`${from} reacted ${args.reaction}`);
});
}
  • command resolves when the room accepts the reaction and rejects with a code when it does not.
  • onCommand hears the reactions other peers send, with the sender’s peer id in from.

1. A host panel that only shows what you may do

Section titled “1. A host panel that only shows what you may do”
HostPanel.jx
#pragma lifecycle(startup)
// Scene: a "Host Panel" UI Panel holding a "Lock" UI Toggle Button with a
// Signal Emitter on 'host/lock', and a "Lower Hands" UI Button with a Signal
// Emitter on 'host/hands'. A Networkable has a Signal Emitter on 'net'.
let panel;
let lockButton;
let handsButton;
function refresh() {
lockButton.visible = Network.can(NetworkCommand.RoomLock);
handsButton.visible = Network.can(NetworkCommand.ParticipantHandLowerAll);
panel.visible = lockButton.visible || handsButton.visible;
}
function startup() {
panel = findEntity('Host Panel');
lockButton = findEntity('Lock');
handsButton = findEntity('Lower Hands');
refresh();
on('net', (event) => {
if (event.eventType === EventType.Networkable.Connect) refresh();
});
on('host/lock', async (event) => {
if (event.eventType !== EventType.UIToggleButton.Change) return;
const name = event.data.checked ? NetworkCommand.RoomLock : NetworkCommand.RoomUnlock;
try {
await Network.command(name);
log(event.data.checked ? 'Room locked' : 'Room unlocked');
} catch (error) {
if (error.code === 403) log('Not allowed');
}
});
on('host/hands', async (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
await Network.command(NetworkCommand.ParticipantHandLowerAll);
});
}
  • can decides which buttons are visible; permissions arrive with the join, so the panel is refreshed on connect too.
  • The toggle button runs RoomLock or RoomUnlock depending on its new state.
  • Arena checks each command again, so the 403 branch still matters.
RoomRequests.jx
#pragma lifecycle(startup)
// Scene: an "XR Origin" or player root entity named "Player", and a "Banner"
// UI Label that shows announcements.
let player;
let banner;
function startup() {
player = findEntity('Player');
banner = findEntity('Banner').getComponent(UILabelComponent);
Network.onCommand(NetworkCommand.RoomAnnounce, (args, from) => {
banner.setProps({ text: `${args.message}` });
log('Announcement from', from);
});
// MIRA does not move the player by itself: this script decides what a summon does.
Network.onCommand(NetworkCommand.ParticipantSummon, (args, from) => {
log(`${from} summoned me`);
player.setPosition(0, 0, 2);
});
}
  • Relayed commands arrive through onCommand only; the runtime leaves the reaction to your script.
  • What a summon does is your choice here: the player is moved to a gathering point.
Moderator.jx
#pragma lifecycle(startup)
// Scene: a UI Button with a Signal Emitter on 'mod/kick-latest'.
async function kick(peerId) {
try {
await Network.command(NetworkCommand.ParticipantKick, {}, peerId);
log(`Removed ${peerId}`);
} catch (error) {
if (error.code === 403) log('You cannot remove this person');
else if (error.code === 404) log('They already left');
else log('Kick failed:', error.code);
}
}
function startup() {
on('mod/kick-latest', (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
if (!Network.can(NetworkCommand.ParticipantKick)) return;
const newest = Network.peers[Network.peers.length - 1];
if (newest) kick(newest);
});
}
  • A command that acts on someone takes that peer’s id as the third argument.
  • Network.peers lists the other peers oldest first, so the last one is the newest arrival.
  • 404 means the target is gone; 403 that the rules forbid it or the target ranks higher.
  • Trusting can alone. It reflects the rules when you read it; the room may refuse anyway. Always handle a rejection.
  • Expecting the runtime to obey relayed requests. media.mute, participant.summon, participant.teleport and the like do nothing unless a script handles them.
  • Passing a string as args. args must be an object, even when empty: Network.command(name, {}, peerId).
  • Running commands while alone and offline. Outside a room every command rejects with 401. Check Network.connected first.