In the 3.9.0 release a new HasSubscribers
function was added to the Device
object allowing you to check if it is actively being used on the current page. This means that any Plugins polling HTTP REST APIs can perform conditional checks to see if it needs to send requests.
The function accepts an optional Attribute
argument in case there is a specific attribute you are targeting. By not providing an argument, it’ll check to see if any attributes are referenced.
Attached is a simple example. Toggle between the “Home” & “Test” tabs & watch the Log window.
HasSubscribers.hrp (96.2 KB)
var device = plugin.Devices["0"];
if (device.HasSubscribers()) {
console.log("yes");
}
else {
console.log("no");
}