Skip to content

Commit

Permalink
fix(transport-commons): Do not error when adding an undefined connect…
Browse files Browse the repository at this point in the history
…ion to a channel (#2268)
  • Loading branch information
daffl authored Mar 26, 2021
1 parent f588257 commit 28114c4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/transport-commons/src/channels/channel/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
3 changes: 1 addition & 2 deletions packages/transport-commons/src/channels/channel/combined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions packages/transport-commons/test/channels/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit 28114c4

Please # to comment.