This commit is contained in:
syuilo 2018-03-14 04:37:20 +09:00
parent 85df5ce3f7
commit 0fb52ea7eb
4 changed files with 8 additions and 3 deletions

View File

@ -6,7 +6,7 @@ import { publishOthelloGameStream } from '../event';
import Othello from '../../common/othello/core'; import Othello from '../../common/othello/core';
import * as maps from '../../common/othello/maps'; import * as maps from '../../common/othello/maps';
export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void { export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user?: any): void {
const gameId = request.resourceURL.query.game; const gameId = request.resourceURL.query.game;
// Subscribe game stream // Subscribe game stream

View File

@ -53,6 +53,11 @@ module.exports = (server: http.Server) => {
const user = await authenticate(request.resourceURL.query.i); const user = await authenticate(request.resourceURL.query.i);
if (request.resourceURL.pathname === '/othello-game') {
othelloGameStream(request, connection, subscriber, user);
return;
}
if (user == null) { if (user == null) {
connection.send('authentication-failed'); connection.send('authentication-failed');
connection.close(); connection.close();
@ -64,7 +69,6 @@ module.exports = (server: http.Server) => {
request.resourceURL.pathname === '/drive' ? driveStream : request.resourceURL.pathname === '/drive' ? driveStream :
request.resourceURL.pathname === '/messaging' ? messagingStream : request.resourceURL.pathname === '/messaging' ? messagingStream :
request.resourceURL.pathname === '/messaging-index' ? messagingIndexStream : request.resourceURL.pathname === '/messaging-index' ? messagingIndexStream :
request.resourceURL.pathname === '/othello-game' ? othelloGameStream :
request.resourceURL.pathname === '/othello' ? othelloStream : request.resourceURL.pathname === '/othello' ? othelloStream :
null; null;

View File

@ -3,7 +3,7 @@ import Stream from './stream';
export class OthelloGameStream extends Stream { export class OthelloGameStream extends Stream {
constructor(me, game) { constructor(me, game) {
super('othello-game', { super('othello-game', {
i: me.token, i: me ? me.token : null,
game: game.id game: game.id
}); });
} }

View File

@ -56,6 +56,7 @@ export default Vue.extend({
computed: { computed: {
iAmPlayer(): boolean { iAmPlayer(): boolean {
if (!(this as any).os.isSignedIn) return false;
return this.game.user1_id == (this as any).os.i.id || this.game.user2_id == (this as any).os.i.id; return this.game.user1_id == (this as any).os.i.id || this.game.user2_id == (this as any).os.i.id;
}, },
myColor(): Color { myColor(): Color {