JSSIP 如何从音频通话切换到视频通话

huangapple go评论73阅读模式
英文:

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);
        });

huangapple
  • 本文由 发表于 2020年1月6日 22:28:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613831.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定