【问题标题】:webrtc onicecandidate not called on opera browser歌剧浏览器上未调用 webrtc onicecandidate
【发布时间】:2020-06-01 19:14:44
【问题描述】:

我有一个问题,我的 onicecandidate 事件没有在 Opera 浏览器中被触发,这是我的代码

我试过 getUserMedia 以不同的方式(通过 addStream 和 addTrack)将流添加到 RTCPeerConnection,设置 offerToReceiveAudio 和 offerToReceiveVideo,这些都没有帮助

代码

const RTCPeerConnection =  window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
const RTCSessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.RTCSessionDescription;
const RTCIceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate;

const mediaConstraints = {
    offerToReceiveAudio: true,
    offerToReceiveVideo: false
}

const options = {
    iceServers: [
        {
          urls: 'turn:74.11.232.11:3478',
          credential: 'password',
          username: 'username'
        }
    ],
};

function getUserMedia(callback) {
    navigator.mediaDevices.getUserMedia({
        audio: true,
        video: false
    }).then(callback);
}

getUserMedia((stream) => {
     localStream = stream

     localStream.getAudioTracks()[0].enabled = false

     WebRtcPeerConnection = new RTCPeerConnection(options)

     WebRtcPeerConnection.addStream(stream)

     WebRtcPeerConnection.createOffer(mediaConstraints).then((offer) => {
         console.log(offer.sdp)
         WebRtcPeerConnection.setLocalDescription(offer);
         WebRtcPeerConnection.onicecandidate = onRoomIceCandidate
         onRoomOffer(null, offer)
     });
})

【问题讨论】:

    标签: javascript webrtc


    【解决方案1】:

    我的错误是声明了常量 RTCPeerConnection,正如我在 Opera 浏览器中理解的那样,RTCPeerConnection 是一个全局类(不在 window.RTCPeerConnection 等中) 我需要替换这一行

    const RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;

    到这里

    const RTCPeerConnection = RTCPeerConnection || window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      相关资源
      最近更新 更多