Answer the question
In order to leave comments, you need to log in
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).
Eventonstream
from the side of the guest does not react to the inclusion of the demonstration.
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();
}
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
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.streamEvents
does connection.attachStream
not 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 questionAsk a Question
731 491 924 answers to any question