withAutomaticReconnect method

HubConnectionBuilder withAutomaticReconnect([
  1. dynamic retryDelaysOrReconnectPolicy
])

Configures the HubConnection to automatically attempt to reconnect if the connection is lost.

Implementation

// ignore: avoid_returning_this
HubConnectionBuilder withAutomaticReconnect(
    [dynamic retryDelaysOrReconnectPolicy]) {
  if (reconnectPolicy != null) {
    throw Exception('A reconnectPolicy has already been set.');
  }

  if (retryDelaysOrReconnectPolicy == null) {
    reconnectPolicy = DefaultReconnectPolicy();
  } else if (retryDelaysOrReconnectPolicy is List) {
    reconnectPolicy = DefaultReconnectPolicy(
      retryDelays: retryDelaysOrReconnectPolicy as List<int>,
    );
  } else if (retryDelaysOrReconnectPolicy is RetryPolicy) {
    reconnectPolicy = retryDelaysOrReconnectPolicy;
  }

  return this;
}