提交 55e358ed 编写于 作者: YYYTDMS's avatar YYYTDMS

304_完成心跳机制验证

上级 071d0224
......@@ -130,6 +130,9 @@ class TwoPlayerPKStudy extends Component {
this.parseParams(params);
}
}
if (data.type === 'HEART_BEAT') {
console.log('Heartbeat is checked.');
}
if (data.type === 'YOU_WIN') {
this.setState({isStarted: false, victories: this.state.victories + 1});
}
......@@ -263,6 +266,7 @@ class TwoPlayerPKStudy extends Component {
ifContinuable = () => {
const ready = websocket.get().readyState;
websocket.heartbeat();
if (ready !== WebSocket.OPEN) {
clearInterval(this.timer);
Alert.alert('错误', '与服务器断开连接', [
......
......@@ -325,6 +325,10 @@ export class websocket {
static quitMatch() {
this.send({type: 'MATCH_QUIT'});
}
static heartbeat() {
this.send({type: 'HEART_BEAT'});
}
}
const mapStateToProps = state => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册