Tuesday 27 August 2019

Building a "use status indicator" app, want to make it real-time. Is sockets.io my best option?

Hey all. I'm making a ridiculously simple app to show the "in use" status of an account I share with a friend. Right now I have it built using express and a mongodb database that stores a single object that represents the current user of the account. The interface for updating this value is basically just three boxes on a page that contain text indicating the user, and some DOM event listeners that update the color of whichever box gets selected. This in turn updates the value in the database so that the "use state" is persistent. I have it so that on page load, the app queries the DB and the current user is indicated in the aforementioned manner. However, if the user value is updated, the browser must be refreshed to guarantee that the new user will be indicated accurately.I was looking into sockets.io to make the background color of the boxes update in real time - so if my friend were to log on and indicate that he's using the account, I'd be able to see the change in real time. This is my ultimate goal - to be able to see any change to the use status (as indicated by my app) in real time. Right now everything works as expected - page load accurately reflects the current use state of the account, and I can update the use state and view its status - I just have to refresh the browser to check for any changes to the status made by the other user.I know that the scope of this project is really simple and kinda silly, but I'm using it as an opportunity to play with some back-end stuff in a low-stakes way. I'm willing to share some code if anyone is curious or particulars are necessary for getting a better idea of what I'm talking about.Thanks in advance for your help!

Submitted August 27, 2019 at 02:43PM by TiredOfMakingThese

No comments:

Post a Comment