livekit / client-sdk-unity-web

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

First participant audio publish issue #22

Closed itsadarshms closed 1 year ago

itsadarshms commented 1 year ago

I was able to setup the project and take a WebGL build in Unity without any issues but came across a bug in publishing the audio (I'm only trying to publish the audio tracks, video is disabled). The issue seems to be only affecting the first participants in a room where in the first participant in the room can hear the audio of all other participants, but other participants are not able to hear the audio of the first participant. I've tested the following scenarios:

My initial assumption was that maybe the first participant doesn't have publishing permissions or maybe the SDP lines were set to recvonly but all of these seems to be set correctly. All participants are having the same permissions and SDP lines were also set to sendrecv.

I've tried the similar implementation using JS SDK as well and everything was working well without any issues. This issue seems to be only happening for Unity WebGL builds.

Tested browsers

theomonnom commented 1 year ago

Hey @crypt3dC4rb0n, thanks for reporting the issue. Which version of Unity are you using? Are you using our unity demo, or have you created a new project? (so I know if I have to dig into the demo repo)

itsadarshms commented 1 year ago

Hey, thanks for the quick response. I've tested with the following unity versions

I tried with your demo as well as a new project but had the same issue in both. I also tried updating the livekit-js sdk version from 1.3.0 to 1.4.2 but it didn't resolve the issue.

Note: I only changed the token fetch part in your code, used UnityWebRequest for fetching the token from a server deployed REST API service. And added a mute button for debugging.

theomonnom commented 1 year ago

I managed to reproduce the issue. I just created a new commit to add the listeners before connecting to the room in the example and it fixed the problem. Can you try to also do that inside your project?

itsadarshms commented 1 year ago

Yes, I've applied the same fix and the issue is resolved now👍 Thank you. Out of curiosity why only the first participants in a room were affected?

theomonnom commented 1 year ago

Hey, because when you join a room, the server will directly subscribe you to other participants' tracks (if auto-subscribe is enabled). So you receive subscription events directly after joining the room and there were no listeners at this time, so we were missing some events..