Unity SDK

com.applooma.rtc puts voice, video and messages inside a Unity game, on the same channels as every other AppLooma RTC SDK. Version 0.1.0 targets WebGL builds: the engine runs the Web SDK in the page, and video arrives in Unity as a Texture2D you can put on a RawImage or a material.

Beta, WebGL only

0.1.0 is a preview and has not been through a full Unity release cycle yet. In the Editor and on Android, iOS and desktop players every call logs that the platform is not supported yet, and JoinChannel throws AppRtcException. Native players are planned. Report problems to support@applooma.dev.

Install#

Unity 2021.3 or newer. Add the package from a git URL in the Package Manager, or to Packages/manifest.json:

Packages/manifest.json
{
"dependencies": {
"com.applooma.rtc": "https://github.com/AppLooma-RTC/Unity-SDK.git#0.1.0"
}
}

WebGL setup#

1

Switch to WebGL

File > Build Settings, platform WebGL.

2

Let the page load the Web SDK

Nothing to do by default: on the first call the plugin imports the Web SDK 0.4.6 from jsDelivr. To self-host it, set AppEngine.WebSdkUrl before AppEngine.Create, or use the package's WebGLTemplates~/AppLooma template (copy it toAssets/WebGLTemplates), which loads the SDK as window.AppLoomaRTC before the player starts.

3

Serve over HTTPS

Browsers only allow camera and microphone on secure pages (or localhost).

4

Join from a click

Browsers start audio only after a user gesture, so call JoinChannel from a button.

Quick start#

The token comes from your server, as in the Quickstart. Never mint tokens inside the game.

VoiceRoom.cs
using AppLooma.Rtc;
using UnityEngine;
public class VoiceRoom : MonoBehaviour
{
public AppVideoTexture remoteVideo; // on a RawImage
AppEngine engine;
void Start()
{
engine = AppEngine.Create("YOUR_APP_ID");
engine.UserJoined += u => Debug.Log(u.Uid + " joined");
engine.TrackSubscribed += u => { if (u.HasVideo) remoteVideo.Uid = u.Uid; };
engine.MessageReceived += m => Debug.Log(m.FromUid + ": " + m.Text);
}
public async void Join(string token, string wsUrl)
{
await engine.JoinChannel(token, wsUrl, new AppJoinOptions { Role = AppRole.Host, Camera = true, Microphone = true });
}
public async void ToggleMute() => await engine.EnableMicrophone(!engine.MicrophoneEnabled);
void OnDestroy() => engine?.Destroy();
}

A fuller script ships as the Basic Call sample (Package Manager, AppLooma RTC, Samples).

AppEngine#

MemberWhat it does
AppEngine.Create(appId)The engine. One per game; a second call returns the same one.
Task JoinChannel(token, wsUrl, options)Role Host, Cohost or Audience; Camera and Microphone on join.
Task LeaveChannel()Leave; the engine can join again.
Task EnableCamera(bool) / EnableMicrophone(bool)Turn your devices on and off.
Task SendMessage(string) / SendMessageJson(json)Reaches the message event of every SDK in the channel.
RenewToken(token)After TokenWillExpire.
RemoteUsers, LocalUid, ConnectionStateCurrent state.
Destroy()Leave and release everything.

Events

Raised on the main thread: UserJoined, UserLeft, TrackSubscribed, TrackUnsubscribed, MessageReceived, ConnectionStateChanged, ActiveSpeakersChanged, TokenWillExpire, Disconnected, Error.

Video as textures#

Add AppVideoTexture to a GameObject with a RawImage or a Renderer. Set Uid to a remote user, or leave it empty for your own camera. Each frame is drawn into a canvas and uploaded into the texture with texImage2D.

  • MaxSize (default 640) caps the longest side; keep it modest when many users are on screen.
  • MaxFps (default 30) caps uploads per second.
  • TextureChanged fires when the texture is recreated because the video size changed.
  • Remote audio plays through the browser by itself; only video needs a component.

What comes next#

  • Android, iOS, Windows and macOS players on the native SDKs.
  • Per-user volume, for proximity voice driven by your own positions.
  • Asset Store listing.