From e05acb8d18059c01e5789db043db82e4abfbd9d5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 7 Oct 2018 17:19:52 +0900 Subject: [PATCH] =?UTF-8?q?=E5=BE=8C=E6=96=B9=E4=BA=92=E6=8F=9B=E6=80=A7?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/stream/index.ts | 4 ++-- src/server/api/streaming.ts | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index 04136b3506..743d77b2a3 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -174,7 +174,7 @@ export default class Connection { * チャンネルに接続 */ @autobind - private connectChannel(id: string, params: any, channelClass: { new(id: string, connection: Connection): Channel }) { + public connectChannel(id: string, params: any, channelClass: { new(id: string, connection: Connection): Channel }) { const channel = new channelClass(id, this); this.channels.push(channel); channel.init(params); @@ -185,7 +185,7 @@ export default class Connection { * @param id チャンネルコネクションID */ @autobind - private disconnectChannel(id: string) { + public disconnectChannel(id: string) { const channel = this.channels.find(c => c.id === id); if (channel) { diff --git a/src/server/api/streaming.ts b/src/server/api/streaming.ts index 4518d21c3f..b7793eb284 100644 --- a/src/server/api/streaming.ts +++ b/src/server/api/streaming.ts @@ -5,6 +5,7 @@ import Xev from 'xev'; import MainStreamConnection from './stream'; import { ParsedUrlQuery } from 'querystring'; import authenticate from './authenticate'; +import channels from './stream/channels'; module.exports = (server: http.Server) => { // Init websocket server @@ -22,6 +23,27 @@ module.exports = (server: http.Server) => { const main = new MainStreamConnection(connection, ev, user, app); + // 後方互換性のため + if (request.resourceURL.pathname !== '/streaming') { + main.sendMessageToWs = (type: string, payload: any) => { + if (type == 'channel') { + type = payload.type; + payload = payload.body; + } + connection.send(JSON.stringify({ + type: type, + body: payload + })); + }; + if (request.resourceURL.pathname === '/') { + main.connectChannel(Math.random().toString(), null, + request.resourceURL.pathname === '/' ? channels.homeTimeline : + request.resourceURL.pathname === '/local-timeline' ? channels.localTimeline : + request.resourceURL.pathname === '/hybrid-timeline' ? channels.hybridTimeline : + request.resourceURL.pathname === '/global-timeline' ? channels.globalTimeline : null); + } + } + connection.once('close', () => { ev.removeAllListeners(); main.dispose();