【m】开发完成

This commit is contained in:
2026-04-30 23:27:34 +08:00
parent c0dd21b524
commit f04556e609
3 changed files with 13 additions and 8 deletions

View File

@@ -97,6 +97,8 @@ namespace Unity.RenderStreaming
public override void DeleteConnection(string connectionId) public override void DeleteConnection(string connectionId)
{ {
// 清理所有Participant连接 // 清理所有Participant连接
// 注意:不能在这里调用 base.DeleteConnection(participantId)否则会给每个Participant发送disconnect
// 导致服务器返回多次通知。应该只发一次disconnect关闭房间Participant的清理由服务器通知触发。
foreach (var participantId in participantIds.ToList()) foreach (var participantId in participantIds.ToList())
{ {
DisconnectParticipant(participantId); DisconnectParticipant(participantId);
@@ -152,10 +154,10 @@ namespace Unity.RenderStreaming
if (m_participantStreams.TryGetValue(participantId, out var ps)) if (m_participantStreams.TryGetValue(participantId, out var ps))
{ {
// 移除Sender关联 // 移除Sender关联
foreach (var sender in streams.OfType<IStreamSender>()) // foreach (var sender in streams.OfType<IStreamSender>())
{ // {
RemoveSender(participantId, sender); // RemoveSender(participantId, sender);
} // }
// 移除Receiver关联 // 移除Receiver关联
if (ps.videoReceiver != null) if (ps.videoReceiver != null)
RemoveReceiver(participantId, ps.videoReceiver); RemoveReceiver(participantId, ps.videoReceiver);

View File

@@ -395,7 +395,9 @@ namespace Unity.RenderStreaming
peer.OnConnectHandler += () => onConnect?.Invoke(connectionId); peer.OnConnectHandler += () => onConnect?.Invoke(connectionId);
peer.OnDisconnectHandler += () => peer.OnDisconnectHandler += () =>
{ {
_signaling?.CloseConnection(connectionId); // PeerConnection失败时不自动发送disconnect避免重复断开通知。
// 主动断开由 Handler 的 DeleteConnection 触发,远端断开由服务器的 disconnect 消息触发。
// 这里只触发 onDisconnect 事件通知 Handler 进行资源清理。
onDisconnect?.Invoke(connectionId); onDisconnect?.Invoke(connectionId);
}; };
peer.OnDataChannelHandler += channel => onAddChannel?.Invoke(connectionId, channel); ; peer.OnDataChannelHandler += channel => onAddChannel?.Invoke(connectionId, channel); ;
@@ -473,10 +475,11 @@ namespace Unity.RenderStreaming
void OnParticipantLeftHandler(ISignaling signaling, ParticipantEventData e) void OnParticipantLeftHandler(ISignaling signaling, ParticipantEventData e)
{ {
// 参与者离开时销毁对应的PeerConnection // 参与者离开时,销毁对应的PeerConnection不触发onDeletedConnection事件
// 因为onParticipantLeft已经会通知Handler进行资源清理避免重复通知
if (_mapConnectionIdAndPeer.ContainsKey(e.participantId)) if (_mapConnectionIdAndPeer.ContainsKey(e.participantId))
{ {
DestroyConnection(e.participantId); DeletePeerConnection(e.participantId);
} }
onParticipantLeft?.Invoke(e.connectionId, e.participantId); onParticipantLeft?.Invoke(e.connectionId, e.participantId);
} }

View File

@@ -160,7 +160,7 @@ namespace Unity.RenderStreaming
{ {
m_transceivers.Remove(connectionId); m_transceivers.Remove(connectionId);
OnStoppedStream?.Invoke(connectionId); OnStoppedStream?.Invoke(connectionId);
if (!m_transceivers.Any()) if (!m_transceivers.Any() && m_track.ReadyState == TrackState.Live)
{ {
m_track.Dispose(); m_track.Dispose();
m_track = null; m_track = null;