From 28114c495d6564868bb3ffbf619bf80b774dce4b Mon Sep 17 00:00:00 2001 From: David Luecke Date: Fri, 26 Mar 2021 16:33:10 -0700 Subject: [PATCH] fix(transport-commons): Do not error when adding an undefined connection to a channel (#2268) --- packages/transport-commons/src/channels/channel/base.ts | 2 +- packages/transport-commons/src/channels/channel/combined.ts | 3 +-- packages/transport-commons/test/channels/channel.test.ts | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) 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 };