diff --git a/packages/transport-commons/src/channels/channel/base.ts b/packages/transport-commons/src/channels/channel/base.ts index 7693d3c775..464eae9caa 100644 --- a/packages/transport-commons/src/channels/channel/base.ts +++ b/packages/transport-commons/src/channels/channel/base.ts @@ -43,7 +43,7 @@ export class Channel extends EventEmitter { join (...connections: RealTimeConnection[]) { connections.forEach(connection => { - if (this.connections.indexOf(connection) === -1) { + if (connection && this.connections.indexOf(connection) === -1) { this.connections.push(connection); } }); diff --git a/packages/transport-commons/src/channels/channel/combined.ts b/packages/transport-commons/src/channels/channel/combined.ts index 112e95185f..840f0a1fc9 100644 --- a/packages/transport-commons/src/channels/channel/combined.ts +++ b/packages/transport-commons/src/channels/channel/combined.ts @@ -48,8 +48,7 @@ export class CombinedChannel extends Channel { } private callChildren (method: string, connections: RealTimeConnection[]) { - // @ts-ignore - this.children.forEach(child => child[method](...connections)); + this.children.forEach((child: any) => child[method](...connections)); this.refresh(); return this; diff --git a/packages/transport-commons/test/channels/channel.test.ts b/packages/transport-commons/test/channels/channel.test.ts index 93129662ab..b3c1e73d7b 100644 --- a/packages/transport-commons/test/channels/channel.test.ts +++ b/packages/transport-commons/test/channels/channel.test.ts @@ -181,6 +181,12 @@ describe('app.channel', () => { assert.strictEqual(combined.length, 2); }); + it('does nothing when the channel is undefined (#2207)', () => { + const channel = app.channel('test', 'me'); + + channel.join(undefined); + }); + it('.join all child channels', () => { const c1 = { id: 1 }; const c2 = { id: 2 };