Skip to content

Commit 4c61f80

Browse files
authored
Pbe 4247 fix network monitor (#153)
* Fix network monitor not raising any events * remove redundant NetworkReachability from the example project - SDK now uses the INetworkMonitor that relies on NetworkReachability internally
1 parent 1687d88 commit 4c61f80

4 files changed

Lines changed: 5 additions & 22 deletions

File tree

Assets/Plugins/StreamChat/Core/LowLevelClient/ReconnectScheduler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public void Dispose()
6060
_client.Reconnecting -= OnReconnecting;
6161
_client.ConnectionStateChanged -= OnConnectionStateChanged;
6262
}
63+
64+
_networkMonitor.NetworkAvailabilityChanged -= OnNetworkAvailabilityChanged;
6365
}
6466

6567
public void SetReconnectStrategySettings(ReconnectStrategy reconnectStrategy, float? exponentialMinInterval,

Assets/Plugins/StreamChat/Core/LowLevelClient/StreamChatLowLevelClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ public async Task DisconnectAsync(bool permanent = false)
348348

349349
public void Update(float deltaTime)
350350
{
351+
_networkMonitor?.Update();
352+
351353
#if !STREAM_TESTS_ENABLED
352354
_updateCallReceived = true;
353355
#endif

Assets/Plugins/StreamChat/Libs/NetworkMonitors/UnityNetworkMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Update()
3030
return;
3131
}
3232

33-
var wasReachable = IsReachable(_lastState.Value);
33+
var wasReachable = IsReachable(prevLastState.Value);
3434

3535
if (wasReachable && !isReachable)
3636
{

Assets/Plugins/StreamChat/SampleProject/Scripts/StreamChatClientBehaviour.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,6 @@ protected void Awake()
8080
}
8181
}
8282

83-
protected void Update()
84-
{
85-
if (_client == null || _missingCredentials)
86-
{
87-
return;
88-
}
89-
90-
var isClientConnectedOrConnecting = _client.ConnectionState == ConnectionState.Connected ||
91-
_client.ConnectionState == ConnectionState.Connecting;
92-
93-
var isNetworkReachable =
94-
Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork ||
95-
Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork;
96-
97-
if (!isClientConnectedOrConnecting && isNetworkReachable)
98-
{
99-
Debug.LogWarning("Client is not connected, but network is reachable. Force reconnect.");
100-
_client.ConnectUserAsync(_authCredentialsAsset.Credentials);
101-
}
102-
}
103-
10483
private IStreamChatClient _client;
10584
private bool _missingCredentials;
10685

0 commit comments

Comments
 (0)