Skip to content

Commit 118ae6d

Browse files
committed
Reconnect Coordinator always + SFU WS only if during the call + reset reconnection scheduler when WS is being disconnected
1 parent feb9b1b commit 118ae6d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Packages/StreamVideo/Runtime/Core/LowLevelClient/ReconnectScheduler.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ internal interface IReconnectScheduler
88
{
99
double? NextReconnectTime { get; }
1010
event Action ReconnectionScheduled;
11+
12+
void Reset();
1113
}
1214
/// <summary>
1315
/// Schedules next reconnection time based on the past attempts and network availability
@@ -43,8 +45,9 @@ private set
4345
}
4446

4547
public ReconnectScheduler(ITimeService timeService, IStreamVideoLowLevelClient lowLevelClient,
46-
INetworkMonitor networkMonitor)
48+
INetworkMonitor networkMonitor, Func<bool> shouldReconnect)
4749
{
50+
_shouldReconnect = shouldReconnect ?? throw new ArgumentNullException(nameof(shouldReconnect));
4851
_client = lowLevelClient ?? throw new ArgumentNullException(nameof(lowLevelClient));
4952
_timeService = timeService ?? throw new ArgumentNullException(nameof(timeService));
5053
_networkMonitor = networkMonitor ?? throw new ArgumentNullException(nameof(networkMonitor));
@@ -98,6 +101,12 @@ void ThrowIfLessOrEqualToZero(float value, string name)
98101
}
99102
}
100103

104+
public void Reset()
105+
{
106+
NextReconnectTime = default;
107+
_reconnectAttempts = 0;
108+
}
109+
101110
public void Stop()
102111
{
103112
NextReconnectTime = float.MaxValue;
@@ -112,6 +121,7 @@ public void Stop()
112121
private int _reconnectAttempts;
113122
private bool _isStopped;
114123
private double? _nextReconnectTime;
124+
private Func<bool> _shouldReconnect;
115125

116126
private void TryScheduleNextReconnectTime()
117127
{
@@ -120,7 +130,7 @@ private void TryScheduleNextReconnectTime()
120130
return;
121131
}
122132

123-
if (_isStopped || ReconnectStrategy == ReconnectStrategy.Never)
133+
if (_isStopped || ReconnectStrategy == ReconnectStrategy.Never || !_shouldReconnect())
124134
{
125135
return;
126136
}

Packages/StreamVideo/Runtime/Core/LowLevelClient/StreamVideoLowLevelClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public StreamVideoLowLevelClient(IWebsocketClient coordinatorWebSocket, IWebsock
143143
}
144144

145145
//StreamTodo: move to factory
146-
var coordinatorReconnect = new ReconnectScheduler(_timeService, this, _networkMonitor);
147-
var sfuReconnect = new ReconnectScheduler(_timeService, this, _networkMonitor);
146+
var coordinatorReconnect = new ReconnectScheduler(_timeService, this, _networkMonitor, shouldReconnect: () => true);
147+
var sfuReconnect = new ReconnectScheduler(_timeService, this, _networkMonitor, shouldReconnect: () => RtcSession.ActiveCall != null);
148148

149149
//StreamTodo: move to factory
150150
_coordinatorWS = new CoordinatorWebSocket(coordinatorWebSocket, coordinatorReconnect, authProvider: this,

Packages/StreamVideo/Runtime/Core/LowLevelClient/WebSockets/BasePersistentWebSocket.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ protected void OnHealthCheckReceived()
228228

229229
protected virtual Task OnDisconnectingAsync(string closeMessage)
230230
{
231+
_reconnectScheduler.Reset();
231232
return Task.CompletedTask;
232233
}
233234

0 commit comments

Comments
 (0)