javascript - SocketIO App 在 Heroku 上表现异常但在本地工作
问题描述
我登录了服务器和客户端应用程序。
组件在单击时会发出 SocketIO 事件。现在第一个客户端(打开到页面的第一个窗口)单击该组件,我在服务器上看到收到事件的日志,在客户端上看到发送事件的日志。
现在有趣的是,当我复制选项卡时,服务器注册了一个新用户(套接字连接成功)但是当我单击组件时,没有消息说事件已发送但组件确实改变了颜色。
我在 setState 的回调中发送 SocketIO 事件和 console.logging 消息。
有问题的组件是一个单元格。
这是我的代码:
handleOnCellClick() {
if (!this.state.alive) {
// if dead then proceed add some color to the Cell's life :) and notify server of event
console.log("cell wasn't alive");
this.setState(
{
r: this.props.defaultRandomColorProps[0],
g: this.props.defaultRandomColorProps[1],
b: this.props.defaultRandomColorProps[2],
alive: true
},
() => {
this.props.socketProps.emit("cellChanged", {
key: [this.props.cell_row_index, this.props.cell_col_index],
color: { r: this.state.r, g: this.state.g, b: this.state.b }
});
console.log("emitted");
}
);
}
}
事实上,请在secret-forest-30430.herokuapp.com/上亲自查看。导航到游戏选项卡。它包含一个单元组件的“板”。
我必须再次重申,这整件事在当地有效。这是 github 上项目的链接:https ://github.com/Dobermensch/ExpressTest.git
知道发生了什么吗?
TL;DR:setState 回调不起作用?
编辑:为了退后一步,我正在尝试创建多人康威的生命游戏
解决方案
推荐阅读
- asp.net - 从 ASP.net 发送电子邮件在 IIS 服务器上失败
- spring-boot - 在 Spring Cloud Stream Kafka 中正确管理 DLQ
- cmd - 如何将HOMEDRIVE从H盘设置到C盘
- auth0 - Zapier 未从令牌响应中获取额外请求的字段
- android - FrameLayout 的宽度永远不会真正为 0
- android - Firebase 存储创建重复文件夹?
- rstudio - DT 包列过滤器在 RMarkdown HTML 中不起作用
- excel - VBA:countif不工作-范围错误?
- python - 对 CSV 文件进行数字排序
- ethereum - 如何在 Web3 中切换当前帐户