init method
void
init({})
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;
}