S
S
Space Around2020-11-27 18:38:12
JavaScript
Space Around, 2020-11-27 18:38:12

How to restart screen capture in an already created session (WebRTC)?

If the room owner turns on screen sharing before guests join the room, then everything works fine and the owner's share is shown to the guests, but if you turn on the share when there are already guests in the room, then only the owner's share is shown.
Since I use the RTCMultiConnection library , there is a demo version of a screen demonstration ( source code ) and a screen demonstration with a webcam ( source code ), my demos do not work, I looked at the demo code, there is little that is clear, I tried to integrate it into my code, I didn’t earned, in general, in any way. I looked in issues on GitHub, there is no similar problem (I looked at almost all the problems related to screen share).
Eventonstreamfrom the side of the guest does not react to the inclusion of the demonstration.

Running the demo:
screenShareOn() {
        let thisAdminVC = this.getInstance();

        this.connection.addStream({
            screen: true,
            oneway: true,
            data: true,
            streamCallback: function(stream) {
                thisAdminVC.connection.extra.streamID = stream.id;

                thisAdminVC.connection.updateExtraData();
                thisAdminVC.videoContainerLocal.screen.elementHTML.appendChild(stream);

                const videoTrack = stream.getVideoTracks()[1];
                videoTrack.onended = () => {
                    thisAdminVC.connection.resetTrack();
                }

                thisAdminVC.connection.getAllParticipants().forEach( participant =>
                    thisAdminVC.connection.replaceTrack(videoTrack, participant, true)
                );
            }
        });
     
        this.connection.renegotiate();
}


Turn off the demo:
screenShareOff() {
        this.connection.attachStreams.forEach(function(stream) {
            if (stream.idInstance.indexOf("isScreen") != -1) {
                stream.getTracks().forEach(track => track.stop());
                stream.getTracks().forEach(track => stream.removeTrack(track));
            }
        });
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Space Around, 2020-11-28
@viksnamax

In general, I found only such a working solution for myself, I don’t know how correct it is. In order for the guest to see the owner of the room when the screen share is restarted, you need to copy the created stream into a temporary variable, insert the temporary stream, then everything works and the array connection.streamEventsdoes connection.attachStreamnot overflow.

screenShareOn() {

        let thisAdminVC = this.getInstance();

        this.connection.addStream({
            screen: true,
            oneway: true,
            data: true,
            streamCallback: function(stream) {

                for (let i = 0; i < thisAdminVC.connection.attachStreams.length; i++) {
                    if (thisAdminVC.connection.attachStreams[i].idInstance.indexOf("isScreen") != -1) {

                        let tmpStreamID = thisAdminVC.connection.attachStreams[i].id,
                        tmpStream = thisAdminVC.connection.streamEvents[tmpStreamID].stream;

                        thisAdminVC.connection.addStream(tmpStream);

                        thisAdminVC.connection.renegotiate();
                    }
                }

                thisAdminVC.connection.extra.streamID = stream.id;

                thisAdminVC.connection.updateExtraData();
                thisAdminVC.videoContainerLocal.screen.elementHTML.appendChild(tmpStream);                
            }
        });
        this.connection.renegotiate();
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question