"Screen Share Stopped" Event in Chrome

I’d like my online classroom application to react when the users presses
the “Stop Sharing” button in the floating window that Chrome displays when
a user is sharing their screen.

Right now, when the user presses this button, it looks to all the
suscribers like the stream is still open, it just stops updating. I would
instead like to update the UI for both the publisher ("you have stopped
sharing your screen. Click here to start again…) and the subscribers.

Is there an event I can listen on the Room or Stream object? Or some other
way to make this happen?

You have to listen to the stream ended event on the screenStream

when your screenStream receives the event access-accepted, it gets the stream stream property on which you can listen to events

screenStream.addEventListener(“access-accepted”, () => {

screenStream.stream.getVideoTracks()[0].addEventListener(‘ended’, () =>{
//do whatever you want here and unpublish the stream
room.unpublish(screenStream);
});
});