Class: MessageBus

MessageBus()

The MessageBus is a class for interacting with a DBus message bus capable of requesting a service Name to export an Interface, or getting a proxy object to interact with an existing name on the bus as a client. A MessageBus is created with dbus.sessionBus() or dbus.systemBus() methods of the dbus-next module.

The MessageBus is an EventEmitter which emits the following events:

  • error - The underlying connection to the bus has errored. After receiving an error event, the MessageBus may be disconnected.
  • connected - The bus is connected and ready to send and receive messages. Before this event, messages are buffered.
  • message - The bus has received a message. Called with the Message that was received. This is part of the low-level api.

Constructor

new MessageBus()

Create a new MessageBus. This constructor is not to be called directly. Use dbus.sessionBus() or dbus.systemBus() to set up the connection to the bus.

Source:
Example
const dbus = require('dbus-next');
const bus = dbus.sessionBus();
// get a proxy object
let obj = await bus.getProxyObject('org.freedesktop.DBus', '/org/freedesktop/DBus');
// request a well-known name
await bus.requestName('org.test.name');

Members

name :string

The unique name of the bus connection. This will be null until the MessageBus is connected.

Type:
  • string
Source:

Methods

addMethodHandler(fn)

Add a user method return handler. Remove the handler with MessageBus#removeMethodHandler

Parameters:
Name Type Description
fn methodHandler

A function to handle a Message of type MessageType.METHOD_RETURN. Takes the Message as the first argument. Return true if the method is handled and no further handlers will run.

Source:

call(msg) → {Promise}

Send a Message of type MessageType.METHOD_CALL to the bus and wait for the reply.

Parameters:
Name Type Description
msg Message

The message to send.

Source:
Returns:

reply - A Promise that resolves to the Message which is a reply to the call.

Type
Promise
Example
let message = new Message({
  destination: 'org.freedesktop.DBus',
  path: '/org/freedesktop/DBus',
  interface: 'org.freedesktop.DBus',
  member: 'ListNames'
});
let reply = await bus.call(message);

disconnect()

Disconnect this MessageBus from the bus.

Source:

export(path, iface)

Export an Interface on the bus. See the documentation for that class for how to define service interfaces.

Parameters:
Name Type Description
path string

The object path to export this Interface on.

iface module:interface~Interface

The service interface to export.

Source:

getProxyObject(name, path, xmlopt) → {Promise}

Get a ProxyObject on the bus for the given name and path for interacting with a service as a client. The proxy object contains a list of the ProxyInterfaces exported at the name and object path as well as a list of nodes.

Parameters:
Name Type Attributes Description
name string

the well-known name on the bus.

path string

the object path exported on the name.

xml string <optional>

xml introspection data.

Source:
Returns:
  • a Promise that resolves with the ProxyObject.
Type
Promise

newSerial() → {int}

Get a new serial for this bus. These can be used to set the Message#serial member to send the message on this bus.

Source:
Returns:
  • A new serial for this bus.
Type
int

releaseName() → {Promise}

Release this name. Requests that the name should no longer be owned by the MessageBus.

Source:
Returns:

A Promise that will resolve with the ReleaseNameReply.

Type
Promise

removeMethodHandler(fn)

Remove a user method return handler that was previously added with MessageBus#addMethodHandler.

Parameters:
Name Type Description
fn methodHandler

A function that was previously added as a method handler.

Source:

requestName(name, flags) → {Promise}

Request a well-known name on the bus.

Parameters:
Name Type Description
name string

the well-known name on the bus to request.

flags NameFlag

DBus name flags which affect the behavior of taking the name.

Source:
See:
Returns:
Type
Promise

send(msg)

Send a Message on the bus that does not expect a reply.

Parameters:
Name Type Description
msg Message

The message to send.

Source:
Example
let message = Message.newSignal('/org/test/path/,
                                'org.test.interface',
                                'SomeSignal');
bus.send(message);

unexport(path, ifaceopt)

Unexport an Interface on the bus. The interface will no longer be advertised to clients.

Parameters:
Name Type Attributes Description
path string

The object path on which to unexport.

iface module:interface~Interface <optional>

The Interface to unexport. If not given, this will remove all interfaces on the path.

Source: