vueuse / vueuse

Collection of essential Vue Composition Utilities for Vue 2 and 3
https://vueuse.org
MIT License
18.99k stars 2.39k forks source link

fix(useDisplayMedia): stop stream when screen is not shared anymore #3976

Closed robertrosman closed 6 days ago

robertrosman commented 2 weeks ago

Before submitting the PR, please make sure you do the following


Description

When the user stops sharing the screen, we need to stop the stream. Hence I've added an event listener to catch when the track ends, and call the stop function.

Additional context

Steps to reproduce the bug:

  1. Open Google Chrome (on mac).
  2. Start sharing screen (select a window, not just a tab).
  3. Look for the small notification that says "vueuse.org is sharing a window" (1. in the attachment).
  4. Click "Stop sharing".
  5. Before this fix the stream turns black, but is still in enabled state (2. in the attachment). After this fix it is properly stopped.

image