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

304_完成心跳机制验证

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