2018-10-07 11:06:17 +09:00
|
|
|
import autobind from 'autobind-decorator';
|
2021-08-19 18:33:41 +09:00
|
|
|
import { publishMainStream } from '@/services/stream.js';
|
|
|
|
|
import Channel from '../../channel.js';
|
|
|
|
|
import { ReversiMatchings } from '@/models/index.js';
|
2018-10-07 11:06:17 +09:00
|
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 23:01:57 +09:00
|
|
|
public readonly chName = 'gamesReversi';
|
2018-10-11 23:07:20 +09:00
|
|
|
public static shouldShare = true;
|
2018-11-11 02:22:34 +09:00
|
|
|
public static requireCredential = true;
|
2018-10-11 23:01:57 +09:00
|
|
|
|
2018-10-07 11:06:17 +09:00
|
|
|
@autobind
|
|
|
|
|
public async init(params: any) {
|
|
|
|
|
// Subscribe reversi stream
|
2019-04-13 01:43:22 +09:00
|
|
|
this.subscriber.on(`reversiStream:${this.user!.id}`, data => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.send(data);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
|
public async onMessage(type: string, body: any) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'ping':
|
|
|
|
|
if (body.id == null) return;
|
2019-04-07 21:50:36 +09:00
|
|
|
const matching = await ReversiMatchings.findOne({
|
2019-04-13 01:43:22 +09:00
|
|
|
parentId: this.user!.id,
|
2019-04-07 21:50:36 +09:00
|
|
|
childId: body.id
|
2018-10-07 11:06:17 +09:00
|
|
|
});
|
|
|
|
|
if (matching == null) return;
|
2021-03-24 11:05:37 +09:00
|
|
|
publishMainStream(matching.childId, 'reversiInvited', await ReversiMatchings.pack(matching, { id: matching.childId }));
|
2018-10-07 11:06:17 +09:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|