webrtc onaddstream not being called on first peer
我创建了下面的脚本,它是混合应用程序的一部分,有时它运行正常,我可以接收/发送音频/视频呼叫,但有时甚至没有从发送方调用 onaddstream 或 ontrack,但是 spd 数据包是通过套接字发送的,我都尝试了 (onaddstream or ontrack) 但没有成功:
在这里发送来自 pc 的报价:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
sendOffer() {
let that = this; that.call_status = ‘connecting’; let call_type; that.pc = new RTCPeerConnection(that.peerConnectionConfig); that.pc.oniceconnectionstatechange = function (e) { that.call_status = that.pc.iceConnectionState; that.pc.onaddstream = e => { that.pc.onicecandidate = e => { if (e.candidate) { that.socket.on(‘sdp-offer-reply’, (sdp: any) => { that.socket.on(‘call-closed’, (sdp: any) => { |
在其他设备上 pc2 接受答案时:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
answerCall() {
let that = this; let call_type; that.pc2 = new RTCPeerConnection(this.peerConnectionConfig); that.pc2.oniceconnectionstatechange = function (e) { if (that.pc2.signalingState !=”stable”) { that.pc2.setRemoteDescription(new RTCSessionDescription(({ type:”offer”, sdp: this.sdp.sdp })))
that.socket.on(‘call-closed’, (sdp: any) => { |
这是我调用的最终函数,用于在通话结束时关闭双方的对等连接:
1
2 3 4 5 6 7 8 |
closeConnection() {
if (typeof this.pc !==”undefined” && this.pc.signalingState !=”closed”) { this.pc.close(); } if (typeof this.pc2 !==”undefined” && this.pc2.signalingState !=”closed”) { this.pc2.close(); } } |
我正在使用 webrtc latest-adapter.js 和 socket.io 作为信号服务器。首先,我在 pc 上发出事件 以发送 sdp 数据包,在 pc2 上我从节点服务器接收 sdp-offer-incoming,然后 pc2 发出 offeraccepted 并在 pc1 上附加带有事件的 sdp 数据接收 sdp 数据包,它应该在两台电脑上显示视频/音频,但有时发送方没有收到流,但接收方总是有两个视频。
创建报价时我必须通过约束:
1
2 3 4 |
this.pc.createOffer({
offerToReceiveAudio: 1, offerToReceiveVideo: 1 }) |
- 你是怎么想出来的,mdn没有在任何地方提到这个
- 你好你在吗
- 这太糟糕了,我有 {mandatory: {offerToReceiveVideo}} 并且它失败了。现在 api 遇到了问题,直到我修复了上面的那个,它才起作用……失去了我生命中的 10 个小时……
- 这需要更多的选票。我一直在努力让 webrtc 为我的 react-native 应用程序工作 DAYS,这是唯一错误的事情。
- 我找到了一些引用这些参数的文档:jasonkang14.github.io/posts/webrtc/…
来源:https://www.codenong.com/45467511/