I have an application with a base controller, base html and base javascript file. In this three a create a token with unique client id (create_channel) and I pass the token to the template and create the connection in the javascript file.
Then I send a message to this connection. If I stay in the same page it works well and I see the message but if I go to other page the base.js is load again and new connection is started so I never see the message that I sent from the server.
Any idea how can I resolve this issue? I only want to create one connection but the base file is load more times…
Each “user” has to have an ID. I use the session ID. Then you create the token against that only if it does not already exist.
So when you go to a different page you don’t create a new channel if one already is available for that user_Id. When the user navigates away you’ll get a disconnect/connect each time. And you can use the
user_idto send the message regardless of what page they are on.