public async Task Check(IRelayServerConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            var logger = _logger?
                         .ForContext("RelayServerUri", connection.Uri)
                         .ForContext("RelayServerConnectionInstanceId", connection.RelayServerConnectionInstanceId);

            if ((connection.TokenExpiry - connection.TokenRefreshWindow) <= DateTime.UtcNow)
            {
                logger?.Information("Access token is going to expire soon. Trying to refresh token for RelayServer {RelayServerUri} with connection instance id {RelayServerConnectionInstanceId}");

                try
                {
                    if (!await connection.TryRequestAuthorizationTokenAsync().ConfigureAwait(false))
                    {
                        throw new AuthenticationException();
                    }
                }
                catch (AuthenticationException)
                {
                    logger?.Warning("Could not renew access token and trying a hard reconnect. relay-server={RelayServerUri}, relay-server-connection-instance-id={RelayServerConnectionInstanceId}");

                    connection.Reconnect();
                }
            }
        }
        public void Check(IRelayServerConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            var logger = _logger?
                         .ForContext("RelayServerUri", connection.Uri)
                         .ForContext("RelayServerConnectionInstanceId", connection.RelayServerConnectionInstanceId);

            var lastHeartbeat = connection.LastHeartbeat;

            if (lastHeartbeat != DateTime.MinValue && lastHeartbeat != DateTime.MaxValue)
            {
                if (lastHeartbeat <= DateTime.UtcNow.Subtract(connection.HeartbeatInterval.Add(TimeSpan.FromSeconds(2))))
                {
                    logger?.Warning("Did not receive expected heartbeat. last-heartbeat={LastHeartbeat}, heartbeat-interval={HeartbeatInterval}, relay-server={RelayServerUri}, relay-server-connection-instance-id={RelayServerConnectionInstanceId}", lastHeartbeat, connection.HeartbeatInterval);

                    connection.Reconnect();
                }
            }
        }