A Node.js implementation of D-Bus with native TypeScript support.
npm install @clebert/node-d-bus> A Node.js implementation of D-Bus with native TypeScript support.
```
npm install @clebert/node-d-bus d-bus-message-protocol d-bus-type-system
- Designed from the ground up with TypeScript.
- Depends only on
d-bus-message-protocol
and d-bus-type-system.
- Built-in support for the system message bus connected via Unix domain socket
path.
- The default path (unix:path=/var/run/dbus/system_bus_socket) can beDBUS_SYSTEM_BUS_ADDRESS
overwritten with the environment variable .
- Built-in support for authentication as external.
- Tested with Node.js 14 on Raspberry Pi OS Lite.
`js
import {SystemDBus} from '@clebert/node-d-bus';
import {MessageType} from 'd-bus-message-protocol';
const dBus = new SystemDBus();
await dBus.connectAsExternal();
try {
const helloReturnMessage = await dBus.callMethod({
messageType: MessageType.MethodCall,
objectPath: /org/freedesktop/DBus,org.freedesktop.DBus
interfaceName: ,Hello
memberName: ,org.freedesktop.DBus
serial: dBus.nextSerial,
destination: ,
});
console.log(JSON.stringify(helloReturnMessage));
} finally {
dBus.disconnect();
}
`
`json`
{
"messageType": 2,
"replySerial": 1,
"serial": 1,
"noReplyExpected": true,
"noAutoStart": false,
"allowInteractiveAuthorization": false,
"destination": ":1.811",
"sender": "org.freedesktop.DBus",
"type": {"typeCode": "s", "bytePadding": 4},
"body": ":1.811"
}
Note: The preceding message can also be conveniently sent using the
await dBus.hello()` method.