RTCPeerConnection在Microsoft Edge中有效吗? [英] Does RTCPeerConnection work in Microsoft Edge?

查看:387
本文介绍了RTCPeerConnection在Microsoft Edge中有效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用WebRTC处理VoIP。这将是一个用JavaScript编写的UWP应用程序。

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

现在,我试图通过测试来自 https://webrtc.github.io/samples

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

事实证明它工作正常除了 RTCPeerConnection

It turns out that it works fine except RTCPeerConnection.

例如,当我打开 https://webrtc.github.io/samples/src/content/peerconnection/audio ,它给了我 getUserMedia()错误:NotFoundError 当我点击通话按钮时。在Chrome上,它运行正常。

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.

另一个例子是我尝试 https ://apprtc.appspot.com ,它给了我

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

那么,我应该如何解决这个问题?还调用 Adapter.js 。我也允许它需要的一切。

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

或者我不应该将WebRTC用于这个项目。如果是这样,我该怎么用?

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

干杯!

推荐答案

Microsoft Edge实现了ORTC,这是WebRTC的一个更低级别的分散表兄,它没有一个总体 RTCPeerConnection 对象。

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

但好消息是 adapter.js ,官方WebRTC polyfill,垫片在Edge上为您提供RTCPeerConnection ,因此您应该能够在所有浏览器上以相同的方式使用WebRTC。

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.

例如,此演示工作正常适用于Edge,Firefox和Chrome。

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>

这篇关于RTCPeerConnection在Microsoft Edge中有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆