Socket.IO emits inside emit aren't firing

Viewed 28

I have an emit where I'm trying to set the current state of the game, and then fire a few more emit after that. For some reason, none of the subsequent emits are working. I am new to Socket.IO so I'm not really sure what I'm doing wrong.

Here is the emit within my app.js:

socket.emit('set_game_state', 'Lobby', () => {
            socket.emit('reconnect');
            socket.emit('set_cookie', player);
            socket.emit('player', player);
        });

I've tried some console logs inside of the function as well and they don't print out.

Here is my angular front end:


this._gameService.socket.on('set_game_state', (newGameState: any) => {
  this.currentGameState = newGameState;
});
1 Answers

I ended up modifying my front-end angular code with the following and it worked:

this._gameService.socket.on('set_game_state', (newGameState: any) => {
  this.currentGameState = newGameState;
  this.gameStateAck = () => ack();
  this.gameStateAck();
});
Related