Skip to content

Commit

Permalink
- fix removing RT command listener for Channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Valodya committed May 24, 2022
1 parent 5d40380 commit 7380679
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backendless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ declare module Backendless {

removeCommandListener(callback: (command: Object) => void): ChannelClass;

removeCommandListeners(): ChannelClass;
removeCommandListeners(callback?: (command: Object) => void): ChannelClass;

addUserStatusListener(callback: (userStates: Object) => void, onError?: (error: Object) => void): ChannelClass;

Expand Down
6 changes: 6 additions & 0 deletions src/messaging/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export default class Channel extends RTScopeConnector {
return this
}

removeCommandListener(callback) {
super.removeCommandListeners.call(this, callback)

return this
}

removeCommandListeners(callback) {
super.removeCommandListeners.call(this, callback)

Expand Down
6 changes: 6 additions & 0 deletions src/rso/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export default class RemoteSharedObject extends RTScopeConnector {
return this
}

removeCommandListener(callback) {
super.removeCommandListeners.call(this, callback)

return this
}

removeCommandListeners(callback) {
super.removeCommandListeners.call(this, callback)

Expand Down
46 changes: 44 additions & 2 deletions test/unit/specs/messaging/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ describe('<Messaging> Channel', function() {
expect(sub3.name).to.be.equal('PUB_SUB_COMMANDS')
expect(sub3.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })

channel.removeCommandListeners(callback1)
channel.removeCommandListeners(callback2)
channel.removeCommandListener(callback1)
channel.removeCommandListener(callback2)

const subOff1 = await subOff1Promise
const subOff2 = await subOff2Promise
Expand All @@ -958,6 +958,48 @@ describe('<Messaging> Channel', function() {

})

it('removes all simple listeners', async () => {
const sub1Promise = rtClient.getNext_SUB_ON() // PUB_SUB_CONNECT
const sub2Promise = rtClient.getNext_SUB_ON() // PUB_SUB_COMMANDS
const sub3Promise = rtClient.getNext_SUB_ON() // PUB_SUB_COMMANDS
const subOff1Promise = rtClient.getNext_SUB_OFF() // PUB_SUB_COMMANDS
const subOff2Promise = rtClient.getNext_SUB_OFF() // PUB_SUB_COMMANDS

const callback1 = () => ({})
const callback2 = () => ({})

channel.addCommandListener(callback1)
channel.addCommandListener(callback2)

const sub1 = await sub1Promise

expect(sub1.id).to.be.a('string')
expect(sub1.name).to.be.equal('PUB_SUB_CONNECT')
expect(sub1.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })

rtClient.subReady(sub1.id)

const sub2 = await sub2Promise

expect(sub2.id).to.be.a('string')
expect(sub2.name).to.be.equal('PUB_SUB_COMMANDS')
expect(sub2.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })

const sub3 = await sub3Promise

expect(sub3.id).to.be.a('string')
expect(sub3.name).to.be.equal('PUB_SUB_COMMANDS')
expect(sub3.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })

channel.removeCommandListeners()

const subOff1 = await subOff1Promise
const subOff2 = await subOff2Promise

expect(sub2.id).to.be.equal(subOff1.id)
expect(sub3.id).to.be.equal(subOff2.id)
})

it('sends command', async () => {
const sub1Promise = rtClient.getNext_SUB_ON() // PUB_SUB_CONNECT

Expand Down
4 changes: 2 additions & 2 deletions test/unit/specs/rso.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ describe('RSO', function() {
expect(sub3.name).to.be.equal('RSO_COMMANDS')
expect(sub3.options).to.be.eql({ name: 'TEST_RSO_NAME' })

rso.removeCommandListeners(callback1)
rso.removeCommandListeners(callback2)
rso.removeCommandListener(callback1)
rso.removeCommandListener(callback2)

const subOff1 = await subOff1Promise
const subOff2 = await subOff2Promise
Expand Down

0 comments on commit 7380679

Please sign in to comment.