ログインしていないとリバーシを観戦できない問題を修正

This commit is contained in:
syuilo 2018-07-27 04:01:12 +09:00
parent 3eb6b36866
commit fab0a0d6e2
3 changed files with 44 additions and 28 deletions

View file

@ -105,7 +105,8 @@ export default Vue.extend({
} }
}, },
isMyTurn(): boolean { isMyTurn(): boolean {
if (this.turnUser == null) return null; if (!this.iAmPlayer) return false;
if (this.turnUser == null) return false;
return this.turnUser.id == this.$store.state.i.id; return this.turnUser.id == this.$store.state.i.id;
}, },
cellsStyle(): any { cellsStyle(): any {

View file

@ -67,7 +67,9 @@ export default Vue.extend({
components: { components: {
XGameroom XGameroom
}, },
props: ['initGame'], props: ['initGame'],
data() { data() {
return { return {
game: null, game: null,
@ -82,54 +84,63 @@ export default Vue.extend({
pingClock: null pingClock: null
}; };
}, },
watch: { watch: {
game(g) { game(g) {
this.$emit('gamed', g); this.$emit('gamed', g);
} }
}, },
created() { created() {
if (this.initGame) { if (this.initGame) {
this.game = this.initGame; this.game = this.initGame;
} }
}, },
mounted() { mounted() {
this.connection = (this as any).os.streams.reversiStream.getConnection(); if (this.$store.getters.isSignedIn) {
this.connectionId = (this as any).os.streams.reversiStream.use(); this.connection = (this as any).os.streams.reversiStream.getConnection();
this.connectionId = (this as any).os.streams.reversiStream.use();
this.connection.on('matched', this.onMatched); this.connection.on('matched', this.onMatched);
this.connection.on('invited', this.onInvited); this.connection.on('invited', this.onInvited);
(this as any).api('games/reversi/games', { (this as any).api('games/reversi/games', {
my: true my: true
}).then(games => { }).then(games => {
this.myGames = games; this.myGames = games;
}); });
(this as any).api('games/reversi/invitations').then(invitations => {
this.invitations = this.invitations.concat(invitations);
});
this.pingClock = setInterval(() => {
if (this.matching) {
this.connection.send({
type: 'ping',
id: this.matching.id
});
}
}, 3000);
}
(this as any).api('games/reversi/games').then(games => { (this as any).api('games/reversi/games').then(games => {
this.games = games; this.games = games;
this.gamesFetching = false; this.gamesFetching = false;
}); });
(this as any).api('games/reversi/invitations').then(invitations => {
this.invitations = this.invitations.concat(invitations);
});
this.pingClock = setInterval(() => {
if (this.matching) {
this.connection.send({
type: 'ping',
id: this.matching.id
});
}
}, 3000);
}, },
beforeDestroy() { beforeDestroy() {
this.connection.off('matched', this.onMatched); if (this.connection) {
this.connection.off('invited', this.onInvited); this.connection.off('matched', this.onMatched);
(this as any).os.streams.reversiStream.dispose(this.connectionId); this.connection.off('invited', this.onInvited);
(this as any).os.streams.reversiStream.dispose(this.connectionId);
clearInterval(this.pingClock); clearInterval(this.pingClock);
}
}, },
methods: { methods: {
go(game) { go(game) {
(this as any).api('games/reversi/games/show', { (this as any).api('games/reversi/games/show', {
@ -139,6 +150,7 @@ export default Vue.extend({
this.game = game; this.game = game;
}); });
}, },
match() { match() {
(this as any).apis.input({ (this as any).apis.input({
title: 'ユーザー名を入力してください' title: 'ユーザー名を入力してください'
@ -158,10 +170,12 @@ export default Vue.extend({
}); });
}); });
}, },
cancel() { cancel() {
this.matching = null; this.matching = null;
(this as any).api('games/reversi/match/cancel'); (this as any).api('games/reversi/match/cancel');
}, },
accept(invitation) { accept(invitation) {
(this as any).api('games/reversi/match', { (this as any).api('games/reversi/match', {
userId: invitation.parent.id userId: invitation.parent.id
@ -172,10 +186,12 @@ export default Vue.extend({
} }
}); });
}, },
onMatched(game) { onMatched(game) {
this.matching = null; this.matching = null;
this.game = game; this.game = game;
}, },
onInvited(invite) { onInvited(invite) {
this.invitations.unshift(invite); this.invitations.unshift(invite);
} }

View file

@ -3,7 +3,6 @@ import ReversiGame, { pack } from '../../../../../models/games/reversi/game';
import { ILocalUser } from '../../../../../models/user'; import { ILocalUser } from '../../../../../models/user';
export const meta = { export const meta = {
requireCredential: true
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {