API Docs

An 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.
status() -> number
number
A number representing the current reachability bitmask.
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.
statusString() -> string
string
An 8-character flag string such as `"-R-----d"`.
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.
setCallback(callback) -> HSNetworkReachability
Name Type Description
callback function Called on each reachability status change.
HSNetworkReachability
This reachability object for chaining.
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.
start() -> HSNetworkReachability
HSNetworkReachability
This reachability object for chaining.
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.
stop() -> HSNetworkReachability
HSNetworkReachability
This reachability object for chaining.
r.stop()