使用 JsSIP 将 mediaStream 绑定到 <Video> 元素 Bad Media 描述

Bind mediaStream to <Video> element with JsSIP Bad Media Description

提问人:Eduardo Galeano 提问时间:9/15/2020 最后编辑:Eduardo Galeano 更新时间:9/17/2020 访问量:1474

问:

我一直在尝试制作一个简单的视频通话界面,到目前为止,我只设法启动了视频通话,接收器获得了我的音频和视频流,但是当我尝试将流(本地或远程)添加到页面中的元素时,我收到错误。JsSIP<video>"Bad Media Description"

我的代码是这样的:

    const address = "my.address.com";
    const pass = "pass";
    const callee = "id2";
    const user = "id1";
    const sockets = [];
    const localStream = new MediaStream();
    const config = {
      sockets: sockets,
      uri: `sip:${user}@${address}`,
      password: pass
    };
        const agent = new JsSIP.UA(config);
    const servers = {
      iceServers: [
        {urls:"stun:stun.l.google.com:19302"}
      ]
    };
    const options = {
      pcConfig: servers,
      mediaConstraints: {
        audio: true,
        video: true
      }
    };
    
    document.getElementById("localVideo").srcObject = localStream;
    document.getElementById("buttonCall").addEventListener("click", call);
    
    sockets.push(
      new JsSIP
      .WebSocketInterface(`wss://${address}:443/ws`)
    );
    
    agent.start();
    
        agent.on("newRTCSession", function(data){
          let dataSession = data.session;
          
          dataSession.on("confirmed",function(e){
            let localTracks = dataSession.connection.getSenders();
            localStream.addTrack(localTracks[0].track);
            localStream.addTrack(localTracks[1].track);
            console.log(e);
            document.getElementById("localVideo").play();
          });
        });
        function call() {
            agent
            .call(
            `sip:${callee}@${address}`,
            options
            );
        }

如果有人能为我指出正确的方法使这成为可能,我将不胜感激。

JavaScript WebRTC JSSIP

评论


答:

0赞 Eduardo Galeano 9/17/2020 #1

我已经解决了它,我的问题是我正在使用 Vue,所以通过在我的函数中覆盖对 s 的引用,解决方案是通过箭头函数更改这些 s,如下所示:functionmounted()thisfunction() => {}

    agent.on("newRTCSession", (data) => {
      let dataSession = data.session;
      
      dataSession.on("confirmed", () => {
        let localTracks = dataSession.connection.getSenders();
        localStream.addTrack(localTracks[0].track);
        localStream.addTrack(localTracks[1].track);
        console.log(e);
        this.$refs.localVideo.play();
      });
    });