Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用webkitPeerConnection00的远程网络摄像头流是';t显示_Javascript_Html_Html5 Video_Webrtc - Fatal编程技术网

Javascript 使用webkitPeerConnection00的远程网络摄像头流是';t显示

Javascript 使用webkitPeerConnection00的远程网络摄像头流是';t显示,javascript,html,html5-video,webrtc,Javascript,Html,Html5 Video,Webrtc,我正在尝试对等网络摄像头通信的示例代码,其中两个客户端都在同一页面中实现 “本地”网络摄像头流显示正确。然而,“远程”流上没有显示任何内容,我不知道为什么 下面是我的代码。我目前正在一台托管服务器上测试它。谢谢 var localStream; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.

我正在尝试对等网络摄像头通信的示例代码,其中两个客户端都在同一页面中实现

“本地”网络摄像头流显示正确。然而,“远程”流上没有显示任何内容,我不知道为什么

下面是我的代码。我目前正在一台托管服务器上测试它。谢谢

var localStream;

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
    navigator.mozGetUserMedia || navigator.msGetUserMedia;

window.URL = window.URL || window.webkitURL;

navigator.getUserMedia({'audio':true, 'video':true}, onMediaSuccess, onMediaFail);

function onMediaSuccess(stream) {
    var localVideo = document.getElementById("localVideo");
    var url = window.URL.createObjectURL(stream);
    localVideo.autoplay = true;
    localVideo.src = url;
    localStream = stream;
    console.log('Local stream established: ' + url);
}

function onMediaFail() {
    alert('Could not connect stream');
}

function iceCallback1(){}
function iceCallback2(){}

function gotRemoteStream(e) {
    var remoteVideo = document.getElementById("remoteVideo");
    var stream = e.stream;
    var url = window.URL.createObjectURL(stream);
    remoteVideo.autoplay = true;
    remoteVideo.src = url;
    console.log('Remote stream received: ' + url);
}   

function call(){

    pc1 = new webkitPeerConnection00(null, iceCallback1);   // create the 'sending' PeerConnection
    pc2 = new webkitPeerConnection00(null, iceCallback2);   // create the 'receiving' PeerConnection

    pc2.onaddstream = gotRemoteStream;                      // set the callback for the receiving PeerConnection to display video

    console.log("Adding local stream to pc1");
    pc1.addStream(localStream);                             // add the local stream for the sending PeerConnection

    console.log("Creating offer");
    var offer = pc1.createOffer({audio:true, video:true});  // create an offer, with the local stream

    console.log("Setting local description for pc1");
    pc1.setLocalDescription(pc1.SDP_OFFER, offer);          // set the offer for the sending and receiving PeerConnection

    console.log("Start pc1 ICE");
    pc1.startIce();

    console.log("Setting remote description for pc2");
    pc2.setRemoteDescription(pc2.SDP_OFFER, offer);

    // gotRemoteStream Triggers here

    console.log("Creating answer");                         // create an answer
    var answer = pc2.createAnswer(offer.toSdp(), {has_audio:true, has_video:true});

    console.log("Setting local description for pc2");   
    pc2.setLocalDescription(pc2.SDP_ANSWER, answer);        // set it on the sending and receiving PeerConnection 

    console.log("Setting remote description for pc1");
    pc1.setRemoteDescription(pc1.SDP_ANSWER, answer);

    console.log("Start pc2 ICE");
    pc2.startIce();                                         // start the connection process

    console.log("script done");
}
试试这个:

siml.info rtpeerconnection
由Vikas Marwaha和Justin Uberti编写


它对我来说工作得很好,而且非常简洁。

不要对STUN/TURN协议/server使用空值——使用这个:var pc1=new-webkitPeerConnection00('STUN-STUN.l.google.com:19302',iceCallback2);--如果不处理ice候选者,就无法获得远程流!谢谢你的回复!这是我正在尝试的一个本地示例(按照教程页面上的代码)。既然“本地客户端”和“远程客户端”在同一个页面上,那么现在还不需要STUN服务器和ice候选服务器吗?(我个人的意见!)所有WebRTC应用程序都需要一个中间服务器(不管是SIP还是libjingle)进行第一次握手——在当前的RTCWeb API中,我们可以使用两种协议:STUN和TURN——我认为这些协议的目的是为每个对等方生成唯一的ice候选。现在,开发人员的工作是在同行中处理/通过这些候选人。如果你想在本地测试;您必须在本地计算机上安装此类服务器(SIP/LibJingle)。我找到了一些迷你SIP客户端,但它们不适合我!你可以通过这个实验来测试我的电脑:-它可以在连接到一个调制解调器的电脑上正常工作------但不能在不同的IP地址上工作。(你知道每个调制解调器都有唯一的IP!)我明白了,几天前我试用了你的应用程序,但似乎无法让它工作。在另一个例子中,我尝试为握手实现一个websocket服务器,但我不知道如何处理ice候选者。您是否将其与报价/答案一起发送?