Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,19 @@ class MessageBus extends EventEmitter {
body: [match]
});
return this.call(msg);
};
}

_removeMatch(match) {
let msg = new Message({
path: '/org/freedesktop/DBus',
destination: 'org.freedesktop.DBus',
interface: 'org.freedesktop.DBus',
member: 'RemoveMatch',
signature: 's',
body: [match]
});
return this.call(msg);
}
};

module.exports = MessageBus;
6 changes: 6 additions & 0 deletions lib/client/proxy-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ProxyInterface extends EventEmitter {
return;
}

this.$object.bus._removeMatch(this._signalMatchRuleString(eventName));
this.$object.bus._signals.removeListener(detailedEvent, this._getEventListener(signal));
});

Expand All @@ -78,10 +79,15 @@ class ProxyInterface extends EventEmitter {
return;
}

this.$object.bus._addMatch(this._signalMatchRuleString(eventName));
this.$object.bus._signals.on(detailedEvent, this._getEventListener(signal));
});
}

_signalMatchRuleString(eventName) {
return `type='signal',sender=${this.$object.name},interface='${this.$name}',path='${this.$object.path}',member='${eventName}'`
}

_getEventListener(signal) {
if (this.$listeners[signal.name]) {
return this.$listeners[signal.name];
Expand Down
1 change: 0 additions & 1 deletion lib/client/proxy-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class ProxyObject {
let iface = ProxyInterface._fromXml(this, i);
if (iface !== null) {
this.interfaces[iface.$name] = iface;
this.bus._addMatch(`type='signal',sender=${this.name},interface='${iface.$name}',path='${this.path}'`);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/integration/signals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ test('test that signals work correctly', async () => {
expect(bus._signals.eventNames().length).toEqual(2);
test.removeListener('SignalMultiple', onSignalMultiple);
expect(bus._signals.eventNames().length).toEqual(2);

// removing the listener on a signal should not remove them all
onSignalMultiple2.mockClear()
await test.EmitSignals();
expect(onSignalMultiple2).toHaveBeenCalledWith('hello', 'world');

test.removeListener('SignalMultiple', onSignalMultiple2);
expect(bus._signals.eventNames().length).toEqual(1);
test.removeListener('SignalComplicated', onSignalComplicated);
Expand Down