【发布时间】:2021-07-01 12:27:57
【问题描述】:
以下代码是我的屏幕共享内容,效果很好。 但是我也想在共享屏幕时发布我的本地相机,是否有可能,如果可以,我该怎么做?
发布提要代码。
function publishOwnFeed(useAudio, isScreenSharing) {
let media = null;
if (isScreenSharing) {
media = {
video: "screen",
audioRecv: false,
videoRecv: false,
audioSend: useAudio,
videoSend: true
};
} else {
media = {
audioRecv: false,
videoRecv: false,
audioSend: useAudio,
videoSend: true
};
}
// Publish our stream
handler.createOffer({
// Add data:true here if you want to publish datachannels as well
media: media, // Publishers are sendonly
// If you want to test simulcasting (Chrome and Firefox only), then
// pass a ?simulcast=true when opening this demo page: it will turn
// the following 'simulcast' property to pass to janus.js to true
simulcast: doSimulcast,
simulcast2: doSimulcast2,
success: function(jsep) {
Janus.debug("Got publisher SDP!", jsep);
let publish = { request: "configure", audio: useAudio, video: true };
if (acodec)
publish["audiocodec"] = acodec;
if (vcodec)
publish["videocodec"] = vcodec;
handler.send({ message: publish, jsep: jsep });
},
error: function(error) {
Janus.error("WebRTC error:", error);
toggleElement(shareScreen);
if (useAudio) {
publishOwnFeed(false);
} else {
Toastnotify.create({
text: "WebRTC error... " + error.message,
type: 'danger',
important: false
});
}
}
});
}
启动屏幕共享代码。
function startScreenShare() {
unpublishOwnFeed();
setTimeout(function(){
publishOwnFeed(false, true); // publish my screen whihout audio
}, 800);
// setTimeout(function(){
// publishOwnFeed(false, false); // this is not work. (publish my camera whitout audio to others to just see me)
// }, 800);
}
停止屏幕共享代码。
function stopScreenShare() {
unpublishOwnFeed();
setTimeout(function(){
publishOwnFeed(true, false);
}, 800);
toggleElement(shareScreen);
}
非常感谢您的帮助。
【问题讨论】:
标签: screensharing janus