jitsi-meet icon indicating copy to clipboard operation
jitsi-meet copied to clipboard

fix(Android): Stop Screen sharing from Android System notification fixed

Open vishal2005025 opened this issue 4 months ago • 2 comments

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));
});

vishal2005025 avatar Dec 09 '25 17:12 vishal2005025

@saghul @damencho please take a look.

vishal2005025 avatar Dec 09 '25 17:12 vishal2005025

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 :(.

jitsi-jenkins avatar Dec 09 '25 17:12 jitsi-jenkins

Is that event emitted for mobile?

saghul avatar Dec 11 '25 23:12 saghul

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.

vishal2005025 avatar Dec 12 '25 07:12 vishal2005025

@Calinteodor PTAL when you get a chance.

saghul avatar Dec 12 '25 07:12 saghul

@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 avatar Dec 15 '25 12:12 Calinteodor

@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 avatar Dec 15 '25 13:12 vishal2005025

@vishal2005025 Please add a screen recording next time you update the PR.

Calinteodor avatar Dec 15 '25 13:12 Calinteodor

@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.

vishal2005025 avatar Dec 15 '25 21:12 vishal2005025

@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 avatar Dec 16 '25 10:12 Calinteodor

@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.

vishal2005025 avatar Dec 16 '25 12:12 vishal2005025