【发布时间】:2019-03-04 23:17:36
【问题描述】:
我使用 WebRTC 构建了一个简单的流媒体服务。我目前仍在通过 localhost 运行所有内容。目前使用 Chrome 浏览器时一切正常,但使用 Firefox 时无法连接。我正在使用 WebRTC-Adapter 垫片。
问题似乎源于 peerConnection.localDescription 始终等于 null,并且无法将我的 localDescription 发送给对等方,或正确设置 remoteDescription。
这是我的代码的 sn-p。这仅涵盖正在启动 p2p 连接的流的接收者。流媒体已经设置了本地流,并设置了自己的本地和远程描述,然后将 localDescription 发送给接收者。 sendRecipientDescription() 只处理通过套接字将 sdp 发送到流媒体。 PC_Config 只包含一个 STUN 服务器:
setUpRecipient = () => {
this.createPeerConnection();
this.pc
.createOffer({ offerToReceiveVideo: true })
.then(offer => {
this.pc.setLocalDescription(offer);
})
.then(() => {
this.sendRecipientDescription();
console.log('recipient local description ', this.pc.localDescription);
})
.catch(e => {
console.log('error recipient set up ', e);
});
};
createPeerConnection = () => {
try {
this.pc = new RTCPeerConnection(PC_CONFIG);
this.pc.onicecandidate = this.handleIceCandidate;
this.pc.ontrack = this.handleRemoteStreamAdded;
this.pc.onremovetrack = this.handleRemoteStreamRemoved;
this.pc.oniceconnectionstatechange = this.handleIceStateChange;
console.log('Created RTCPeerConnection', this.pc.localDescription);
} catch (e) {
console.log('Failed to create PeerConnection, exception: ', e.message);
}
};
使用 Chrome 浏览器时,this.pc.localDescription 按预期返回。使用火狐浏览器时,this.pc.localDescription 始终为null,根本没有RTCSessionDescription。当我在 setLocalDescription 之后 console.log(this.pc) 时,似乎 localDescription 确实为空:RTCPeerConnection un-expanded
但是,当我展开 RTCPeerConnection 对象时,您会看到 localDescription 似乎设置正确:RTCPeerConnection expanded。但是,当我尝试发送 this.pc.localDescription 时,它只发送 null。
【问题讨论】:
标签: javascript google-chrome firefox webrtc