This commit is contained in:
syuilo
2018-06-11 06:48:25 +09:00
parent e70fb71a04
commit dc3c80e3ce
8 changed files with 140 additions and 7 deletions

View File

@ -0,0 +1,35 @@
import * as websocket from 'websocket';
import Xev from 'xev';
const ev = new Xev();
export default function(request: websocket.request, connection: websocket.connection): void {
const onStats = stats => {
connection.send(JSON.stringify({
type: 'stats',
body: stats
}));
};
connection.on('message', async data => {
const msg = JSON.parse(data.utf8Data);
switch (msg.type) {
case 'requestLog':
ev.once('hashtagsStatsLog:' + msg.id, statsLog => {
connection.send(JSON.stringify({
type: 'statsLog',
body: statsLog
}));
});
ev.emit('requestHashtagsStatsLog', msg.id);
break;
}
});
ev.addListener('hashtagsStats', onStats);
connection.on('close', () => {
ev.removeListener('hashtagsStats', onStats);
});
}

View File

@ -14,6 +14,7 @@ import othelloGameStream from './stream/othello-game';
import othelloStream from './stream/othello';
import serverStatsStream from './stream/server-stats';
import notesStatsStream from './stream/notes-stats';
import hashtagsStatsStream from './stream/hashtags-stats';
import requestsStream from './stream/requests';
import { ParsedUrlQuery } from 'querystring';
import authenticate from './authenticate';
@ -39,6 +40,11 @@ module.exports = (server: http.Server) => {
return;
}
if (request.resourceURL.pathname === '/hashtags-stats') {
hashtagsStatsStream(request, connection);
return;
}
if (request.resourceURL.pathname === '/requests') {
requestsStream(request, connection);
return;