From c6110dd99605553f5cbd88eaf93fd490a4d33d51 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 9 Oct 2018 01:50:49 +0900 Subject: [PATCH] Fix bug Closes #2855 --- src/client/app/common/scripts/stream.ts | 9 +++--- .../components/games/reversi/reversi.game.vue | 10 +++--- .../components/games/reversi/reversi.room.vue | 32 ++++++++----------- .../views/components/messaging-room.vue | 6 ++-- .../api/stream/channels/games/reversi-game.ts | 8 ++--- 5 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/client/app/common/scripts/stream.ts b/src/client/app/common/scripts/stream.ts index 3b1a94adf..e95306183 100644 --- a/src/client/app/common/scripts/stream.ts +++ b/src/client/app/common/scripts/stream.ts @@ -253,14 +253,13 @@ abstract class Connection extends EventEmitter { @autobind public send(typeOrPayload, payload?) { - const data = payload === undefined ? typeOrPayload : { - type: typeOrPayload, - body: payload - }; + const type = payload === undefined ? typeOrPayload.type : typeOrPayload; + const body = payload === undefined ? typeOrPayload.body : payload; this.stream.send('channel', { id: this.id, - body: data + type: type, + body: body }); } diff --git a/src/client/app/common/views/components/games/reversi/reversi.game.vue b/src/client/app/common/views/components/games/reversi/reversi.game.vue index 751abe2ec..608e1c182 100644 --- a/src/client/app/common/views/components/games/reversi/reversi.game.vue +++ b/src/client/app/common/views/components/games/reversi/reversi.game.vue @@ -186,9 +186,8 @@ export default Vue.extend({ if (this.game.isStarted && !this.game.isEnded) { this.pollingClock = setInterval(() => { const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join('')); - this.connection.send({ - type: 'check', - crc32 + this.connection.send('check', { + crc32: crc32 }); }, 3000); } @@ -224,9 +223,8 @@ export default Vue.extend({ sound.play(); } - this.connection.send({ - type: 'set', - pos + this.connection.send('set', { + pos: pos }); this.checkEnd(); diff --git a/src/client/app/common/views/components/games/reversi/reversi.room.vue b/src/client/app/common/views/components/games/reversi/reversi.room.vue index 9f0d9c23f..29c6794f6 100644 --- a/src/client/app/common/views/components/games/reversi/reversi.room.vue +++ b/src/client/app/common/views/components/games/reversi/reversi.room.vue @@ -149,9 +149,9 @@ export default Vue.extend({ }, created() { - this.connection.on('change-accepts', this.onChangeAccepts); - this.connection.on('update-settings', this.onUpdateSettings); - this.connection.on('init-form', this.onInitForm); + this.connection.on('changeAccepts', this.onChangeAccepts); + this.connection.on('updateSettings', this.onUpdateSettings); + this.connection.on('initForm', this.onInitForm); this.connection.on('message', this.onMessage); if (this.game.user1Id != this.$store.state.i.id && this.game.settings.form1) this.form = this.game.settings.form1; @@ -159,9 +159,9 @@ export default Vue.extend({ }, beforeDestroy() { - this.connection.off('change-accepts', this.onChangeAccepts); - this.connection.off('update-settings', this.onUpdateSettings); - this.connection.off('init-form', this.onInitForm); + this.connection.off('changeAccepts', this.onChangeAccepts); + this.connection.off('updateSettings', this.onUpdateSettings); + this.connection.off('initForm', this.onInitForm); this.connection.off('message', this.onMessage); }, @@ -171,15 +171,11 @@ export default Vue.extend({ }, accept() { - this.connection.send({ - type: 'accept' - }); + this.connection.send('accept', {}); }, cancel() { - this.connection.send({ - type: 'cancel-accept' - }); + this.connection.send('cancelAccept', {}); }, onChangeAccepts(accepts) { @@ -189,8 +185,7 @@ export default Vue.extend({ }, updateSettings() { - this.connection.send({ - type: 'update-settings', + this.connection.send('updateSettings', { settings: this.game.settings }); }, @@ -216,8 +211,7 @@ export default Vue.extend({ }, onChangeForm(item) { - this.connection.send({ - type: 'update-form', + this.connection.send('updateForm', { id: item.id, value: item.value }); @@ -238,9 +232,9 @@ export default Vue.extend({ const y = Math.floor(pos / this.game.settings.map[0].length); const newPixel = pixel == ' ' ? '-' : - pixel == '-' ? 'b' : - pixel == 'b' ? 'w' : - ' '; + pixel == '-' ? 'b' : + pixel == 'b' ? 'w' : + ' '; const line = this.game.settings.map[y].split(''); line[x] = newPixel; this.$set(this.game.settings.map, y, line.join('')); diff --git a/src/client/app/common/views/components/messaging-room.vue b/src/client/app/common/views/components/messaging-room.vue index 488dff528..55aafc3ee 100644 --- a/src/client/app/common/views/components/messaging-room.vue +++ b/src/client/app/common/views/components/messaging-room.vue @@ -174,8 +174,7 @@ export default Vue.extend({ this.messages.push(message); if (message.userId != this.$store.state.i.id && !document.hidden) { - this.connection.send({ - type: 'read', + this.connection.send('read', { id: message.id }); } @@ -247,8 +246,7 @@ export default Vue.extend({ if (document.hidden) return; this.messages.forEach(message => { if (message.userId !== this.$store.state.i.id && !message.isRead) { - this.connection.send({ - type: 'read', + this.connection.send('read', { id: message.id }); } diff --git a/src/server/api/stream/channels/games/reversi-game.ts b/src/server/api/stream/channels/games/reversi-game.ts index 11f1fb1fe..54d9d1ae1 100644 --- a/src/server/api/stream/channels/games/reversi-game.ts +++ b/src/server/api/stream/channels/games/reversi-game.ts @@ -23,10 +23,10 @@ export default class extends Channel { public onMessage(type: string, body: any) { switch (type) { case 'accept': this.accept(true); break; - case 'cancel-accept': this.accept(false); break; - case 'update-settings': this.updateSettings(body.settings); break; - case 'init-form': this.initForm(body); break; - case 'update-form': this.updateForm(body.id, body.value); break; + case 'cancelAccept': this.accept(false); break; + case 'updateSettings': this.updateSettings(body.settings); break; + case 'initForm': this.initForm(body); break; + case 'updateForm': this.updateForm(body.id, body.value); break; case 'message': this.message(body); break; case 'set': this.set(body.pos); break; case 'check': this.check(body.crc32); break;