RTCMultiConnection icon indicating copy to clipboard operation
RTCMultiConnection copied to clipboard

Is there a way detect if remote stream is user sharing their screen?

Open ngstwr opened this issue 4 years ago • 2 comments

I tried isScreen flag but it only works in local, for remote this is always coming false.

ngstwr avatar May 18 '20 03:05 ngstwr

Connection object is an object with data from the each local peer. I think that's why isScreen flag of remote users is always false.

So, I think you should use extra. when create room, set extra data like this. if(isScreen) { connection.extra.isScreen = true; } else { connection.extra.isScreen = false; }

and when remote user join, they can check this property in event.extra object. connection.onstream = function(event) { var isScreenShare = event.extra.isScreen; }

wnsvy223 avatar May 23 '20 09:05 wnsvy223

When you start screen capture for the first user, here we get the id of the screen capture stream and send it to all participants in the room:

connection.addStream({
            screen: true,
            oneway: true,
            data: true,
            streamCallback: function(stream) {
                connection.extra = {
                    stream_id: stream.id
                };
                connection.updateExtraData();
            }
        });

Text data arrives faster than screen capture, so you can send it inside a callback:

connection.onstream = function(event) {
    if (event.type == "remote") {
        if (event.stream.id == event.extra.stream_id) {
            // here if the stream turned out to be a screen share
        } else {
            // here is the usual video stream from a webcam
        }
    }
}

spacearound404 avatar Nov 13 '20 16:11 spacearound404