Web Sockets / EventSource

I'm curious if we could have a widget at some point utilize a web sockets or event source API (or perhaps MQTT) as these models would be good for pushing status updates to BTT for updating the touch bar and would remove polling for internet services that support those subscription models.

Battery life hasn't been an issue for me, but it would be nice to get more to the second updates for specific things I have in my touchbar vs. having stale data until the next refresh rate.

Have a look at the scripting api:
https://docs.bettertouchtool.net/docs/scripting_btt.html

This currently doesn't include websockets, but the webserver should already be good enough for most use cases (I have already included basic websocket support, but not yet enabled it because I'm not sure if it would really add many advantages over the integrated webserver api).

I'm not quite sure I'm following. My feature request is more to have features that would allow widgets to be updated via push messages from a server instead of polling. Ideally with some type of subscription model.

I.E - BTT would listen to a web socket address, digests messages and if messages pertain to a touchbar widget the widget would automatically update. So no need for setting a refresh interval for digestible services that support websockets or other things such as MQTT.

1 Like

Ah sorry I misunderstood your usecase.
Yep that would be an interesting feature, I'll look into that.

Well you can achieve that with a little node library that I'm developing: https://github.com/worie/btt-node - it basically is a wrapper for current API for BTT built in webserver.

You can hook it up to socket.io or anything and communicate with it. Surely built in mechanism would be better, but you can already achieve it without too much hussle using mentioned package :slight_smile:

1 Like

cool! :slight_smile:

@Worie could you please give me an example of how one could listen for websocket data from an external server to trigger something in BTT with your project?

I don't think I'll be able to provide you with a full working example, but that would be just like any node.js app that works with websockets - on specific event, trigger code available from the library