System Improvement - Web App with WebSockets
In this thread I will be posting updates on this particular work in progress, feel free to reply with suggestions & ideas
Description:
For some time now, I've been wanting to improve one of the functionalities of the ChipChop Web App.
At the moment to get the current status of your devices the Web App is using Ajax and requests a status update from the ChipChop engine on a 10 seconds interval.
That's all fine a peachy because the maximum devices heartbeat interval is 10 sec so at worst you maybe seeing your device status few seconds later than it was broadcast by the device.
But, if you initiate a "trigger event" (they execute instantly) you will not see that reflected in the Web App interface until the next update request cycle happens. For basic use that's absolutely fine, the trigger event will still happen in real-time in the background and it's just a matter seeing it happen.
I mean who needs to stare at the phone waiting to see if a motion sensor has detected motion...right? (yeah, that would be me and I have valid reasons :-)
So...why do I care if the current Ajax method has been working fine for a very long time? Because it can be made better, because Ajax is a http request and they are expensive...and, because I can!
The right solution is to use WebSockets and have a real-time bi-directional communication between the WebApp and the ChipChop engine so trigger-events can be sent instantly to the Web App as they happen.
How difficult is that? Technically, not a big deal, in reality, It's a royal pain in the ass. It needs to keep track in real time who exactly is observing their devices through the WebApp, which devices that belong to that account are on-line and forwarding the trigger events to the exact socket...and all of that without blocking or slowing down anything.
So, I'm rolling up the sleeves and digging into the crap bucket. Let's see how deep this rabbit hole goes :-)