後方互換性を追加
This commit is contained in:
parent
10af684804
commit
e05acb8d18
|
@ -174,7 +174,7 @@ export default class Connection {
|
||||||
* チャンネルに接続
|
* チャンネルに接続
|
||||||
*/
|
*/
|
||||||
@autobind
|
@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);
|
const channel = new channelClass(id, this);
|
||||||
this.channels.push(channel);
|
this.channels.push(channel);
|
||||||
channel.init(params);
|
channel.init(params);
|
||||||
|
@ -185,7 +185,7 @@ export default class Connection {
|
||||||
* @param id チャンネルコネクションID
|
* @param id チャンネルコネクションID
|
||||||
*/
|
*/
|
||||||
@autobind
|
@autobind
|
||||||
private disconnectChannel(id: string) {
|
public disconnectChannel(id: string) {
|
||||||
const channel = this.channels.find(c => c.id === id);
|
const channel = this.channels.find(c => c.id === id);
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import Xev from 'xev';
|
||||||
import MainStreamConnection from './stream';
|
import MainStreamConnection from './stream';
|
||||||
import { ParsedUrlQuery } from 'querystring';
|
import { ParsedUrlQuery } from 'querystring';
|
||||||
import authenticate from './authenticate';
|
import authenticate from './authenticate';
|
||||||
|
import channels from './stream/channels';
|
||||||
|
|
||||||
module.exports = (server: http.Server) => {
|
module.exports = (server: http.Server) => {
|
||||||
// Init websocket server
|
// Init websocket server
|
||||||
|
@ -22,6 +23,27 @@ module.exports = (server: http.Server) => {
|
||||||
|
|
||||||
const main = new MainStreamConnection(connection, ev, user, app);
|
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', () => {
|
connection.once('close', () => {
|
||||||
ev.removeAllListeners();
|
ev.removeAllListeners();
|
||||||
main.dispose();
|
main.dispose();
|
||||||
|
|
Loading…
Reference in New Issue