From 5729b42cc15dd05d7406d70239329b1ffae2bf8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sierpi=C5=84ski?= <33436839+sierpinskid@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:13:53 +0200 Subject: [PATCH 1/2] Fix network monitor not raising any events --- .../StreamChat/Core/LowLevelClient/ReconnectScheduler.cs | 2 ++ .../StreamChat/Core/LowLevelClient/StreamChatLowLevelClient.cs | 2 ++ .../StreamChat/Libs/NetworkMonitors/UnityNetworkMonitor.cs | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Assets/Plugins/StreamChat/Core/LowLevelClient/ReconnectScheduler.cs b/Assets/Plugins/StreamChat/Core/LowLevelClient/ReconnectScheduler.cs index 175bf6c6..9ad3d3b5 100644 --- a/Assets/Plugins/StreamChat/Core/LowLevelClient/ReconnectScheduler.cs +++ b/Assets/Plugins/StreamChat/Core/LowLevelClient/ReconnectScheduler.cs @@ -60,6 +60,8 @@ public void Dispose() _client.Reconnecting -= OnReconnecting; _client.ConnectionStateChanged -= OnConnectionStateChanged; } + + _networkMonitor.NetworkAvailabilityChanged -= OnNetworkAvailabilityChanged; } public void SetReconnectStrategySettings(ReconnectStrategy reconnectStrategy, float? exponentialMinInterval, diff --git a/Assets/Plugins/StreamChat/Core/LowLevelClient/StreamChatLowLevelClient.cs b/Assets/Plugins/StreamChat/Core/LowLevelClient/StreamChatLowLevelClient.cs index 49892720..a44d7a1d 100644 --- a/Assets/Plugins/StreamChat/Core/LowLevelClient/StreamChatLowLevelClient.cs +++ b/Assets/Plugins/StreamChat/Core/LowLevelClient/StreamChatLowLevelClient.cs @@ -348,6 +348,8 @@ public async Task DisconnectAsync(bool permanent = false) public void Update(float deltaTime) { + _networkMonitor?.Update(); + #if !STREAM_TESTS_ENABLED _updateCallReceived = true; #endif diff --git a/Assets/Plugins/StreamChat/Libs/NetworkMonitors/UnityNetworkMonitor.cs b/Assets/Plugins/StreamChat/Libs/NetworkMonitors/UnityNetworkMonitor.cs index 3dd25957..9e5ab27c 100644 --- a/Assets/Plugins/StreamChat/Libs/NetworkMonitors/UnityNetworkMonitor.cs +++ b/Assets/Plugins/StreamChat/Libs/NetworkMonitors/UnityNetworkMonitor.cs @@ -30,7 +30,7 @@ public void Update() return; } - var wasReachable = IsReachable(_lastState.Value); + var wasReachable = IsReachable(prevLastState.Value); if (wasReachable && !isReachable) { From 094fe2fefd7b2875f99eb624ed55aecacd37d689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sierpi=C5=84ski?= <33436839+sierpinskid@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:14:56 +0200 Subject: [PATCH 2/2] remove redundant NetworkReachability from the example project - SDK now uses the INetworkMonitor that relies on NetworkReachability internally --- .../Scripts/StreamChatClientBehaviour.cs | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/Assets/Plugins/StreamChat/SampleProject/Scripts/StreamChatClientBehaviour.cs b/Assets/Plugins/StreamChat/SampleProject/Scripts/StreamChatClientBehaviour.cs index e74ed4fb..462cf905 100644 --- a/Assets/Plugins/StreamChat/SampleProject/Scripts/StreamChatClientBehaviour.cs +++ b/Assets/Plugins/StreamChat/SampleProject/Scripts/StreamChatClientBehaviour.cs @@ -80,27 +80,6 @@ protected void Awake() } } - protected void Update() - { - if (_client == null || _missingCredentials) - { - return; - } - - var isClientConnectedOrConnecting = _client.ConnectionState == ConnectionState.Connected || - _client.ConnectionState == ConnectionState.Connecting; - - var isNetworkReachable = - Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork || - Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork; - - if (!isClientConnectedOrConnecting && isNetworkReachable) - { - Debug.LogWarning("Client is not connected, but network is reachable. Force reconnect."); - _client.ConnectUserAsync(_authCredentialsAsset.Credentials); - } - } - private IStreamChatClient _client; private bool _missingCredentials;