I am working on a game that is highly dependent on sockets. I want to create a socket connection to stay open even if the client has not logged in.
The game has one admin and few players. Admin has the right to override the player. So the below is the node js code in the backend of admin file (it just trigger socket in the player file) if admin choose to override the player:
serverfile.app.io.route('forceForward', req => {
req.io
.room(req.session.user.game_id)
.broadcast('gameforced');
console.log('broadcast game force');
}
);
Here server file is the file which is running the app and it contains the library express.io
with the var name app.
Below is the Javascript code which is triggered in the players front end screen:
socket.on('gameforced', function() {
socket.emit('buy', 0);
window.location.replace('/buyer_wait')
});
The code works fine and triggers the socket buy in the player file backend if the player is logged in but if the player is not logged in the socket doesn't work. Any suggestions.
Thanks