0

我是JSSIP的新手。我需要在正在进行的通话中将音频通话切换为视频通话。

const session = userAgent.call(destinationNumber, {
      mediaConstraints: {
        audio: true,
        video: false
      },
      pcConfig: {
        iceServers: [{ urls: Config.STUN_SERVER }]
      }
    });

这就是我发起音频通话的方式。我如何能够在通话之间切换到视频通话?

4

1 回答 1

0

您可以做一个技巧并使用视频发起呼叫,但不是放置真正的视频轨道,而是放置一些虚拟的“静音”视频轨道:

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);
        });
于 2020-01-13T16:41:36.937 回答