微信PC端使用WebRTC相关接口时, 连接建立失败, 无法打开数据通道
发布于 5 年前 作者 guiyingcao 5021 次浏览 来自 官方Issues

操作系统: Windows7 Service Pack 1(64位)

PC端微信版本: 2.9.5.41 

============== 第一种情况: 连接建立失败, 无法打开数据通道 ==============

PC端Chrome浏览器 主动连接 PC端微信, 连接建立失败, 数据通道打开失败

重现步骤:

在PC端Chrome中:

1.创建RTCPeerConnection对象: peerConn

2.通过peerConn创建DataChannel对象: dataChannel, 并配置其onopen回调处理   

  dataChannel = peerConn.createDataChannel(‘test_p2p_connection’, {negotiated: true, id: 0});

3.配置peerConn.onicecandidate收集本地icecandidate信息

4.调用peerConn.createOffer收集到localOffer信息, 调用peerConn.setLocalDescription(localOffer)

  并将收集到的localOffer信息提交给Server, 以便推送给其它连接端

5.将收集到的本地icecandidate信息提交给Server, 以便推送给其它连接端

6.等待Server推送answer sdp回应信息

7.收到Server推送的answer sdp回应信息, 调用peerConn.setRemoteDescription(remoteAnswer)设置对端answer sdp信息

8.调用peerConn.addIceCandidate添加对端icecandidate信息

9.一直不触发dataChannel.onopen回调, 连接建立失败, 数据通道无法打开

在PC端微信中: 

1.收到Server推送的remoteOffer与icecandidate, 创建RTCPeerConnection对象: peerConn

2.通过peerConn创建DataChannel对象: dataChannel, 并配置其onopen回调处理   

  dataChannel = peerConn.createDataChannel(‘test_p2p_connection’, {negotiated: true, id: 0});

3.配置peerConn.onicecandidate收集本地icecandidate信息

4.调用peerConn.setRemoteDescription(remoteOffer)设置对端offer sdp信息

5.调用peerConn.addIceCandidate添加对端icecandidate信息

6.调用peerConn.createAnswer收集到localAnswer信息, 调用peerConn.setLocalDescription(localAnswer)

  并将收集到的localAnswer信息提交给Server, 以便推送给对端

7.将收集到的本地icecandidate信息提交给Server, 以便推送给对端

8.等待连接的建立

9.一直不触发dataChannel.onopen回调, 连接建立失败, 数据通道无法打开

简单描述第一种情况:

PC端Chrome浏览器调用RTCPeerConnection.createOffer作为建立连接的邀请方, 

PC端微信作为被邀请方, 调用RTCPeerConnection.createAnswer进行回应, 连接建立失败, 数据通道无法打开

============== 第二种情况: 连接建立成功, 并可以打开数据通道 ==============

PC端微信 主动连接 PC端Chrome浏览器, 连接建立成功, 可以打开数据通道

重现步骤:

在PC端微信中: 

1.创建RTCPeerConnection对象: peerConn

2.通过peerConn创建DataChannel对象: dataChannel, 并配置其onopen回调处理   

  dataChannel = peerConn.createDataChannel(‘test_p2p_connection’, {negotiated: true, id: 0});

3.配置peerConn.onicecandidate收集icecandidate信息

4.调用peerConn.createOffer收集到localOffer信息, 调用peerConn.setLocalDescription(localOffer)

  并将收集到的localOffer信息提交给Server, 以便推送给其它连接端

5.将收集到的icecandidate信息提交给Server, 以便推送给其它连接端

6.等待Server推送answer sdp回应信息

7.收到Server推送的answer sdp回应信息, 调用peerConn.setRemoteDescription(remoteAnswer)设置对端answer sdp信息

8.调用peerConn.addIceCandidate添加对端icecandidate信息

9.连接建立成功, 数据通道打开成功(dataChannel.onopen被触发)

在PC端Chrome中:

1.收到Server推送的remoteOffer与icecandidate, 创建RTCPeerConnection对象: peerConn

2.通过peerConn创建DataChannel对象: dataChannel, 并配置其onopen回调处理   

  dataChannel = peerConn.createDataChannel(‘test_p2p_connection’, {negotiated: true, id: 0});

3.配置peerConn.onicecandidate收集icecandidate信息

4.调用peerConn.setRemoteDescription(remoteOffer)设置对端offer sdp信息

5.调用peerConn.addIceCandidate添加对端icecandidate信息

6.调用peerConn.createAnswer收集到localAnswer信息, 调用peerConn.setLocalDescription(localAnswer)

  并将收集到的localAnswer信息提交给Server, 以便推送给对端

7.将收集到的本地icecandidate信息提交给Server, 以便推送给对端

8.等待连接的建立

9.连接建立成功, 数据通道打开成功(dataChannel.ondatachannel被触发)

简单描述第二种情况:

PC端微信调用RTCPeerConnection.createOffer作为建立连接的邀请方, 

PC端Chrome浏览器作为被邀请方, 调用RTCPeerConnection.createAnswer进行回应, 可以成功建立连接并打开数据通道

回到顶部