javascript - RTCPeerConnection 是否适用于 Microsoft Edge?

标签 javascript win-universal-app webrtc voip microsoft-edge

我目前正在使用 WebRTC 开发 VoIP。它将是一个用 JavaScript 编写的 UWP 应用程序。

现在,我正在尝试通过测试来自 https://webrtc.github.io/samples 的样本来检查它是否有效在 Microsoft Edge 上。

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

例如,当我打开https://webrtc.github.io/samples/src/content/peerconnection/audio在 Edge 中,当我单击调用按钮时,它给了我 getUserMedia() error: NotFoundError。在 Chrome 上,它工作正常。

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

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 也被调用。我也允许它需要的一切。

或者我不应该为这个项目使用 WebRTC。如果可以,我应该使用什么?

干杯!

最佳答案

Microsoft Edge 实现了 ORTC,它是 WebRTC 的低级分散表亲,没有总体 RTCPeerConnection 对象。

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

例如,这个演示适用于 Edge、Firefox 和 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>

关于javascript - RTCPeerConnection 是否适用于 Microsoft Edge?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36824585/

相关文章:

c# - uwp : how to change background color of listview item based on its value?

c# - 使计时器减少实际秒数

javascript - 通过 UDP 和 DataChannel 的 FFmpeg 到 WebRTC,实现低延迟屏幕共享

android - Opentok 存档问题?

javascript - Webpack:导出到窗口中的现有模块

javascript - 如何为具有相同类名的不同 div 应用 javascript 函数?

javascript - 我可以从 javascript 调用网络服务吗?

c# - 单个 ListView 中的多个列表

ffmpeg - h264 通过 WebRTC 延迟问题

javascript - Google Maps API v3 TypeScript 定义文件 bool 而不是 Boolean