twilio / twilio-video-app-react

A collaboration application built with the twilio-video.js SDK and React.js
Apache License 2.0
1.81k stars 728 forks source link

Audio MediaStreamTrack is found ended #613

Closed ashrakrahman closed 2 years ago

ashrakrahman commented 2 years ago

Room Type : GO Issue occurring frequency : almsot 4 out of 10 times after trying.

In our implementation, the audio track of the participant is generated after joining a Room.

Participant A creates a Twilio room and joined into it. Participant A published this track successfully. His local audio mediasteam track info :

LocalAudioTrack id: "360335d1-b0fe-469b-92c4-d0c79cd028fe" isEnabled: true isStarted: true isStopped: false kind: "audio" mediaStreamTrack: MediaStreamTrack contentHint: "" enabled: true id: "360335d1-b0fe-469b-92c4-d0c79cd028fe" kind: "audio" label: "Webcam C270 Mono" muted: false onended: null onmute: null onunmute: null readyState: "live"

Now, participant B joins the same room. But he founds Participant A's MediaStreamTrack as "ended"

value: RemoteAudioTrackPublication isSubscribed: true isTrackEnabled: true kind: "audio" publishPriority: (...) track: RemoteAudioTrack isEnabled: true isStarted: true isSwitchedOff: false kind: "audio" mediaStreamTrack: MediaStreamTrack contentHint: "" enabled: true id: "01df80a2-2c7e-4dba-8b02-c2c789c79db4" kind: "audio" label: "01df80a2-2c7e-4dba-8b02-c2c789c79db4" muted: true onended: null onmute: null onunmute: null readyState: "ended"

What could be the reason of it ?

Our implementation : After participant joining a Room, we call toggleAudioEnabled() to publish Participant Audio Track. const toggleAudioEnabled = useCallback(() => { if (audioTrack) { audioTrack.isEnabled ? audioTrack.disable() : audioTrack.enable(); } else { const createTrack = async () => { await getLocalAudioTrack() .then((track: any) => { if (localParticipant && track) { localParticipant?.publishTrack(track); } }) .catch((e: any) => { console.log('New Audio Track could not be published', e); }); }; createTrack(); } }, [audioTrack, localParticipant, getLocalAudioTrack]);

timmydoza commented 2 years ago

Thanks for the question @ashrakrahman!

I'm not sure what the problem could be. Would you mind providing a little more information about how the problem is encountered? I'm curious about:

readyState: 'ended' comes from the MediaStreamTrack object, and there are a number of reasons why it could switch to an ended state. According to the MDN documentation here, there are a few reasons why the MediaStreamTrack could transition to an ended state:

One thing you can try, is to add an event listener to all MediaStreamTracks to listen for the ended event. This could help you pinpoint when and why the track ends.

olipyskoty commented 2 years ago

Closing this issue due to inactivity. We are happy to reopen with more information. Thank you!