Skip to main content

Run Participants and Collaboration in Unity

Build participant controls and shared room activities with com.mediasfu.unity@0.1.0-preview.2: participant media control, waiting and requests, removal and co-host assignment, chat, polls, breakouts, whiteboard, and recording.

Complete the Unity room lifecycle first. The current client has no backend-authorized handoff constructor, so this guide does not add account credentials to a Unity build or claim a secure direct create or join path.

Bind the Unity client to your scene controller

using System.Threading;
using System.Threading.Tasks;
using MediaSFU.Unity;

public sealed class RoomActivities
{
private readonly MediaSfuClient client;

public RoomActivities(MediaSfuClient client) => this.client = client;

public Task<MediaSfuOperationResult<bool>> AdmitAsync(
MediaSfuWaitingRoomParticipant person,
bool allow,
CancellationToken cancellationToken) =>
client.RespondToWaitingParticipantAsync(person, allow, cancellationToken);

public Task<MediaSfuOperationResult<bool>> SendMessageAsync(
string message,
CancellationToken cancellationToken) =>
client.SendChatMessageAsync(message, cancellationToken);

public Task<MediaSfuOperationResult<bool>> CreatePollAsync(
MediaSfuPollCreateRequest poll,
CancellationToken cancellationToken) =>
client.CreatePollAsync(poll, cancellationToken);
}

Keep one MediaSfuClient per active room scene. Read participants, pending requests, waiting people, polls, breakout state, whiteboard state, and recording state from CurrentRoom. Subscribe once to RoomChanged, ParticipantJoined, ParticipantLeft, MessageReceived, and ErrorOccurred, then unsubscribe when the scene closes.

Participant authority

Remove and ban are different actions

RemoveParticipantAsync disconnects a participant from the active room. The Unity package does not currently publish the separate outbound ban: true operation exposed by some other MediaSFU clients. If your application offers Ban from room, send that decision through an authorized server integration that sets MediaSFU's room ban state; do not relabel RemoveParticipantAsync.

Bind the MediaSFU username to a stable and unique authenticated account. If a person can choose a different name on every join, a username-based ban can be evaded.

  • ControlParticipantMediaAsync controls a participant's allowed media action.
  • RespondToRoomRequestAsync approves or denies a current room request.
  • RespondToWaitingParticipantAsync admits or rejects a waiting person.
  • RemoveParticipantAsync removes a current participant.
  • UpdateCoHostAsync assigns a co-host and responsibilities.

Only enable these controls for the current role. Confirm success from CurrentRoom or a room event; a changed Unity GameObject is not server proof. Ask for confirmation before removal or a broad media restriction. UpdateCoHostAsync is not a user-defined role-and-permission system; the package does not publish arbitrary permission assignment.

Chat and polls

Use SendChatMessageAsync for chat. Keep a sending state, show bounded errors, and display success after MessageReceived or current room state confirms it.

Use CreatePollAsync, VotePollAsync, and EndPollAsync for a complete poll. Disable repeated button presses while awaiting a result. After reconnect, load CurrentRoom.Polls and CurrentRoom.ActivePoll; do not repeat an interrupted action.

Breakouts and whiteboard

Pass reviewed assignments to StartOrUpdateBreakoutRoomsAsync, observe CurrentRoom.Breakout, and use StopBreakoutRoomsAsync before clearing scene drafts. Handle unassigned participants explicitly. Navigate a player only after the observed room state confirms their destination; stop the breakout before returning people to the main-room scene.

Use StartOrUpdateWhiteboardAsync to start the shared session, SendWhiteboardActionAsync or UpdateWhiteboardShapesAsync for changes, and StopWhiteboardAsync to finish. Confirm a second client receives the shapes. A local Unity drawing alone is not a shared whiteboard.

This is the package's shared annotation path. It does not publish a separate screen-annotation or canvas-capture API, so keep any local overlay clearly separate from the shared whiteboard.

Recording

Explain what will be captured and collect the consent your product requires. Use StartRecordingAsync, PauseRecordingAsync, ResumeRecordingAsync, and StopRecordingAsync. Show state from CurrentRoom.Recording, not only from a button press. Apply your backend's retention, access, export, and deletion policy.

Reconnect and cleanup

Disable authority and collaboration controls while disconnected. On reconnect, reload CurrentRoom before enabling them and never replay an interrupted action automatically.

On leave, removal, or meeting end, cancel pending tasks, unsubscribe scene events, stop app-owned media, clear selections and drafts, release temporary whiteboard assets, and close room UI. Keep leave, removal, and host-ended meeting states distinct.

Release checklist

  • Test host, co-host, and participant scenes separately.
  • Admit, reject, approve, deny, control media, remove, and assign co-host.
  • Send chat and confirm the receiving client event.
  • Create, vote, and end a poll without duplicate actions.
  • Start and stop breakouts; confirm all destinations.
  • Start, update, clear, and stop a whiteboard with two clients.
  • Start, pause, resume, and stop recording with consent visible.
  • Disconnect during pending actions and confirm none are replayed.
  • Verify tasks, events, media, assets, UI, and authority clear after exit.

Compile and test your application, then run this checklist in the Unity Editor and on each release platform.