Plugin "HasSubscribers" Function

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");
}
3 Likes

This is pretty cool! Out of curiosity, would it be possible to provide a list of Attributes and if any of them are subscribed, it returns true? I was going to integrate this into my Roku plugin and, as I was thinking it through, I realized that some pages might only wanted to access “MediaCommands”, others might want “InputSource” and/or "“TvChannel”, just as an example.

Perhaps in the future. For now you’d have to split those into separate calls & do something like this:

if (device.HasSubscribers("InputSource")) {
    console.log("poll for input");
}

if (device.HasSubscribers("TvChannel.Name") || device.HasSubscribers("TvChannel.Number")) {
    console.log("poll for TV channel");
}