我需要再次从共享屏幕切换到视频。我首先使用此代码共享屏幕。connection.addStream ({ screen: true, oneway: true, streamCallback: function (screen) { addStreamStopListener (screen, function () { selectFrontCameraDuringActiveSession (); }); }, })
然后我使用此代码再次显示我做错的视频。
connection.attachStreams.forEach (function (stream) {
// stop only video tracks
// so that we can recapture video track
stream.getVideoTracks (). forEach (function (track) {
track.stop ();
});
});
var mediaConstraints = {
audio: false, // NO need to capture audio again
video: {
facingMode: "application",
},
};
navigator.mediaDevices
.getUserMedia (mediaConstraints)
.then (function (frontCamera) {
var frontCameraTrack = frontCamera.getVideoTracks () [0];
//video.srcObject = frontCamera;
connection.getAllParticipants (). forEach (function (pid) {
connection.peers [pid] .peer
.getSenders ()
.forEach (function (sender) {
if (sender.track.kind == "video") {
sender.replaceTrack (frontCameraTrack);
}
});
});
app.toggleShareScreen = false;
});
每个倾听的人都会得到改变。但是传递变化的那个人并没有反映出来。并关闭视频和激活视频,例如停止工作。
if (value === false) {
connection.attachStreams.forEach (function (stream) {
stream.getVideoTracks (). forEach ((t) => (t.enabled = value));
});
}
if (value === true) {
connection.attachStreams.forEach (function (stream) {
stream.getVideoTracks (). forEach ((t) => (t.enabled = value));
});
}