1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-05 07:45:54 +02:00
Files
misskey/src/server/api/stream/games/reversi.ts
syuilo 83d9730d93 #2020
2018-07-30 07:20:27 +09:00

29 lines
915 B
TypeScript

import * as mongo from 'mongodb';
import * as websocket from 'websocket';
import Xev from 'xev';
import Matching, { pack } from '../../../../models/games/reversi/matching';
import { publishUserStream } from '../../../../stream';
export default function(request: websocket.request, connection: websocket.connection, subscriber: Xev, user: any): void {
// Subscribe reversi stream
subscriber.on(`reversi-stream:${user._id}`, data => {
connection.send(JSON.stringify(data));
});
connection.on('message', async (data) => {
const msg = JSON.parse(data.utf8Data);
switch (msg.type) {
case 'ping':
if (msg.id == null) return;
const matching = await Matching.findOne({
parentId: user._id,
childId: new mongo.ObjectID(msg.id)
});
if (matching == null) return;
publishUserStream(matching.childId, 'reversi_invited', await pack(matching, matching.childId));
break;
}
});
}