相关疑难解决方法(0)

为什么WebRTC远程视频源由URL.createObjectURL生成

本文档中,它用于URL.createObjectURL设置视频源.(这是接听电话的代码).

var offer = getOfferFromFriend();
navigator.getUserMedia({video: true}, function(stream) {
  pc.onaddstream = e => video.src = URL.createObjectURL(e.stream);
  pc.addStream(stream);

  pc.setRemoteDescription(new RTCSessionDescription(offer), function() {
    pc.createAnswer(function(answer) {
      pc.setLocalDescription(answer, function() {
        // send the answer to a server to be forwarded back to the caller (you)
      }, error);
    }, error);
  }, error);
});
Run Code Online (Sandbox Code Playgroud)

我希望video.src成为检索远程视频的地址.所以它应该由连接的另一端(无论是谁发起呼叫)修复和给出.但价值URL.createObjectURL回答者的一边产生,它的事件取决于函数被调用的时间.如何使用它来获取远程视频流?

编辑:URL.createObjectURL看起来像blob 的结果:http://some.site.com/xxxx-the-token-xxxx.使用此字符串,视频组件如何知道加载远程流的位置?是否存在{url:stream}的哈希映射?如果是这样,视频组件如何访问hashmap?

流对象确实存储了一个令牌字符串,您可以使用该字符串stream.toURL.但它与结果不同URL.createObjectURL.价值URL.createObjectURL取决于时间.如果连续两次调用它,则会得到不同的值.

webrtc

2
推荐指数
1
解决办法
1679
查看次数

标签 统计

webrtc ×1