[英]Socket.IO emits inside emit aren't firing
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.我有一个发射,我试图设置游戏的当前 state,然后再发射几个发射。 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.我是 Socket.IO 的新手,所以我不太确定自己做错了什么。
Here is the emit within my app.js:这是我的 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.我也在 function 中尝试了一些控制台日志,但它们没有打印出来。
Here is my angular front end:这是我的 angular 前端:
this._gameService.socket.on('set_game_state', (newGameState: any) => {
this.currentGameState = newGameState;
});
I ended up modifying my front-end angular code with the following and it worked:我最终用以下代码修改了我的前端 angular 代码,它起作用了:
this._gameService.socket.on('set_game_state', (newGameState: any) => {
this.currentGameState = newGameState;
this.gameStateAck = () => ack();
this.gameStateAck();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.