【发布时间】: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