Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine if track stopped event triggered by restart #1607

Open
alexcameron7 opened this issue Oct 18, 2021 · 2 comments
Open

Determine if track stopped event triggered by restart #1607

alexcameron7 opened this issue Oct 18, 2021 · 2 comments
Assignees
Labels
bug filed A bug has been filed upstream for this issue

Comments

@alexcameron7
Copy link

Hello,

I'm seeking the ability to determine if the 'stopped' event on track was triggered by a restart (https://sdk.twilio.com/js/video/releases/2.18.0/docs/LocalAudioTrack.html#restart).

Currently out 'stopped' event handler is responsible for unpublishing the track and performing other cleanup. An example of where this occurs is when a media device disconnects, causing the underlying MediaStreamTrack to end. However, we don't want to run such cleanup when a track is restarted.

Does this sound like a possible enhancement, or are there some alternative solutions I can implement?

@makarandp0 makarandp0 added the bug filed A bug has been filed upstream for this issue label Oct 19, 2021
@makarandp0 makarandp0 self-assigned this Oct 19, 2021
@makarandp0
Copy link
Contributor

Hello @alexcameron7,

Thank you reporting this issue. Yeah, it's hard to differentiate between 'stopped' caused by restart v/s other things causing the track to end. In your case - is restart initiated by you or the SDK in response to track being ended (SDK does call restart internally for some iOS safari use cases)

if restart is initiated by your application, you can wait for the promise returned by restart to resolve before acting on any stop event.

For the restart that is initiated by SDK - The only workaround I see is to delay your stopped handling. if you get a 'stopped` event wait for a couple second , and act on it only if it stayed in stopped state.

  localTrack.on('stopped', () => {
    setTimeout(() => {
      if (track.isStopped) {
        console.log('makarand: processing stop event');
      }
    }, 2000)
  }) 

That said, I think we will consider adding a parameter to stopped event to distinguish between these cases. I have added a ticket to track this improvement: VIDEO-7421

Thanks,
Makarand

@alexcameron7
Copy link
Author

Thank you for your reply @makarandp0,

The main case in our application is the internal SDK restart for iOS safari backgrounding/foregrounding, as you mentioned. However, we do plan on replacing old unpublish/publish workflows in our application with the new restart functionality.

I am keen for an enhancement such as the extra parameter you proposed. Cheers for creating a ticket and providing some workarounds in the mean time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug filed A bug has been filed upstream for this issue
Projects
None yet
Development

No branches or pull requests

3 participants