Skip to content

JeffreyCastellano/livekit-client-sdk-unity-native

Repository files navigation

UniLiveKit - LiveKit Unity SDK for Native Platforms

-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:

For WebRTC functions, Unity WebRTC package(com.unity.webrtc) is used.

Requirements

There are some requirements related to Unity WebRTC. Check Unity WebRTC's Requirements specifically for Android builds.

Unity Version

  • Unity 2021.3 & 2022.1

Platform

  • Windows
  • macOS
  • iOS
  • Android (ARMv7 is not supported)

Docs about LiveKit

You can check docs and guides at https://docs.livekit.io

Installation

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.

Additional Dependencies

https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.3.3

Features

  • The screen capture function uses the Unity Scene Camera input, so UI components(Canvas, Button, ...) won't show in the capture.

From Unity WebRTC

Following features are not supported:

  • WebGL - LiveKit has its own WebGL Unity official SDK
  • Simulcast - sure...
  • Android ARMv7 - I mean...fair enough.

Examples

Interface was implemented referring to LiveKit Unity WebGL SDK. The sample below is conceptual. Check DemoApp in Samples~/UniLiveKitDemo for details.

Connecting to a room

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
        }
    }
}

Publishing video & audio

room.LocalParticipant?.SetCamera(true);
room.LocalParticipant?.SetMicrophone(true);

Display a video on a RawImage

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;
        }
    });
}

Known issues

  • If a remote peer leaves the room during video call, the remaining peer's Windows Unity Editor will crash.

License

Apache-2.0 license

Third Party

About

Temporary spot for unofficial Unity LiveKit SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages