livekit / client-sdk-unity-web

Client SDK for Unity WebGL
Apache License 2.0
47 stars 15 forks source link

hardware camera not releasing when disconnect and reconnect in another room #24

Open leandro-zanardi opened 1 year ago

leandro-zanardi commented 1 year ago

If you connect a room room.Connect(url, token) then you disconnect from room room.Disconect(true)

and so connect again in a different room with other token and roomName, the video track stack, and camera hardware never turn off.

publishing track {localTrack: LocalVideoTrack} publishing track {localTrack: LocalVideoTrack} publishing track {localTrack: LocalVideoTrack}

and no way to unpublish and release de camera. even doing a disconnection again, the track keep stacking

leandro-zanardi commented 1 year ago

how to fully destroy a local Track? from c# before disconnect room, to prevent it keep stacking?

Client.CreateLocalVideoTrack(opts);

has no way to be destroyed

theomonnom commented 1 year ago

Hey, you should be able to unpublish a track using LocalParticipant.UnpublishTrack.

leandro-zanardi commented 1 year ago

It remove from unity, not from JS. In my case, the user can change many times of Room, when user change a room, even the room destroyed, the JS object still having listeners and alive in the DOM. From the C# side, has no way to clear the JS object complete. If you use only one room is fine, use the LocalParticipant.UnpublishTrack, but in the next room you enter, it will be stacked in the HTML DOM.

theomonnom commented 1 year ago

Hey, sorry for the late answer. The DOM objects will not be directly deleted because of the C# GC. You can try to call Room.Dispose when you're done with it. You should still be able to turn off the hardware camera even if the DOM is still present. Removing the listeners from the Room object on destroy is tricky (can lead to Null references when an event is called in a certain timing). I will experiment with another way of dealing with listeners after releasing the native SDK :)