Screensharing : detecting the stop from Chrome interface

5,441 views
Skip to first unread message

Geoffrey Hug

unread,
Nov 21, 2017, 4:26:15 AM11/21/17
to meetecho-janus
TL;DR : When sharing your screen through Chrome, it provides its own interface with a button to stop sharing the screen. I don't get any event when that happens and am therefore unable to remove the stopped feed. How am I supposed to do that ?

I have a videoroom app where people come in, publish their video feed, and listen to others. To share the screen, I create a new handle, attach to the videoroom and publish a new feed with { video: "screen" } in the 'media' field.

So the screensharing feed is added just like the regular video feeds, so I'd expect to have some kind of message or callback firing on the listening handle. Seems like nothing is firing when the user stops screensharing from the Chrome button. Even though if someone quits, their video feed is removed correctly.

Mirko Brankovic

unread,
Nov 21, 2017, 5:26:41 AM11/21/17
to meetecho-janus
I think you can use stream.onended, like:
stream.onended = () => { // Click on browser UI stop sharing button
  console.info("ScreenShare has ended");
};

--
You received this message because you are subscribed to the Google Groups "meetecho-janus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meetecho-janus+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Mirko

Geoffrey Hug

unread,
Nov 21, 2017, 6:45:47 AM11/21/17
to meetecho-janus
From the latest specs https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/onended

It looks like this should work, I took my stream, called getVideoTracks() then looped over it to add an track.onended function, but it's still not firing...

Geoffrey Hug

unread,
Nov 23, 2017, 4:11:30 PM11/23/17
to meetecho-janus
So digging a bit more I found out that nor my stream object nor my videoTrack object change at all after pressing the stop button.
The stream is still enabled: true and the videoTrack still has readyState: "live" after.

Not sure what's going on here. Can it be because I'm testing on the same computer ? I already noticed it doesn't like it if I have the two windows on different screens, the screensharing fails altogether.

Mirko Brankovic

unread,
Nov 23, 2017, 6:21:37 PM11/23/17
to meetecho-janus
I think you will get event SS_UI_CANCEL message in content-script.js on window.eventlistener. that one you need to pass to backround.js listener which needs to stop the stream of screen sharing.
I found a github plugin example that  had this already and was working like that out of the box ;)

--

Mirko Brankovic

unread,
Nov 23, 2017, 6:22:18 PM11/23/17
to meetecho-janus

Geoffrey Hug

unread,
Nov 24, 2017, 10:45:59 AM11/24/17
to meetecho-janus
Thanks for your help ! I figured it out.

The reason I wasn't seeing the event fired was because I was trying to listen on the remote stream that I'd get from whoever is sharing with me. Instead what I needed to do was to listen for it on the local stream of the sharer. Then I just send a leave request through my plugin handle :

    onlocalstream: function(stream){
      stream.getVideoTracks()[0].onended = function(){
        var leave = {
          "request": "leave",
          "room": room,
        }
        screensharing_handle.send({
          "message" : leave
        })
      }
    }

Not sure if the room parameter is necessary here but it works.

Lorenzo Miniero

unread,
Nov 27, 2017, 5:16:36 AM11/27/17
to meetecho-janus
This onended property is interesting, and I guess it might make sense to add it to janus.js so that we can notify the application via a dedicated callback. I'll have a look at this as soon as I have some time (catching up with a lot of stuff as I just came back from many weeks abroad).

L. 
Reply all
Reply to author
Forward
0 new messages