HSNetworkReachability
TypeAn active or inactive network reachability monitor. Create with hs.network.reachability*().
Properties
Methods
status() -> number
Returns the current reachability flags as a numeric bitmask.
Compare against constants in `hs.network.reachabilityFlags`. Returns `0` if the
network is currently unreachable.
Declaration
status() -> number
Returns
number
A number representing the current reachability bitmask.
Example
const r = hs.network.reachabilityInternet()
const f = hs.network.reachabilityFlags
console.log("Reachable: " + ((r.status() & f.reachable) !== 0))
statusString() -> string
Returns a human-readable summary of the current reachability flags.
The string contains 8 characters in order: `t` (transient/expensive), `R` (reachable),
`c` (connectionRequired), `C` (connectionOnTraffic — always `-`), `i` (interventionRequired/constrained),
`D` (connectionOnDemand — always `-`), `l` (isLocalAddress — always `-`), `d` (isDirect).
A letter appears when that flag is set; `-` appears when it is clear.
Declaration
statusString() -> string
Returns
string
An 8-character flag string such as `"-R-----d"`.
Example
const r = hs.network.reachabilityInternet()
console.log(r.statusString()) // e.g. "-R-----d"
setCallback(callback) -> HSNetworkReachability
Replaces the callback invoked when reachability changes.
The callback receives `(reachability, flags)` where `flags` is the same numeric
bitmask as returned by `status()`. Call `start()` after `setCallback()` to begin
monitoring.
Declaration
setCallback(callback) -> HSNetworkReachability
Parameters
| Name | Type | Description |
|---|---|---|
| callback | function | Called on each reachability status change. |
Returns
HSNetworkReachability
This reachability object for chaining.
Example
hs.network.reachabilityInternet()
.setCallback((r, flags) => console.log(r.statusString()))
.start()
start() -> HSNetworkReachability
Starts monitoring for reachability changes.
After calling `start()`, the callback registered with `setCallback()` is invoked
whenever the reachability status changes.
Declaration
start() -> HSNetworkReachability
Returns
HSNetworkReachability
This reachability object for chaining.
Example
hs.network.reachabilityInternet()
.setCallback((r, flags) => console.log(r.statusString()))
.start()
stop() -> HSNetworkReachability
Stops monitoring for reachability changes.
The callback will no longer be invoked. Call `start()` again to resume monitoring.
Declaration
stop() -> HSNetworkReachability
Returns
HSNetworkReachability
This reachability object for chaining.
Example
r.stop()