-Note from Jeff:
Just fixing and updating a few packages here temporarily while the main repo works things out. Taken from the unofficial package and modified a bit - https://github.com/maxstdev/livekit-client-sdk-unity-native
UniLiveKit package is for developing Unity apps that target native platforms(Android, iOS, Mac, and Windows). Note that it is not the official Client SDK for LiveKit. It doesn't work in Unity WebGL.
This package is written in C#, referencing the following SDKs:
- Mainly : LiveKit Swift SDK
- Partially : LiveKit Unity WebGL SDK
For WebRTC functions, Unity WebRTC package(com.unity.webrtc) is used.
There are some requirements related to Unity WebRTC. Check Unity WebRTC's Requirements specifically for Android builds.
- Unity 2021.3 & 2022.1
- Windows
- macOS
- iOS
- Android (ARMv7 is not supported)
You can check docs and guides at https://docs.livekit.io
Follow this unity tutorial using the https://github.com/JeffreyCastellano/livekit-client-sdk-unity-native/package link.
You can then directly import the samples into the package manager.
https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.3.3
- The screen capture function uses the Unity Scene Camera input, so UI components(Canvas, Button, ...) won't show in the capture.
Following features are not supported:
- WebGL - LiveKit has its own WebGL Unity official SDK
- Simulcast - sure...
- Android ARMv7 - I mean...fair enough.
Interface was implemented referring to LiveKit Unity WebGL SDK. The sample below is conceptual. Check DemoApp in Samples~/UniLiveKitDemo for details.
public class JoinMenu : MonoBehaviour
{
public static string LivekitURL { get; private set; }
public static string RoomToken { get; private set; }
}
public class ExampleRoom : MonoBehaviour
{
public Room room;
void Start()
{
ConnectRoom();
}
async void ConnectRoom()
{
room = new Room(this);
room.PrepareConnection();
try
{
await room.Connect(JoinMenu.LivekitURL, JoinMenu.RoomToken);
// Connected
StartCoroutine(WebRTC.Update());
}
catch
{
// Error
}
}
}room.LocalParticipant?.SetCamera(true);
room.LocalParticipant?.SetMicrophone(true);void IRoomDelegate.DidSubscribe(Room room, RemoteParticipant participant, RemoteTrackPublication publication, Track track)
{
DispatchQueue.MainSafeAsync(() =>
{
switch (track.kind)
{
case Track.Kind.Video:
var videoTrack = track.GetMediaTrack as VideoStreamTrack;
videoTrack.OnVideoReceived += (texture =>
{
GameObject participantViewGO = Instantiate(participantViewPrefab, ViewContainer.transform);
var participantView = participantViewGO.GetComponent<ParticipantView>();
var videoView = participantView.VideoView;
videoView.texture = texture;
});
break;
case Track.Kind.Audio:
break;
default:
break;
}
});
}- If a remote peer leaves the room during video call, the remaining peer's Windows Unity Editor will crash.