This commit is contained in:
syuilo
2018-07-30 07:20:27 +09:00
parent 4e6dcd16ac
commit 83d9730d93
33 changed files with 189 additions and 242 deletions

View File

@ -1,7 +1,6 @@
import * as http from 'http';
import * as websocket from 'websocket';
import * as redis from 'redis';
import config from '../../config';
import Xev from 'xev';
import homeStream from './stream/home';
import localTimelineStream from './stream/local-timeline';
@ -39,20 +38,17 @@ module.exports = (server: http.Server) => {
return;
}
// Connect to Redis
const subscriber = redis.createClient(
config.redis.port, config.redis.host);
const ev = new Xev();
connection.on('close', () => {
subscriber.unsubscribe();
subscriber.quit();
connection.once('close', () => {
ev.removeAllListeners();
});
const q = request.resourceURL.query as ParsedUrlQuery;
const [user, app] = await authenticate(q.i as string);
if (request.resourceURL.pathname === '/games/reversi-game') {
reversiGameStream(request, connection, subscriber, user);
reversiGameStream(request, connection, ev, user);
return;
}
@ -75,7 +71,7 @@ module.exports = (server: http.Server) => {
null;
if (channel !== null) {
channel(request, connection, subscriber, user, app);
channel(request, connection, ev, user, app);
} else {
connection.close();
}