init method

void init({
  1. List<String>? targetHosts,
  2. String? targetHost,
  3. Duration? interval,
  4. Duration? timeout,
  5. String? targetIp,
  6. int? targetPort,
})

Initialize the ping service with custom settings. Supports complete URLs, hostnames, or IP addresses with automatic extraction and failover so firewalls or content blockers never block the ping measurement.

Implementation

void init({
  List<String>? targetHosts,
  String? targetHost,
  Duration? interval,
  Duration? timeout,
  String? targetIp,
  int? targetPort,
}) {
  if (targetHosts != null && targetHosts.isNotEmpty) {
    _targetHosts = targetHosts.map(sanitizeHost).toList();
  } else if (targetHost != null) {
    _targetHosts = [sanitizeHost(targetHost), ...defaultPingHosts];
  } else if (targetIp != null) {
    _targetHosts = [sanitizeHost(targetIp), ...defaultPingHosts];
  }
  if (interval != null) _interval = interval;
  if (timeout != null) _timeout = timeout;
  _currentHostIndex = 0;
}