How to use SSE -Server Side Events- in Ionic App (openhab)

I am creating an app to control my smarthome devices. My smarthome runs on the basis of openhab. To switch smarthome devices and query their status openhab provides a rest api.
For the HTTP requests I used this plugin:

So there are no problems with CORS.

Switching the devices or initial requesting the status of a device works fine.

Openhab also provides a SSE. You can subscribe to it via an event source. This way you always get automatically status changes of the devices.

With Openhab you have to authenticate with the basic variant.
There I already encounter the first problem. To subscribe to the event bus my request looks like this:
But Chrome forbids this variant. See image.

However, I don’t know of any other variant to send this information with an event source.

Does anyone know of a variant in an Ionic app, perhaps with a plugin, to subscribe to such an SSE? Also that no CORS problems arise.

Many greetings

Maybe not exactly the same, and maybe a bit too much out of the box, but let me share my solution for this anyways. :slight_smile:

I have managed to solve this by using Firebase Realtime Database. The client-app can directly listen to DB / collection / record changes. When a change is triggered, the client is informed instantly about the the update. (Even with offline support. )

Remark: My main database is not a Firebase Database at this moment, but i am just using the Firebase RTDB for this SSE purpose only. The only thing that needs do be done when my clients need to be informed of a change, Is to update a specific record that contains a timestamp where all subscribers are listening to.

As soon as that timestamp is updated (ie. via the api, or a manual update of the record), all clients receive a signal that it’s time to refresh it’s data. (Which can be done in the reqular way by fetching) Works flawless! And no CORS-issues obviously

1 Like