dbusjs / node-dbus-next

🚌 The next great dbus library for node
https://www.npmjs.com/package/dbus-next
155 stars 52 forks source link

ProxyObject or Interface went away event missing #103

Open KryQ opened 2 years ago

KryQ commented 2 years ago

Hi The problem I'm facing is checking if service emitting signals went dark. There seems to not be any event emitted when interface goes down. To make problem worse when service goes back up properties.on("SendBrightness", ()=>{}); does not work anymore.

What I'm doing to circumvent this problem is registering listener on brightness service as usual:

const registerBrightnessService = async () => {
    try {
        // get a proxy object
        const obj = await bus.getProxyObject("me.kryq.brightness", "/me/kryq/brightness");
        const properties = obj.getInterface("me.kryq.brightness");

        properties.on("SendBrightness", ()=>{});
    }
    catch (e) {
        console.log(e.toString());

        setTimeout(registerBrightnessService, 5000);
    }
};

but then listening on the bus for messages:

bus.on("message", (msg:dbus.Message)=> {
        if(msg.interface == "me.kryq.brightness" && msg.member === "SendBrightness") {
            setBrightness(msg.body[0])
                .catch(console.error);
        }
    });

This allows me to listen to messages when service reconnects.

Is there any event I'm missing? Thanks for help