thecowan / wallpanel-android

WallPanel is an Android application for Web Based Dashboards and Home Automation Platforms
https://wallpanel.app
Apache License 2.0
750 stars 103 forks source link

[FEATURE] JS-Exposed APIs #307

Closed Matchlighter closed 3 years ago

Matchlighter commented 3 years ago

It would be really nice if there was an option that could enable access to certain app-features from the the JS running on the loaded page. It would be super useful to have at least the following functionality exposed:

This feature would need some sort of whitelist functionality so that the functionality will only be exposed to trusted domains.

thanksmister commented 3 years ago

Yeah, this something that the HA application does, it has a channel interface used to communicate from the web page to commands in the application. MQTT already has discovery, just enable in the settings. I don't know what's the difference for a JS MQTT client and a regular MQTT client, its not clear what you mean. I think you have two different features here, one is discovery which already exists, the other is JS commands from the web site, which do not. However, you didn't suggest any command you would use with JS from the web page, given that discovery already exists.

Matchlighter commented 3 years ago

It varies from discovery. The idea here is for WallPanel to expose an MQTT interface to the JS. For example, if WallPanel set window.wallpanel, it might be something like:

// Publishing
wallpaenl.mqtt_publish('some/topic', 'PAYLOAD')
// Subscribing
const unsubscribe = wallpanel.mqtt_subscribe('some/other/topic/#', (message) => {
  // Do something with message
})
// ... and maybe call unsubscibe() later if the JS no longer wants to listen to that topic.

There are multiple commands that I would want to use from the web page, but an example would be setBrightness. I'm running a custom JS app in WallPanel. It would be really nice if I could configure the app to (for example) set the screen brightness depending on the time of day, rather than having to configure some third- system to send an MQTT message to do that.

thanksmister commented 3 years ago

If your webpage is a JS app, can you just use the http server for commands directly from the webpage?

https://github.com/thanksmister/wallpanel-android/wiki/MQTT-and-HTTP-Commands