Unity (Web) Quickstart

1. Install LiveKit SDK

Click the Add + menu in the Package Manager toolbar, select Add package from git URL, and enter: https://github.com/livekit/client-sdk-unity-web.git

For more details, see the Unity docs on installing packages from Git URLs.

2. Connect to a room

Note that this example hardcodes a token. In a real app, you’ll need your server to generate a token for you.

public class MyObject : MonoBehaviour
{
public Room Room;
IEnumerator Start()
{
Room = new Room();
var c = Room.Connect("<your LiveKit server URL>", "<generate a token>");
yield return c;
if (!c.IsError) {
// Connected
}
}
}

3. Publish video & audio

yield return Room.LocalParticipant.EnableCameraAndMicrophone();

4. Display a video on a RawImage

RawImage image = GetComponent<RawImage>();
Room.TrackSubscribed += (track, publication, participant) =>
{
if(track.Kind == TrackKind.Video)
{
var video = track.Attach() as HTMLVideoElement;
video.VideoReceived += tex =>
{
// VideoReceived is called every time the video resolution changes
image.texture = tex;
};
}
};

5. Create a backend server to generate tokens

Set up a server to generate tokens for your app at runtime by following this guide: Generating Tokens.