我是JSSIP的新手。我需要在正在进行的通话中将音频通话切换到视频通话。
const session = userAgent.call(destinationNumber, {
mediaConstraints: {
audio: true,
video: false
},
pcConfig: {
iceServers: [{ urls: Config.STUN_SERVER }]
}
});
这就是我发起音频通话的方式。如何在通话之间切换到视频通话?
您可以做一个技巧并用视频发起通话,但不是放置真正的视频轨道,而是放置一些虚拟的"无声"视频轨道:
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).getVideoTracks()[0].then(track => {
connection.getSenders().filter(sender => sender.track !== null && sender.track.kind === "video").forEach(sender => {
sender.replaceTrack(track);
});