Remote UI: How to be notified on updated variable?

I would like to have an external UI to control my Mac from my smartphone (similar to Stream Deck or an improved version of BTT Remote).
We discussed this concept in depth a few years ago (

In order to change the remote UI dynamically it needs to know the current state in the Mac (e.g. the current active app or BTTActiveAppBundleIdentifier variable).

I wonder if there is a proper mechanism to achieve this.
The BTT Remote app seems to be notified on app change (which interface does it use to communicate remotely with the Mac? Is it available for custom-made interfaces?).
And local Floating Webviews have a function automatically injected (BTTNotification() ) that is called whenever a variable changes.

But from a custom app or HTML UI, the only option that I have found is to use the HTTP webserver interface and poll the current value of the variables continuously. But it creates an undesirable overload on the smartphone and Mac.

Is there any way to have a remote UI automatically notified on changes?
For example, a websocket that receives notifications on variable changes? or accessing the same interface that BTT Remote uses?