2012-10-16 40 views
0

整合JSEP我发现这个video conferencing prototype。但是由于ROAP协议已被JSEP取代,我无法运行它。中的WebRTC演示

我曾尝试使用以下资源来解决这个问题:

Example ROAP and JSEP

ROAP on JSEP

我想很多人会喜欢有一个工作JSEP例子建。

<script> 
    var socket = new WebSocket('ws://mydomain.com:1337'); 
    var sourcevid = document.getElementById('sourcevid'); 
    var remotevid = document.getElementById('remotevid'); 
    var localStream = null; 
    var peerConn = null; 
    var started = false; 

    var logg = function(s) { console.log(s); }; 

    // when PeerConn is created, send setup data to peer via WebSocket 
    function onSignal(message) { 
     logg("Sending setup signal"); 
     socket.send(message); 
    } 

    // when remote adds a stream, hand it on to the local video element 
    function onRemoteStreamAdded(event) { 
    logg("Added remote stream"); 
    remotevid.src = window.webkitURL.createObjectURL(event.stream); 
    } 

    // when remote removes a stream, remove it from the local video element 
    function onRemoteStreamRemoved(event) { 
    logg("Remove remote stream"); 
    remotevid.src = ""; 
    } 

    function createPeerConnection() { 
    try { 
     logg("Creating peer connection"); 
     peerConn = new webkitDeprecatedPeerConnection("STUN stun.l.google.com:19302", onSignal); 
    } catch (e) { 
     try { 
     peerConn = new webkitPeerConnection00("STUN stun.l.google.com:19302", onSignal); 
     } catch (e) { 
     console.log("Failed to create PeerConnection, exception: " + e.message); 
     } 
    } 
    peerConn.addEventListener("addstream", onRemoteStreamAdded, false); 
    peerConn.addEventListener("removestream", onRemoteStreamRemoved, false) 
    } 

    // start the connection upon user request 
    function connect() { 
    if (!started && localStream) { 
     createPeerConnection(); 
     logg('Adding local stream...'); 
     peerConn.addStream(localStream); 
     started = true; 
    } else { 
     alert("Local stream not running yet."); 
    } 
    } 

    // accept connection request 
    socket.addEventListener("message", onMessage, false); 
    function onMessage(evt) { 
    logg("RECEIVED: "+evt.data); 
    if (!started) { 
     createPeerConnection(); 
     logg('Adding local stream...'); 
     peerConn.addStream(localStream); 
     started = true; 
    } 
    // Message returned from other side 
    logg('Processing signaling message...'); 
    peerConn.processSignalingMessage(evt.data); 
    } 

    function hangUp() { 
    logg("Hang up."); 
    peerConn.close(); 
    peerConn = null; 
    started = false; 
    } 

    function startVideo() { 
     // Replace the source of the video element with the stream from the camera 
     try { //try it with spec syntax 
     navigator.webkitGetUserMedia({audio: true, video: true}, successCallback, errorCallback); 
     } catch (e) { 
     navigator.webkitGetUserMedia("video,audio", successCallback, errorCallback); 
     } 
     function successCallback(stream) { 
      sourcevid.src = window.webkitURL.createObjectURL(stream); 
      localStream = stream; 
     } 
     function errorCallback(error) { 
      console.error('An error occurred: [CODE ' + error.code + ']'); 
     } 
    } 
    function stopVideo() { 
    sourcevid.src = ""; 
    } 
    </script> 

回答

0

apprtc.appspot.com的示例显示WebRTC与JSEP一起使用。

还有一个ROAP to JSEP library在使用JSEP API抽象DeprecatedPeerConnection。

+1

虽然此链接可以回答这个问题,最好是在这里有答案的主要部件,并提供链接以供参考。如果链接页面更改,则仅链接答案可能会失效。 – LittleBobbyTables

+0

对不起 - 通过我的手机在火车上快速添加答案!现在添加更多细节。 –

+0

谢谢你的回复。我只是不明白我如何使用webSocket来使用ROAP到JSEP库(在本例中为pc1&pc2)在两个对等方之间进行通信。 – user574199