You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,6 +169,47 @@ To emit a signal, just call the method marked with the `signal` decorator and th
169
169
170
170
If you have an interface xml description, which can be gotten from the `org.freedesktop.DBus.Introspect` method on an exported interface, you can generate dbus-next JavaScript classes from the xml file with the `bin/generate-interfaces.js` utility.
171
171
172
+
## The Low-Level Interface
173
+
174
+
The low-level interface can be used to interact with messages directly. Create new messages with the `Message` class to be sent on the bus as method calls, signals, method returns, or errors. Method calls can be called with the `call()` method of the `MessageBus` to await a reply and `send()` can be use for messages that don't expect a reply.
175
+
176
+
```js
177
+
let dbus =require('dbus-next');
178
+
let Message =dbus.Message;
179
+
180
+
let bus =dbus.sessionBus();
181
+
182
+
// send a method call to list the names on the bus
183
+
let methodCall =newMessage({
184
+
destination:'org.freedesktop.DBus',
185
+
path:'/org/freedesktop/DBus',
186
+
interface:'org.freedesktop.DBus',
187
+
member:'ListNames'
188
+
});
189
+
190
+
let reply =awaitbus.call(message);
191
+
console.log('names on the bus: ', reply.body[0]);
192
+
193
+
// add a custom handler for a particular method
194
+
bus.addMethodHandler((msg) => {
195
+
if (msg.path==='/org/test/path'&&
196
+
msg.interface==='org.test.interface'
197
+
&&msg.member==='SomeMethod') {
198
+
// handle the method by sending a reply
199
+
let someMethodReply =Message.newMethodReturn(msg, 's', ['hello']);
200
+
bus.send(someMethodReply);
201
+
returntrue;
202
+
}
203
+
});
204
+
205
+
// listen to any messages that are sent to the bus
206
+
bus.on('message', (msg) => {
207
+
console.log('got a message: ', msg);
208
+
});
209
+
```
210
+
211
+
For a complete example of how to use the low-level interface to send messages, see the `dbus-next-send.js` script in the `bin` directory.
212
+
172
213
## Contributing
173
214
174
215
Contributions are welcome. Development happens on [Github](https://github.com/acrisci/node-dbus-next).
0 commit comments