Does RTCPeerConnection work in Microsoft Edge?

2020-03-01 20:29发布

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!

2条回答
来,给爷笑一个
2楼-- · 2020-03-01 20:32

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

查看更多
▲ chillily
3楼-- · 2020-03-01 20:48

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>

查看更多
登录 后发表回答