Skip to main content

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:

  1. Choose Add package from git URL or Add package from disk for com.mediasfu.mediasoup-client-unity.
  2. Add com.mediasfu.unity after the media client package is installed.
  3. 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​

ModeSetUse it for
MediaSFU Open (self-hosted)ConnectionMode = MediaSfuConnectionMode.CommunityEdition and LocalLink set to your serverBuilds you distribute: no MediaSFU account credentials are needed in the client
MediaSFU CloudConnectionMode = MediaSfuConnectionMode.Cloud (the default) and CredentialsIsolated 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:

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.

More for Unity​