gpt4 book ai didi

javascript - PeerConnection 创建不完整的报价

转载 作者:行者123 更新时间:2023-12-03 07:16:44 24 4
gpt4 key购买 nike

我正在尝试创建报价,但我得到的 sdp-offer 不完整,如下所示

sdp:
"v=0↵o=- 981077471509521330 2 IN IP4 127.0.0.1
↵s=-
↵t=0 0
↵a=msid-semantic: WMS
↵"

我错过了什么。我的代码如下

//适配器部分

window.RTCPeerConnection = window.RTCPeerConnection || 
window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
window.RTCIceCandidate = window.RTCIceCandidate ||
window.mozRTCIceCandidate || window.webkitRTCIceCandidate;
window.RTCSessionDescription = window.RTCSessionDescription ||
window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
window.URL = window.URL || window.mozURL || window.webkitURL;
window.navigator.getUserMedia = window.navigator.getUserMedia ||
window.navigator.webkitGetUserMedia || window.navigator.mozGetUserMedia;

创建 sdp 流

var iceConfig = {'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }]};
var pc = new RTCPeerConnection(null);
pc.onicecandidate = function (evnt) {
socket.emit('video', {ice: evnt.candidate, type: 'ice' });
};
pc.onaddstream = function(evnt) {
$rootScope.remotestream = evnt.stream;
$rootScope.$broadcast('remotestream');
};
pc.createOffer(function(offer) {console.log(offer);});

最佳答案

我发现的两件事:

  • 需要向RTCPeerConnection添加本地流:pc.addStream(localStream);,localStream通常是通过navigator.getUserMedia()获取的
  • >
  • 您需要将 iceConfig 作为第一个参数传递给 RTCPeerConnection 构造函数

有关更多信息,请参阅 https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection ,尤其是初始化调用部分。

关于javascript - PeerConnection 创建不完整的报价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36397380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com