summaryrefslogtreecommitdiff
path: root/src/server/api/streaming.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-14 20:38:55 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-14 20:38:55 +0900
commitd66e4b7ff97d512e2a2523815e2eef170456b37f (patch)
tree59ae1a102d88b5c2c2236b734ea4a584b4f9ba46 /src/server/api/streaming.ts
parent10.100.0 (diff)
parent11.0.0 (diff)
downloadmisskey-d66e4b7ff97d512e2a2523815e2eef170456b37f.tar.gz
misskey-d66e4b7ff97d512e2a2523815e2eef170456b37f.tar.bz2
misskey-d66e4b7ff97d512e2a2523815e2eef170456b37f.zip
Merge branch 'develop'
Diffstat (limited to 'src/server/api/streaming.ts')
-rw-r--r--src/server/api/streaming.ts58
1 files changed, 13 insertions, 45 deletions
diff --git a/src/server/api/streaming.ts b/src/server/api/streaming.ts
index f8f3c0ff4a..902c62ef98 100644
--- a/src/server/api/streaming.ts
+++ b/src/server/api/streaming.ts
@@ -1,7 +1,6 @@
import * as http from 'http';
import * as websocket from 'websocket';
import * as redis from 'redis';
-import Xev from 'xev';
import MainStreamConnection from './stream';
import { ParsedUrlQuery } from 'querystring';
@@ -23,58 +22,27 @@ module.exports = (server: http.Server) => {
let ev: EventEmitter;
- if (config.redis) {
- // Connect to Redis
- const subscriber = redis.createClient(
- config.redis.port, config.redis.host);
+ // Connect to Redis
+ const subscriber = redis.createClient(
+ config.redis.port, config.redis.host);
- subscriber.subscribe('misskey');
+ subscriber.subscribe('misskey');
- ev = new EventEmitter();
+ ev = new EventEmitter();
- subscriber.on('message', async (_, data) => {
- const obj = JSON.parse(data);
+ subscriber.on('message', async (_, data) => {
+ const obj = JSON.parse(data);
- ev.emit(obj.channel, obj.message);
- });
+ ev.emit(obj.channel, obj.message);
+ });
- connection.once('close', () => {
- subscriber.unsubscribe();
- subscriber.quit();
- });
- } else {
- ev = new Xev();
- }
+ connection.once('close', () => {
+ subscriber.unsubscribe();
+ subscriber.quit();
+ });
const main = new MainStreamConnection(connection, ev, user, app);
- // 後方互換性のため
- if (request.resourceURL.pathname !== '/streaming') {
- main.sendMessageToWsOverride = (type: string, payload: any) => {
- if (type == 'channel') {
- type = payload.type;
- payload = payload.body;
- }
- if (type.startsWith('api:')) {
- type = type.replace('api:', 'api-res:');
- }
- connection.send(JSON.stringify({
- type: type,
- body: payload
- }));
- };
-
- main.connectChannel(Math.random().toString().substr(2, 8), null,
- request.resourceURL.pathname === '/' ? 'homeTimeline' :
- request.resourceURL.pathname === '/local-timeline' ? 'localTimeline' :
- request.resourceURL.pathname === '/hybrid-timeline' ? 'hybridTimeline' :
- request.resourceURL.pathname === '/global-timeline' ? 'globalTimeline' : null);
-
- if (request.resourceURL.pathname === '/') {
- main.connectChannel(Math.random().toString().substr(2, 8), null, 'main');
- }
- }
-
connection.once('close', () => {
ev.removeAllListeners();
main.dispose();