【问题标题】:Integrate JSEP in WebRTC Demo在 WebRTC Demo 中集成 JSEP
【发布时间】:2012-10-06 18:21:42
【问题描述】:

我找到了这个video conferencing prototype。但我无法让它运行,因为 ROAP 协议已被 JSEP 取代。

我已尝试使用以下来源解决问题:

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>

【问题讨论】:

    标签: websocket webrtc


    【解决方案1】:

    apprtc.appspot.com 的示例显示了 WebRTC 与 JSEP 的作用。

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

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    • 对不起 - 在火车上通过我的手机快速添加答案!现在添加了更多细节。
    • 感谢您的回复。我只是不明白如何使用 webSocket 使用 ROAP 到 JSEP 库(在本例中为 pc1 和 pc2)在两个对等方之间进行通信。
    • WebSocket 可用于通过中间服务器发送信号,而对等点之间的流数据的实际通信是通过 RTCPeerConnection 完成的。信令是对等点之间交换网络和媒体数据的“握手”/启动过程。 (同行还需要发现彼此——就像会议参与者共享电话会议号码一样——在apprtc.appspot.com 等示例中,这只需通过“呼叫者”向“被呼叫者”提供具有标识符的 URL 即可完成。)一切顺利完成后,RTCPeerConnection 就可以发挥它的 P2P 魔力了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    相关资源
    最近更新 更多