Skip to content

Commit 28114c4

Browse files
authored
fix(transport-commons): Do not error when adding an undefined connection to a channel (#2268)
1 parent f588257 commit 28114c4

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

packages/transport-commons/src/channels/channel/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Channel extends EventEmitter {
4343

4444
join (...connections: RealTimeConnection[]) {
4545
connections.forEach(connection => {
46-
if (this.connections.indexOf(connection) === -1) {
46+
if (connection && this.connections.indexOf(connection) === -1) {
4747
this.connections.push(connection);
4848
}
4949
});

packages/transport-commons/src/channels/channel/combined.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ export class CombinedChannel extends Channel {
4848
}
4949

5050
private callChildren (method: string, connections: RealTimeConnection[]) {
51-
// @ts-ignore
52-
this.children.forEach(child => child[method](...connections));
51+
this.children.forEach((child: any) => child[method](...connections));
5352
this.refresh();
5453

5554
return this;

packages/transport-commons/test/channels/channel.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ describe('app.channel', () => {
181181
assert.strictEqual(combined.length, 2);
182182
});
183183

184+
it('does nothing when the channel is undefined (#2207)', () => {
185+
const channel = app.channel('test', 'me');
186+
187+
channel.join(undefined);
188+
});
189+
184190
it('.join all child channels', () => {
185191
const c1 = { id: 1 };
186192
const c2 = { id: 2 };

0 commit comments

Comments
 (0)