I'm quite new to programming, and it is only a hobby for now.
I have used firebase through ports for a while and it works fine, but I would love to use firebase in a more functional / elm way + avoid writing any javascript.
I have made a simple native module that works fine, but this is suboptimal since native/kernal code should be avoided as much as possible and the javascript firebase client is very object oriented.
So this week I started builing a pure elm implementation of the Google firebase client, without using native/kernal code.
Trying to start with the minimal implementation just to get something working and then build on from there.
The effectmodule uses elm Websocket.LowLevel to communicate with firebase.
Status now:
Opening and closing of the firebase websocket connection is done automatically based on whether there is active subscriptions in the Main program or not.
I can subscribe to multiple firebase database locations/paths and the effectmodule will send the updated data to the correct subscription in my elm program.
I can also write firebase data by sending commands to the effectmodule. Large multi websocket frame messages is also working.
My problem:
Subscription is cancelled if nothing is sent for about a minute.
To keep the firebase subscription live a value has to be sent every 45 second. So if there is no activity I need to send a websocket frame with "0" if it has been more that 45seconds since last firebase data frame. (The same way as the javascript client works)
I'm having problems solving this. Does anyone have an idea how to solve this? I guess if there is no activity in the elm program It will not trigger "onEffects" and "onSelfMessage" in the effectmodule?
It can be handled in the main elm program, but I feel lowlevel stuff like websocket keepalive belongs in the firebase package/effectmodule. ?
Is it possible to use subscriptions inside an effect-module in some way? (subscribe to the Time package)
Is it possible to spawn a separate process that sleeps for 45sec and then change the sleep time everytime a websocket frame is sent? :)