Jac*_*Guy 3 javascript webcam webrtc peerjs
我正在使用 PeerJS 及其云托管服务器来构建 WebRTC 应用程序。这是我的代码:
navigator.getMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
window.URL = window.URL || window.webkitURL;
var callSettings = {
video: {
mandatory: {
maxWidth: 400,
maxHeight: 300
}
},
audio: true
};
$(document).ready(function ()
{
var videoel = $("#teacher-stream")[0];
$(document).on('click', ".start-call", function () //A button initiates call
{
var peerID = $(this).data('id'); //Button contains ID of peer
navigator.getMedia(callSettings, function (stream)
{
var call = peer.call(peerID, stream);
call.on('stream', function(remoteStream)
{
console.log('stream!');
videoel.src = window.URL.createObjectURL(remoteStream);
//On stream copy data to video el
});
});
});
peer.on('call', function(call)
{
console.log('got call');
navigator.getMedia(callSettings, function(stream)
{
call.answer(stream);
call.on('stream', function(remoteStream)
{
videoel.src = window.URL.createObjectURL(remoteStream);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
流启动,并且要求两个用户授予网络摄像头访问权限。但是,过去仅显示第一帧。尽管 Chrome 选项卡上的脉冲记录图标仍然显示,但不会显示更多帧。“流!” 上面的日志只添加一次。
我尝试在本地托管服务器以检查是否是问题所在,但事实并非如此。我错过了什么?
归档时间: |
|
查看次数: |
1068 次 |
最近记录: |