- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
亲爱的 friend 们,我正在尝试构建测试应用程序,该应用程序允许将浏览器窗口连接到自身(从用户摄像头传输视频数据)。最终结果是在页面上获取两个视频流,一个直接来自摄像头,一个来自摄像头。另一个来自浏览器在本地建立的 WebRTC 连接。我猜问题是实例化 RTCPeerconnection 对象时不会调用 onaddstream 方法,因此第二个屏幕不会从 window.URL.createObjectURL(e.stream); 接收 url
function hasUserMedia() {
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
return !!navigator.getUserMedia;
}
function hasRTCPeerConnection() {
window.RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
return !!window.RTCPeerConnection;
}
var yourVideo = document.querySelector('#yours'),
theirVideo = document.querySelector('#theirs'),
yourConnection, theirConnection;
if (hasUserMedia()) {
navigator.getUserMedia({ video: true, audio: false }, function (stream) {
yourVideo.src = window.URL.createObjectURL(stream);
if (hasRTCPeerConnection()) {
startPeerConnection(stream);
} else {
alert("Sorry, your browser does not support WebRTC.");
}
}, function (error) {
console.log(error);
});
} else {
alert("Sorry, your browser does not support WebRTC.");
}
function startPeerConnection(stream) {
var configuration = {
"iceServers": [{ "url": "stun:192.168.1.100:9876" }] // this is address of a local server
};
yourConnection = new mozRTCPeerConnection(configuration);
theirConnection = new mozRTCPeerConnection(configuration);
console.log(theirConnection);
// Setup stream listening
yourConnection.addStream(stream);
theirConnection.onaddstream = function (e) {
theirVideo.src = window.URL.createObjectURL(e.stream);
};
// Setup ice handling
yourConnection.onicecandidate = function (event) {
if (event.candidate) {
theirConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
}
};
theirConnection.onicecandidate = function (event) {
if (event.candidate) {
yourConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
}
};
// Begin the offer
yourConnection.createOffer(function (offer) {
yourConnection.setLocalDescription(offer);
theirConnection.setRemoteDescription(offer);
theirConnection.createAnswer(function (offer) {
theirConnection.setLocalDescription(offer);
yourConnection.setRemoteDescription(offer);
});
});
};
这是完整的代码:https://gist.github.com/johannesMatevosyan/8e4529fdcc53dd711479
这是它在浏览器中的样子:http://screencast.com/t/6dthclGcm
最佳答案
您的 onaddstream
事件未触发,因为您的连接尚未启动,您必须先完成提供/应答流程,然后才能触发该事件。我在 Firefox 41.0.2 中尝试了您的代码,但未创建优惠,因为您缺少错误回调方法,请尝试以下操作:
function error () { console.log('There was an error'); };
yourConnection.createOffer(function (offer) { console.log('Offer:'); console.log(offer);
yourConnection.setLocalDescription(offer);
theirConnection.setRemoteDescription(offer);
theirConnection.createAnswer(function (answer) { console.log('Answer:'); console.log(answer);
theirConnection.setLocalDescription(answer);
yourConnection.setRemoteDescription(answer);
}, error);
}, error);
关于javascript - RTCPeerconnection对象实例化后不执行onaddstream方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34795582/
我最近一直在研究 webRTC,并且正在创建一个抽象层,以便通过网状网络架构轻松获得多个客户端通信。 我的问题是关于创建数据通道。目前我执行以下操作: var pc = new RTCPeerConn
我知道网络浏览器对同时 http 请求的数量等有限制。但是对于打开的 RTCPeerConnection 的网页可以拥有的数量也有限制吗? 并且有些相关:RTCPeerConnection 允许通过
我正在尝试检测 RTCPeerConnection 的另一端何时断开连接。目前我正在对我的 RTCPeerConnection 对象执行以下操作: rtcPeerConnection.onicecon
有谁知道有什么好的RTCPeerConnection教程? 我想在浏览器之间直播网络摄像头。我有 websocket从我的服务器到所有客户端的连接,所以它应该相当容易 - 但到目前为止我在该主题上发现
我正在尝试检测 RTCPeerConnection 的另一端何时断开连接。目前我正在对我的 RTCPeerConnection 对象执行以下操作: rtcPeerConnection.onicecon
我可以使用以下代码创建一个新的对等连接对象: var peer = new RTCPeerConnection(); 发生这种情况时,chrome 在 chrome://webrtc-internal
建立首次成功的 RTC 连接的最佳方法是什么? 下面的代码有时有效,有时无效。我认为这是在 createAnswer 之前或之后调用 addIceCandidate 的问题,而且我不知道哪个更好,或者
我开始用 rtcPeerConnection 做一些测试,我是这个技术的初学者,我想知道它是否正常:在控制台中,当调用方法 onicecandidate 时,我打印了 ice candidate,但我
我正在我的 chrome 浏览器中运行 WebRTC 演示,我已经可以设置视频 session 了。但是,如果其中一个对等点断开连接(例如刷新浏览器),我不知道如何在另一端检测到它(并且可能会警告“对
如何更改代码,使计算机1的代码连接到计算机2的代码(计算机1和计算机2不是同一台计算机,但在同一网络上)。 它在本地工作,但在两台不同的计算机上不工作 用于连接的计算机 1 和计算机 2 代码定义如下
这是著名的 Chromium bug:https://bugs.chromium.org/p/chromium/issues/detail?id=825576 错误是:无法构造“RTCPeerConn
我正在 Javascript 中运行一些 RTC(在 Chrome 上),我希望能够看到所有打开的 RTCPeerCONnections(或任何处于任何事件状态的)。显然我可以将它们列为已创建的,但我
下面我摘录了this link关于 RTCPeerConnection.onicecandidate 并希望根据我的理解提出两个问题,如果我的概念正确与否,则需要帮助。对我来说有点复杂 The RTC
我正在创建一个应用程序,它将使用 WebRTC 将相机视频共享到多个对等连接。服务器只是为用户提供了一个房间,房间里的所有用户都会看到摄像头视频。唯一不起作用的是 onicecandidate 没有触
这个问题已经有答案了: RTCPeerConnection.createAnswer callback returns undefined object in mozilla for WebRTC c
我有一个非常简单的 RTCPeerConnection 应用在运行。使用 Firebase 发送信号。 RTCPeerConnections 建立,然后我获取流,并对其执行以下操作: let stre
有没有人看到过这个错误,字面意思是: “Uncaught DOMException: Failed to construct 'RTCPeerConnection': Cannot create so
我得到了一个RTCPeerConnection,建立连接后我想断开与网络服务器的连接。 如何检查已建立的连接? readyState 始终是 undefined 并且 onopen 从未触发。 最佳答
我接触 WebRTC 时遇到了一个问题,即 RTCPeerConnection.ontrack 事件不会在创建新的 MediaStreamTrack 对象时触发(通过 RTCPeerConnectio
我的简单 WebRTC javascript 代码没有按预期工作。事实上,音频通话并没有建立(请注意,我对 WebRTC 了解最少,我是通过查看互联网上的示例创建的)。该页面应启动两个参与者之间的音频
我是一名优秀的程序员,十分优秀!