Skip to content

Commit

Permalink
Add public closeChannels
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFellger committed Aug 7, 2019
1 parent b26ac9b commit 6f90133
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class QuidditchClient extends EventEmitter {
}
}

closeChannels (prefix) {
for (const channelName of Object.keys(this._otChannels)) {
if (channelName.startsWith(prefix)) this._closeChannel(channelName)
}
}

// ===========================================================================
// INTERNALS
// ===========================================================================
Expand Down
16 changes: 16 additions & 0 deletions test/socket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ describe('Quidditch Client', () => {
})
})

it('should close channels by prefix', (done) => {
const client = new QuidditchClient(WS_URL, {token: 'hunter2'})
client.once('joined', () => {
return Promise.all([
client.sendDelta('test:1:foo', new Delta().insert('a')),
client.sendDelta('test:1:bar', new Delta().insert('b')),
client.sendDelta('test:2:foo', new Delta().insert('c'))
]).then(() => {
client.closeChannels('test:1')
expect(Object.keys(client._otChannels)).to.deep.equal(['initalChannel', 'test:2:foo'])
client.close()
setTimeout(done, 1)
})
})
})

// it('should not accept random acks', (done) => {
// client.removeAllListeners('error')
// client.once('error', () => done())
Expand Down

0 comments on commit 6f90133

Please sign in to comment.