node-dbus
D-bus protocol client and server for node.js
Installation
npm install dbus-native
or
git clone https://github.com/sidorares/node-dbus # clone the repo cd node-dbusnpm install # install dependencies sudo cp examples/com.github.sidorares.dbus.Example.conf /etc/dbus-1/system.d/ # if you want to test examples/service.js
Usage
Short example using desktop notifications service
var dbus = ;var sessionBus = dbus;sessionBus;
API
Low level messaging: bus connection
connection = dbus.createClient(options)
options:
- socket - unix socket path
- port - TCP port
- host - TCP host
- busAddress - encoded bus address. Default is
DBUS_SESSION_BUS_ADDRESS
environment variable. See http://dbus.freedesktop.org/doc/dbus-specification.html#addresses - authMethods - array of authentication methods, which are attempted in the order provided (default:['EXTERNAL', 'DBUS_COOKIE_SHA1', 'ANONYMOUS'])
- ayBuffer - boolean (default:true): if true 'ay' dbus fields are returned as buffers
- ReturnLongjs - boolean (default:false): if true 64 bit dbus fields (x/t) are read out as Long.js objects, otherwise they are converted to numbers (which should be good up to 53 bits)
- ( TODO: add/document option to use adress from X11 session )
connection has only one method, message(msg)
message fields:
- type - methodCall, methodReturn, error or signal
- path - object path
- interface
- destination
- sender
- member
- serial
- signature
- body
- errorName
- replySerial
connection signals:
- connect - emitted after successful authentication
- message
- error
example:
var dbus = ;var conn = dbus;conn;conn;
Note on INT64 'x' and UINT64 't'
Long.js is used for 64 Bit support. https://github.com/dcodeIO/long.js The following javascript types can be marshalled into 64 bit dbus fields:
- typeof 'number' up to 53bits
- typeof 'string' (consisting of decimal digits with no separators or '0x' prefixed hexadecimal) up to full 64bit range
- Long.js objects (or object with compatible properties)
By default 64 bit dbus fields are unmarshalled into a 'number' (with precision loss beyond 53 bits). Use {ReturnLongjs:true} option to return the actual Long.js object and preserve the entire 64 bits.
Links
- http://cgit.freedesktop.org/dbus - freedesktop reference C library
- https://github.com/guelfey/go.dbus
- https://github.com/Shouqun/node-dbus - libdbus
- https://github.com/Motorola-Mobility/node-dbus - libdbus
- https://github.com/izaakschroeder/node-dbus - libdbus
- https://github.com/agnat/node_libdbus
- https://github.com/agnat/node_dbus - native js
- https://github.com/cocagne/txdbus - native python + twisted
- http://search.cpan.org/~danberr/Net-DBus-1.0.0/ (seems to be native, but requires libdbus?)
- https://github.com/mvidner/ruby-dbus (native, sync)
- http://www.ndesk.org/DBusSharp (C#/Mono)
- https://github.com/lizenn/erlang-dbus/ - erlang
- https://github.com/mspanc/dbux/ - elixir
- http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html - Blog post about sb-bus and D-Bus in general