RTCPeerConnection 是不是在 Microsoft Edge 中工作?
Posted
技术标签:
【中文标题】RTCPeerConnection 是不是在 Microsoft Edge 中工作?【英文标题】:Does RTCPeerConnection work in Microsoft Edge?RTCPeerConnection 是否在 Microsoft Edge 中工作? 【发布时间】:2016-04-24 14:43:43 【问题描述】:我目前正在使用 WebRTC 开发 VoIP。这将是一个用 javascript 编写的 UWP 应用程序。
现在,我正在尝试通过在 Microsoft Edge 上测试来自 https://webrtc.github.io/samples 的样本来检查它是否有效。
事实证明它工作正常除了RTCPeerConnection
。
例如,当我在 Edge 中打开 https://webrtc.github.io/samples/src/content/peerconnection/audio 时,当我单击通话按钮时,它给了我 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。如果是这样,我应该使用什么?
干杯!
【问题讨论】:
您的摄像头/麦克风似乎有问题。检查 navigator.mediaDevices.enumerateDevices 的输出,例如使用this demo 【参考方案1】:Microsoft Edge 实现了 ORTC,它是 WebRTC 的一个更底层的去中心化表亲,它没有总体 RTCPeerConnection
对象。
但好消息是adapter.js,官方 WebRTC 填充程序,在 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" autoplay muted></video>
<video id="video2" autoplay></video><br>
<div id="div"></div>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
【讨论】:
【参考方案2】:您应首先检查您的隐私设置,以允许 Edge 访问您的媒体设备。 https://privacy.microsoft.com/en-us/windows-10-camera-and-privacy
【讨论】:
以上是关于RTCPeerConnection 是不是在 Microsoft Edge 中工作?的主要内容,如果未能解决你的问题,请参考以下文章
WebRTC的RTCPeerConnection()原理探析
当不同网络上的对等点时,RTCPeerConnection 失败
实例化 RTCPeerconnection 对象后不执行 onaddstream 方法
WebRTC 无法在控制台上的 RTCPeerConnection 错误上执行“addIceCandidate”,但仍可以显示远程和本地视频
iOS 上的 webRTC:无法发送 SDP 应答,RTCPeerConnection.setRemoteDescription() 失败