【m】开发完成
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user