diff --git a/lib/client/proxy-object.js b/lib/client/proxy-object.js index f662c5d..08723c8 100644 --- a/lib/client/proxy-object.js +++ b/lib/client/proxy-object.js @@ -117,7 +117,25 @@ class ProxyObject { return reject(err); } this._initXml(data); - resolve(this); + + const nameOwnerMessage = new Message({ + destination: 'org.freedesktop.DBus', + path: '/org/freedesktop/DBus', + interface: 'org.freedesktop.DBus', + member: 'GetNameOwner', + signature: 's', + body: [this.name] + }); + + this.bus.call(nameOwnerMessage) + .then((msg) => { + this.bus._nameOwners[this.name] = msg.body[0]; + resolve(this); + }) + .catch((err) => { + if (err.type === 'org.freedesktop.DBus.Error.NameHasNoOwner') { return resolve(this); } + return reject(err); + }); }); } else { const introspectMessage = new Message({ diff --git a/test/integration/signals.test.js b/test/integration/signals.test.js index fa74160..1765966 100644 --- a/test/integration/signals.test.js +++ b/test/integration/signals.test.js @@ -11,6 +11,56 @@ const TEST_NAME = 'org.test.signals'; const TEST_NAME2 = 'org.test.signals_name2'; const TEST_PATH = '/org/test/path'; const TEST_IFACE = 'org.test.iface'; +const TEST_XML = ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +`; const bus = dbus.sessionBus(); bus.on('error', (err) => { @@ -190,3 +240,25 @@ test('regression #64: adding multiple listeners to a signal', async () => { expect(cb2).toHaveBeenCalledTimes(1); expect(cb3).toHaveBeenCalledTimes(2); }); + +test('bug #XXX: signals dont get lost when no previous method calls have been made', async () => { + // clear the name owners cache from previous tests + bus._nameOwners = {}; + + // when providing XML data, no introspection call is made + const object = await bus.getProxyObject(TEST_NAME, TEST_PATH, TEST_XML); + const test = object.getInterface(TEST_IFACE); + const cb = jest.fn(); + + test.on('HelloWorld', cb); + test.on('SignalMultiple', cb); + test.on('SignalComplicated', cb); + + // don't call EmitSignals through the proxy object + testIface.EmitSignals(); + + // allow signal handlers to run + await new Promise(resolve => { setTimeout(resolve, 0); }); + + expect(cb).toHaveBeenCalledTimes(3); +});