0

I have an application that consists of three parts: a Python server application, a web front end that is connected to the Python tool via WebSocket, and a second website that is connected to the first website via local storage. The first page transfers its status via local storage to the second page, which then switches accordingly.

Since i want to run this pages on two screens in kiosk mode and this only seems to work if you use different browsers or different profiles in chrome, i want to search for an alternative of local.Storage to get the same result.

The local storage approach was just the first thing that came into my mind and since its just a local application i did not bother about security. Also the nice thing about it is that with jquery the event is triggered with every change of the storage.

status.js (Website 1)

function setStatus(status) {
  localStorage.setItem("status", status);
}

toggle.js (website 2)

$( document ).ready(function() {
    var showslide = localStorage.status;
    toggleSlide(showslide);
});

$( window ).on('storage',function(){
    var showslide = localStorage.status;
    toggleSlide(showslide); 
});

function toggleSlide(showslide) {
 //toggle part with animations/fade 
}

This works very well and was easy. Is there a simple alternative that yould be used by two different browsers? Would be the existing websocket connection the right way?

3
  • The simplest might just be to have a session key, then read and write in local storage under that session key. But it seems you should just be using a websocket and connect both sites to the same server. Not sure why you've set up relay via localstorage, there. Commented 2 days ago
  • its been a while since i did it and i really also dont know why i did it like this. i think i had the localstorage first and then added a python application via websocket. i might change the websocket to have a json structure and then add a listener so changes - that could do the job. Commented 2 days ago
  • It seems a bit of needless complexity in the frontend. Both apps are effectively sharing the same state using localstorage. If you persist the state on the backend and have both apps connect to it, you could remove this complexity. Commented 2 days ago

1 Answer 1

0

Thank you for the comments.

My solution to get rid of localstorage:

  1. I use websockets changed the message to json which now transports the initial message and the status.

  2. I changed the websocket server so it now allows for communication between clients and also broadcasts everything that is sent to the server to all clients.

  3. For the clients js i keep the variables that i dont want to change (message) and just send them again with the json structure. the big benefit is now that i could reduce functions to clean the message and i have more control and flexability

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.