MediaSFU Unity
Add MediaSFU voice and video rooms to Unity apps, games, training tools, and
simulations with com.mediasfu.unity@0.1.0-preview.2. MediaSfuClient runs
the room: create and join, room state, participant events, microphone, camera,
and screen share, remote media, chat, polls, breakouts, whiteboard, recording
controls, co-host updates, participant leave, and host end. Your scene owns the
interface and how media is presented.
For an isolated local prototype, use only a restricted, revocable development
credential and never commit it. Reusable Cloud credentials must not ship in
scenes, prefabs, ScriptableObject assets, player preferences, environment
files, or C# source; see the secure backend guide
and Choose your backend mode before you share a
build.
Install
In Unity Package Manager:
- Choose Add package from git URL or Add package from disk for
com.mediasfu.mediasoup-client-unity. - Add
com.mediasfu.unityafter the media client package is installed. - Confirm your target platform includes a supported native WebRTC/mediasoup plugin.
When installing from local package folders during development, select each package's package.json.
com.mediasfu.mediasoup-client-unity supplies capture, encoding, decoding,
playback, and rendering. com.mediasfu.unity handles signaling, room state,
moderation, and media orchestration on top of it.
Copy/paste starter
This starter joins a room on a self-hosted MediaSFU Open server and connects media. Replace the server address, meeting ID, and display name with values from your app.
using MediaSFU.Unity;
var client = new MediaSfuClient(
new MediaSfuClientOptions
{
ConnectionMode = MediaSfuConnectionMode.CommunityEdition,
LocalLink = "https://your-mediasfu-server.example",
}
);
var join = await client.JoinRoomAsync(
new MediaSfuJoinRoomRequest
{
MeetingId = "s12345678",
UserName = "player-one",
IsLevel = "0"
}
);
if (!join.Success)
{
UnityEngine.Debug.LogError(join.Detail);
return;
}
var connect = await client.ConnectMediaAsync();
if (!connect.Success)
{
UnityEngine.Debug.LogError(connect.Detail);
}
Attach real media
Attach the media device before enabling microphone, camera, screen share, or remote playback:
var deviceResult = MediaSfuNativePluginWebRtcEngine.TryCreateWebRtcDevice(
new MediaSfuNativePluginWebRtcEngineOptions
{
EnableVerboseLogging = true
});
if (!deviceResult.Success)
{
UnityEngine.Debug.LogError(deviceResult.Detail);
return;
}
client.AttachWebRtcDevice(deviceResult.Value);
Codec support comes from the attached native WebRTC backend, not from managed C# alone.
Choose your backend mode
| Mode | Set | Use it for |
|---|---|---|
| MediaSFU Open (self-hosted) | ConnectionMode = MediaSfuConnectionMode.CommunityEdition and LocalLink set to your server | Builds you distribute: no MediaSFU account credentials are needed in the client |
| MediaSFU Cloud | ConnectionMode = MediaSfuConnectionMode.Cloud (the default) and Credentials | Isolated local development with a restricted, revocable key |
In this preview, Cloud mode sends the configured API username and key from the client, and the package has no way to accept a room result from your backend instead. Use Cloud mode only for local development, and never ship a build that contains those credentials.
What you build in the scene
There is no web-style uiOverrides map: you build the interface with Unity UI,
UI Toolkit, or your scene system and bind it to MediaSfuClient state and
events. Continue with:
- Unity room operations for room state, media, screen sharing, leave, and host end;
- Unity participants and collaboration for waiting rooms, moderation, chat, polls, breakouts, whiteboard, and recording.
Before you ship
Test room join, audio, camera video, screen share, and remote playback on the exact Unity builds and devices you distribute; Editor tests do not cover native capture or playback. Keep demo values out of published scenes and packages.