PeerConnection创建不完整的报价

时间:2016-04-04 08:04:30

标签: javascript webrtc sdp

我正在尝试创建优惠,但我不完整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);});

1 个答案:

答案 0 :(得分:1)

我发现了两件事:

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

有关详细信息,请参阅https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection,尤其是正在初始化通话部分。