sidorares / dbus-native

D-bus protocol client and server for node.js written in native javascript
Other
258 stars 93 forks source link

TypeError: Cannot read property 'on' of undefined #109

Open kclim2 opened 8 years ago

kclim2 commented 8 years ago

Hi,

I tried to replicate the work as discussed in issue #8 for USB mounting but get the following errors:

/home/ubuntu/test-dbus_native.js:8
        ud.on('DeviceAdded', function(deviceObjectPath) {
          ^

TypeError: Cannot read property 'on' of undefined
    at /home/ubuntu/test-dbus_native.js:8:11
    at /home/ubuntu/node_modules/dbus-native/lib/bus.js:273:33
    at /home/ubuntu/node_modules/dbus-native/lib/bus.js:265:33
    at Object.<anonymous> (/home/ubuntu/node_modules/dbus-native/lib/introspect.js:10:23)
    at EventEmitter.<anonymous> (/home/ubuntu/node_modules/dbus-native/lib/bus.js:115:26)
    at emitOne (events.js:90:13)
    at EventEmitter.emit (events.js:182:7)
    at /home/ubuntu/node_modules/dbus-native/index.js:98:12
    at Socket.<anonymous> (/home/ubuntu/node_modules/dbus-native/lib/message.js:53:9)
    at emitNone (events.js:85:20)

the code:

cat test-dbus_native.js

var dbus = require('dbus-native');

var bus = dbus.systemBus();
udservice = bus.getService('org.freedesktop.UDisks');

udservice.getInterface('/org/freedesktop/UDisks', 'org.freedesktop.UDisks', function(err, ud) {
    /* Event, which gets called, if a usb-device has been found. //*/
        ud.on('DeviceAdded', function(deviceObjectPath) {
            udservice.getInterface(deviceObjectPath, 'org.freedesktop.DBus.Properties', function(err, diskProperties) {
                    diskProperties.Get('DeviceMountPaths', function(err, mountPointPaths) {
                console.log(mountPointPaths);
                    });
            })
    });
});

The detail of my system is as follow: ubuntu@ubuntu-lenovo:~$ cat node_modules/dbus-native/package.json

{
  "_args": [
    [
      "dbus-native",
      "/home/ubuntu"
    ]
  ],
  "_from": "dbus-native@latest",
  "_id": "dbus-native@0.2.0",
  "_inCache": true,
  "_installable": true,
  "_location": "/dbus-native",
  "_nodeVersion": "1.5.1",
  "_npmUser": {
    "email": "sidorares@yandex.com",
    "name": "sidorares"
  },
  "_npmVersion": "2.7.0",
  "_phantomChildren": {
    "sax": "1.1.4"
  },
  "_requested": {
    "name": "dbus-native",
    "raw": "dbus-native",
    "rawSpec": "",
    "scope": null,
    "spec": "latest",
    "type": "tag"
  },
  "_requiredBy": [
    "#USER"
  ],
  "_resolved": "https://registry.npmjs.org/dbus-native/-/dbus-native-0.2.0.tgz",
  "_shasum": "b3fe24f44298ba62bd2fa2add492d75a851a2f8e",
  "_shrinkwrap": null,
  "_spec": "dbus-native",
  "_where": "/home/ubuntu",
  "author": {
    "email": "sidorares@yandex.com",
    "name": "Andrey Sidorov"
  },

ubuntu 14.04LTS 64-bit

uname -a Linux ubuntu-lenovo 3.16.0-62-generic #83~14.04.1-Ubuntu SMP Fri Feb 26 22:52:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

sidorares commented 8 years ago

looks like getInterface returns error - could you 1) check which version of UDisk you aare running ( start d-feet and see what services look like UDisk ? ) 2) verify err before using ud

kclim2 commented 8 years ago

there is no error returned by getInterface (err == null)

using the d-feet, i found that the only available UDisks Object path is /org/freedesktop/UDisks2

the interfaces under org.freedesktop.DBus are: org.freedesktop.DBus.Introspectable org.freedesktop.DBus.ObjectManager org.freedesktop.DBus.Peer org.freedesktop.DBus.Properties

another UDisks related Object path is /org/freedesktop/UDisks2/Manager the interfaces under this object path are: org.freedesktop.DBus.Introspectable org.freedesktop.DBus.Peer org.freedesktop.DBus.Properties org.freedesktop.UDisk2.Manager

anyway, now the error message is: node test-dbus_native.js

err == null

/home/ubuntu/node_modules/dbus-native/node_modules/xml2js/lib/xml2js.js:216 throw ex; ^

TypeError: Cannot read property 'on' of undefined at /home/ubuntu/test-dbus_native.js:14:5 at /home/ubuntu/node_modules/dbus-native/lib/bus.js:274:17 at /home/ubuntu/node_modules/dbus-native/lib/bus.js:267:17 at /home/ubuntu/node_modules/dbus-native/lib/introspect.js:167:11 at Parser. (/home/ubuntu/node_modules/dbus-native/node_modules/xml2js/lib/xml2js.js:199:18) at emitOne (events.js:90:13) at Parser.emit (events.js:182:7) at Object.saxParser.onclosetag (/home/ubuntu/node_modules/dbus-native/node_modules/xml2js/lib/xml2js.js:183:24) at emit (/home/ubuntu/node_modules/sax/lib/sax.js:639:35) at emitNode (/home/ubuntu/node_modules/sax/lib/sax.js:644:5)

`var dbus = require('dbus-native');

var bus = dbus.systemBus(); udservice = bus.getService('org.freedesktop.UDisks2'); try { udservice.getInterface('/org/freedesktop/UDisks2', 'org.freedesktop.UDisks2', function(err, ud) { console.log('err == ',err); if(err){ console.lorg('error getting interface!'); throw(err) } /* Event, which gets called, if a usb-device has been found. //*/ ud.on('DeviceAdded', function(deviceObjectPath) { udservice.getInterface(deviceObjectPath, 'org.freedesktop.DBus.Properties', function(err, diskProperties) { diskProperties.Get('DeviceMountPaths', function(err, mountPointPaths) { console.log(mountPointPaths); }); }) }); }); }catch(ex){ console.log(ex); } `