简体   繁体   English

具有多个对等连接的 WebRTC - 现有对等连接之间的 Stream 在创建新连接时停止

[英]WebRTC with multiple Peer Connections - Stream between existing peer connections stop when a new connection is created

I am creating a video chat application for multiple users.The host initiates the call, when a second participant joins, a Peer Connection is created between host and the second participant.我正在为多个用户创建一个视频聊天应用程序。主持人发起呼叫,当第二个参与者加入时,在主持人和第二个参与者之间创建对等连接。

When the third person joins, Peer connections are created between 1 & 3 and 2 & 3 (n-1 peer connections for each client).当第三个人加入时,在 1 & 3 和 2 & 3 之间创建对等连接(每个客户端有 n-1 个对等连接)。 The new connection work as expected but the media streaming between 1 & 2 breaks.新连接按预期工作,但 1 和 2 之间的媒体流中断。

I am registering the appropriate event listeners for each peer connection with the index after the Peer Connection is created -在创建对等连接后,我正在使用索引为每个对等连接注册适当的事件侦听器 -

  peerConnection.onicecandidate = (event) => handleIceCanditate(pcIndex, event);
  peerConnection.ontrack = (event) => handleTrack(pcIndex, event);
  peerConnection.onnegotiationneeded = (event) => handleNegotiationNeeded(pcIndex, event);
  peerConnection.oniceconnectionstatechange = (event) => handleICEConnectionStateChange(pcIndex, event);
  peerConnection.onicegatheringstatechange = (event) => handleICEGatheringStateChange(pcIndex, event);
  peerConnection.onsignalingstatechange = (event) => handleSignalingStateChange(pcIndex, event); 

None of the events for the older Peer Connection with index 0 get fired before it stops working.在停止工作之前,索引为 0 的旧对等连接的任何事件都不会被触发。 Any leads on how to debug the issue.有关如何调试问题的任何线索。 The connection state of the older Peer Connection is connected旧Peer Connection的连接state是connected

This is resolved.The webRtc implementation works as expected, the issue was on the React front end layer.这已解决。webRtc 实现按预期工作,问题出在 React 前端层。

I was using React state that mapped the remote users to create the Video components that show the participants live feed.我正在使用 React state 映射远程用户来创建视频组件,以显示参与者的实时提要。 Because the function was being invoked on useEffects to create that list all the elements were being re-rendered.因为 function 在 useEffects 上被调用以创建该列表,所以所有元素都被重新渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM