fix(Android): Stop Screen sharing from Android System notification fixed
Fixes: #16746
What was the issue?
When screen sharing on Android, if the user stops sharing using the Android system “Stop sharing” UI (red system chip), the MediaProjection stops and the local frames stop updating - but Jitsi still considers the user to be screen sharing. Remote participants continue to see a frozen screen-share tile until the user presses the in-app “Stop sharing” button.
Root cause
The underlying JitsiLocalTrack for desktop capture emits JitsiTrackEvents.LOCAL_TRACK_STOPPED when MediaProjection is terminated by the OS.
However, on React Native (Android/iOS), we were not listening for this event in actions.native.ts, so the existing toggleScreensharing(false) cleanup flow was never triggered.
Solution
Added a listener for LOCAL_TRACK_STOPPED on the desktop track when starting screensharing:
track.on(JitsiTrackEvents.LOCAL_TRACK_STOPPED, () => {
dispatch(toggleScreensharing(false));
});
@saghul @damencho please take a look.
Hi, thanks for your contribution! If you haven't already done so, could you please make sure you sign our CLA (https://jitsi.org/icla for individuals and https://jitsi.org/ccla for corporations)? We would unfortunately be unable to merge your patch unless we have that piece :(.
Is that event emitted for mobile?
Yes, LOCAL_TRACK_STOPPED is emitted on mobile. When the Android system UI stops MediaProjection, the desktop JitsiLocalTrack fires this event. The RN layer wasn’t listening for it before, so I added the missing listener in the PR.
@Calinteodor PTAL when you get a chance.
@Calinteodor PTAL when you get a chance.
Issue has not been fixed. Screen-share doesn't stop when android system button is pressed, it freezes. It stops only if you press stop screen sharing button from Jitsi overflow menu.
@Calinteodor Thanks for checking. Looks like stopping via the Android system UI doesn’t go through the same teardown path as the in-app stop, so the JS-side change alone isn’t enough. I’ll dig into the Android MediaProjection lifecycle and follow up once I have a clearer fix.
@vishal2005025 Please add a screen recording next time you update the PR.
@Calinteodor Thanks for the note.
I’ve updated the PR. In the current change, I handle the Android system stop via TRACK_STOPPED in middleware.native.ts, so when the local desktop screenshare track is stopped by the OS it now triggers toggleScreensharing(false), matching the in-app stop behavior. Previously, middleware.native.ts only handled TRACK_UPDATED, which covers the muted case but not the system-initiated stop, so the screensharing state wasn’t cleared when MediaProjection was stopped by the OS.
I tried checking this on an Android emulator (Pixel 5), but the system “Stop sharing” UI doesn’t appear there, so I couldn’t capture a recording. This seems to depend on the real device / MediaProjection UI.
I’d appreciate it if you could test this revision on a physical device. Happy to iterate based on the results.
Thank you.
@Calinteodor Thanks for the note.
I’ve updated the PR. In the current change, I handle the Android system stop via TRACK_STOPPED in middleware.native.ts, so when the local desktop screenshare track is stopped by the OS it now triggers toggleScreensharing(false), matching the in-app stop behavior. Previously, middleware.native.ts only handled TRACK_UPDATED, which covers the muted case but not the system-initiated stop, so the screensharing state wasn’t cleared when MediaProjection was stopped by the OS.
I tried checking this on an Android emulator (Pixel 5), but the system “Stop sharing” UI doesn’t appear there, so I couldn’t capture a recording. This seems to depend on the real device / MediaProjection UI.
I’d appreciate it if you could test this revision on a physical device. Happy to iterate based on the results.
Thank you.
Not working. If you are unable to test on a real device, please stop doing updates related to this issue.
@Calinteodor Understood - thanks for testing and for the feedback. I’ll stop iterating on this for now and will be happy to revisit it once I’m able to test on a real device.