sidorares / dbus-native

D-bus protocol client and server for node.js written in native javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PropertiesChange with NetworkManager

nand87 opened this issue · comments

commented

When I use NetworkManager I want to monitoring the change of an Interface (i.e. eth0, wlan0) when I plug the eth or when I connect the wlan; because I want to reconnect to my on-line broker.

The code that I use is:

var sessionBus = dbus.sessionBus();
sessionBus.getService('org.freedesktop.NetworkManager').getInterface(
    '/org/freedesktop/NetworkManager',
    'org.freedesktop.NetworkManager', function(err, notifications) {
        notifications.on('PropertiesChanged', function() {
            try{
                client.end(true, function(){
                    console.log("Connection Forced to Close after Network Interface Changes");
                });
            }
            catch(e)
            {
                console.log("Client already closed???");
            }
            console.log("Re-Subscribing");
            client.reconnect();
        });
    });

Any suggestions to monitor that?
Thank you all