HSNetworkConfigurationWatcher
TypeA watcher for System Configuration dynamic store key changes. Create with hs.network.configurationWatcher().
Properties
Methods
setKeys(keys, pattern) -> HSNetworkConfigurationWatcher
Specifies which dynamic store keys (or key patterns) to watch for changes.
Must be called before `start()`. Each element of `keys` is treated as a string literal
when `pattern` is `false` (the default), or as a regular expression when `pattern` is `true`.
Calling `setKeys` again replaces the previous set of watched keys.
Declaration
setKeys(keys, pattern) -> HSNetworkConfigurationWatcher
Parameters
| Name | Type | Description |
|---|---|---|
| keys | string[] | An array of exact key strings (when `pattern` is `false`) or regular expressions (when `pattern` is `true`). |
| pattern | boolean | Pass `true` to treat each element of `keys` as a regular expression; omit or pass `false` for literal key matching. |
Returns
HSNetworkConfigurationWatcher
This watcher for chaining.
Example
// Watch a specific literal key
hs.network.configurationWatcher()
.setKeys(["State:/Network/Global/IPv4"])
.setCallback((w, keys) => console.log(JSON.stringify(hs.network.configurationStore("State:/Network/Global/IPv4"))))
.start()
// Watch all State:/Network keys by pattern
hs.network.configurationWatcher()
.setKeys(["State:/Network/.*"], true)
.setCallback((w, keys) => console.log("Changed: " + keys.join(", ")))
.start()
setCallback(callback) -> HSNetworkConfigurationWatcher
Sets the callback invoked when a watched key changes.
The callback receives `(watcher, changedKeys)` where `changedKeys` is an array of key
strings that changed since the last notification. Call `hs.network.configurationStore()`
inside the callback to read the updated values.
Declaration
setCallback(callback) -> HSNetworkConfigurationWatcher
Parameters
| Name | Type | Description |
|---|---|---|
| callback | function | Called whenever a watched key changes. |
Returns
HSNetworkConfigurationWatcher
This watcher for chaining.
Example
w.setCallback((w, keys) => {
const vals = hs.network.configurationStore(keys[0])
console.log(JSON.stringify(vals))
})
start() -> HSNetworkConfigurationWatcher
Starts watching for dynamic store changes.
The callback registered with `setCallback()` will be invoked whenever a key matching the
patterns registered with `setKeys()` changes. Call `setKeys()` and `setCallback()` before
calling `start()`.
Declaration
start() -> HSNetworkConfigurationWatcher
Returns
HSNetworkConfigurationWatcher
This watcher for chaining.
Example
w.start()
stop() -> HSNetworkConfigurationWatcher
Stops watching for dynamic store changes.
The callback will no longer be invoked. Call `start()` again to resume monitoring.
Declaration
stop() -> HSNetworkConfigurationWatcher
Returns
HSNetworkConfigurationWatcher
This watcher for chaining.
Example
w.stop()