Syncing frontend instances?

So I have a project that involves OBS browser source as an overlay and I need a dashboard as a backup control of the overlay. Is the best solution using websockets and having dashboard and overlay instances on separate web servers? Both instances would be ran on the host computer.
18 Replies
Jochem
Jochem8mo ago
you may want to look at that particle demo that floated around a while ago, it used localstorage I think? https://twitter.com/_nonfigurativ_/status/1727340311490265209 I thought they went into more detail than this
MartynasXS
MartynasXS8mo ago
I guess i can use local storage yeah
Jochem
Jochem8mo ago
looks like they just store data in localstorage, and listen to the storage event to update local state: https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event
MDN Web Docs
Window: storage event - Web APIs | MDN
The storage event of the Window interface fires when a storage area (localStorage or sessionStorage) has been modified in the context of another document.
Jochem
Jochem8mo ago
if it's guaranteed to run on the same machine, in different windows of the same browser, it's probably by far the easiest way. Sockets would be very complicated just to share a little data for an overlay
MartynasXS
MartynasXS8mo ago
Hmm i wonder how I would have to execute the events oh nvm i can just have data in a variable and if something changes in the local storage update and that will act as an event
Jochem
Jochem8mo ago
yup, the window.storage event fires whenever there's a change in localstorage
MartynasXS
MartynasXS8mo ago
oh i didnt even know that yeah its a desktop app, I just have webserver cuz i run svelte and the url is the way you add the overlay into OBS
Jochem
Jochem8mo ago
the event even tells you what changed, so that's extra nice
MartynasXS
MartynasXS8mo ago
thanks for the help ❤️
Jochem
Jochem8mo ago
no problem!
MartynasXS
MartynasXS8mo ago
also this way its probably better to have two webservers right? one only write to local storage other to only read
Jochem
Jochem8mo ago
I wouldn't call it webservers, the page in your browser is the one interacting with localstorage... But you could probably get away with both writing in this particular case, cause you won't be clicking on buttons at the exact same time anyway
MartynasXS
MartynasXS8mo ago
Cuz the way i originally thought of doing it was having it all in the same frontend just adding a class to all the controls that would just get display:hidden css applied in OBS
Jochem
Jochem8mo ago
that'll likely be fine, yeah
MartynasXS
MartynasXS8mo ago
eh now that i think of it I do have to have them separate I need to make api calls to the game api to fetch data having it on both instances would make double the calls
Want results from more Discord servers?
Add your server