共有可能チャンネルに接続しようとしていて、かつそのチャンネルに既に接続していたら無意味なので無視するように

This commit is contained in:
syuilo
2018-10-11 23:01:57 +09:00
parent ad67886f96
commit e85f9f4aa5
17 changed files with 59 additions and 11 deletions

View File

@ -148,7 +148,7 @@ export default class Connection {
private onChannelConnectRequested(payload: any) {
const { channel, id, params } = payload;
log(`CH CONNECT: ${id} ${channel} by @${this.user.username}`);
this.connectChannel(id, params, (channels as any)[channel]);
this.connectChannel(id, params, channel);
}
/**
@ -177,10 +177,15 @@ export default class Connection {
* チャンネルに接続
*/
@autobind
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);
public connectChannel(id: string, params: any, channel: string) {
// 共有可能チャンネルに接続しようとしていて、かつそのチャンネルに既に接続していたら無意味なので無視
if ((channels as any)[channel].shouldShare && this.channels.some(c => c.chName === channel)) {
return;
}
const ch: Channel = new (channels as any)[channel](id, this);
this.channels.push(ch);
ch.init(params);
this.sendMessageToWs('connected', {
id: id
});