Does RTCPeerConnection work in Microsoft Edge?

有些话、适合烂在心里 提交于 2019-12-18 21:17:37

问题


I am currently working on VoIP using WebRTC. It's going to be a UWP application written in JavaScript.

Now, I am trying to check whether it works or not by testing samples from https://webrtc.github.io/samples on Microsoft Edge.

It turns out that it works fine except RTCPeerConnection.

For example, when I opened https://webrtc.github.io/samples/src/content/peerconnection/audio in Edge, it gave me getUserMedia() error: NotFoundError when I clicked the call button. On Chrome, it works fine.

Another example is when I tried https://apprtc.appspot.com, it gave me

Messages:  
Error getting user media: null
getUserMedia error: Failed to get access to local media. Error name was NotFoundError. Continuing without sending a stream.
Create PeerConnection exception: InvalidAccessError

Version:    
gitHash:    c135495bc71e5da61344f098a8209a255f64985f
branch:     master
time:       Fri Apr 8 13:33:05 2016 +0200

So, how should I fix that? Adapter.js is also called. I also allow everything it needs.

Or I shouldn't use WebRTC for this project. If so, what should I use?

Cheers!


回答1:


Microsoft Edge implements ORTC, a more low-level decentralized cousin of WebRTC that does not have an overarching RTCPeerConnection object.

But the good news is that adapter.js, the official WebRTC polyfill, shims RTCPeerConnection for you on Edge, so you should be able to use WebRTC the same way on all the browsers.

For instance, this demo works for me in Edge, Firefox and Chrome.

var pc1 = new RTCPeerConnection(), pc2 = new RTCPeerConnection();

navigator.mediaDevices.getUserMedia({ video: true, audio: true })
  .then(stream => pc1.addStream(video1.srcObject = stream))
  .catch(log);

var add = (pc, can) => can && pc.addIceCandidate(can).catch(log);
pc1.onicecandidate = e => add(pc2, e.candidate);
pc2.onicecandidate = e => add(pc1, e.candidate);

pc2.onaddstream = e => video2.srcObject = e.stream;
pc1.oniceconnectionstatechange = e => log(pc1.iceConnectionState);
pc1.onnegotiationneeded = e =>
  pc1.createOffer().then(d => pc1.setLocalDescription(d))
  .then(() => pc2.setRemoteDescription(pc1.localDescription))
  .then(() => pc2.createAnswer()).then(d => pc2.setLocalDescription(d))
  .then(() => pc1.setRemoteDescription(pc2.localDescription))
  .catch(log);

var log = msg => div.innerHTML += "<br>" + msg;
<video id="video1" width="160" height="120" autoplay muted></video>
<video id="video2" width="160" height="120" autoplay></video><br>
<div id="div"></div>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>



回答2:


You should check your privacy settings first to allow Edge to access your media devices. https://privacy.microsoft.com/en-us/windows-10-camera-and-privacy



来源:https://stackoverflow.com/questions/36824585/does-rtcpeerconnection-work-in-microsoft-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!