HSWifiWatcher
TypeA Wi-Fi event watcher that monitors changes to a Wi-Fi interface.
Create via hs.wifi.addWatcher(). Set a callback with setCallback(), then
call start() to begin receiving events. By default only "ssidChange" is
watched; use the events property to watch other event types.
The callback receives (event, info):
| Event | Info keys |
|---|---|
"ssidChange" |
interface: string |
"bssidChange" |
interface: string |
"countryCodeChange" |
interface: string |
"linkChange" |
interface: string |
"linkQualityChange" |
interface: string, rssi: number, transmitRate: number |
"modeChange" |
interface: string |
"powerChange" |
interface: string |
"scanCacheUpdated" |
interface: string |
Example:
const w = hs.wifi.addWatcher()
w.setCallback((event, info) => {
console.log(event + " on " + info.interface)
}).start()
Properties
events
string[]
The event types this watcher will invoke its callback for. Defaults to
`["ssidChange"]`. Unrecognized values are ignored with a console warning;
see `hs.wifi.watcherEventTypes` for the list of valid values. Can be
changed while the watcher is running.
Methods
start() -> HSWifiWatcher
Starts monitoring the event types configured in `events`.
Declaration
start() -> HSWifiWatcher
Returns
HSWifiWatcher
self, for chaining
Example
const w = hs.wifi.addWatcher()
w.setCallback((ev, info) => console.log(ev)).start()
stop() -> HSWifiWatcher
Stops monitoring Wi-Fi events.
Declaration
stop() -> HSWifiWatcher
Returns
HSWifiWatcher
self, for chaining
Example
w.stop()
setCallback(fn) -> HSWifiWatcher
Sets the callback function invoked when a watched Wi-Fi event occurs.
Declaration
setCallback(fn) -> HSWifiWatcher
Parameters
| Name | Type | Description |
|---|---|---|
| fn | function | Called with the event name and an info dictionary; see type documentation for event names and info keys. |
Returns
HSWifiWatcher
self, for chaining
Example
w.setCallback((event, info) => {
if (event === "powerChange") console.log("power changed on " + info.interface)
})
destroy() -> None
Stops the watcher and releases all resources. Called automatically during shutdown.
Declaration
destroy() -> None
Returns
None
Example
w.destroy()