英文:
JSSIP How to switch between audio call to video call
问题
我是新手使用 JSSIP。我需要在正在进行的通话中 切换音频通话为视频通话。
const session = userAgent.call(destinationNumber, {
mediaConstraints: {
audio: true,
video: false
},
pcConfig: {
iceServers: [{ urls: Config.STUN_SERVER }]
}
});
这是我发起音频通话的方式。我如何能够在通话中间切换到视频通话?
英文:
I am new in JSSIP. I need to switch Audio call to video call in ongoing call.
const session = userAgent.call(destinationNumber, {
mediaConstraints: {
audio: true,
video: false
},
pcConfig: {
iceServers: [{ urls: Config.STUN_SERVER }]
}
});
This is how i initiate audio call. How i can able to switch to video call in between the call?
答案1
得分: 1
你可以进行一个小技巧,启动一个带视频的通话,但是不使用真实的视频轨道,而是使用一些虚拟的“静音”视频轨道:
function createSilentVideoTrack() {
const canvas = document.createElement("canvas");
canvas.width = 50;
canvas.height = 30;
canvas.getContext("2d").fillRect(0, 0, canvas.width, canvas.height);
animateCanvas(canvas);
const stream = canvas.captureStream(1);
const tracks = stream.getTracks();
const videoTrack = tracks[0];
return videoTrack;
}
当你需要启用视频时,只需将虚拟视频轨道替换为真实的视频轨道:
navigator.mediaDevices.getUserMedia(constraints).then(stream => {
const videoTrack = stream.getVideoTracks()[0];
connection.getSenders().forEach(sender => {
if (sender.track !== null && sender.track.kind === "video") {
sender.replaceTrack(videoTrack);
}
});
});
英文:
You can do a trick and initiate a call with video, but instead of putting real video track, you will put some dummy "silent" video track:
function createSilentVideoTrack() {
const canvas = document.createElement("canvas");
canvas.width = 50;
canvas.height = 30;
canvas.getContext("2d").fillRect(0, 0, canvas.width, canvas.height);
animateCanvas(canvas);
const stream = canvas.captureStream(1);
const tracks = stream.getTracks();
const videoTrack = tracks[0];
return videoTrack;
}
And when you need to enable video, you just replace dummy video track to the real one:
navigator.mediaDevices.getUserMedia(constraints).getVideoTracks()[0].then(track => {
connection.getSenders().filter(sender => sender.track !== null && sender.track.kind === "video").forEach(sender => {
sender.replaceTrack(track);
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论