Reference for the current JavaScript API exposed by require("dbus").
This reference lists the current JavaScript API exposed by the goja-dbus native module. It describes the implemented subset, not the full future design.
The module is available as:
const dbus = require("dbus");
dbus.session(): BusBuilderCreates a builder for the session bus. This is the default safe bus for examples.
dbus.system(): BusBuilderCreates a builder for the system bus. The default policy denies system bus access, so dbus.system().connect() rejects unless policy support is explicitly widened in a future host configuration.
dbus.connect(address: string): BusBuilderCreates a builder for an explicit D-Bus address. Empty addresses are rejected. Explicit-address connections are denied by the default policy; opt in with policy({ allowAddressBus: true }) only when the host intentionally allows direct addresses.
BusBuildertimeout(ms: number): BusBuilderReturns a new builder with a default timeout for connect-created bus operations.
policy(policy: DBusPolicy): BusBuilderReturns a new builder with policy options applied. Current fields are:
interface DBusPolicy {
allowSessionBus?: boolean;
allowSystemBus?: boolean;
denySystemBus?: boolean;
allowAddressBus?: boolean;
allowCall?: string[];
}
allowAddressBus is separate from session/system policy so callers cannot bypass the default system-bus denial by passing a raw system bus address to connect(address). allowCall supports exact matches and suffix * prefix matches. An explicitly empty allowCall: [] list denies all method calls; omit the field to keep the builder's existing call policy.
connect(): Promise<DBusBus>Connects to the selected bus and resolves to a bus object. Rejections use JavaScript Error objects with:
err.name === "DBusError"
err.code === "ERR_DBUS"
DBusBusclose(): Promise<void>Closes the bus and tracked subscriptions. The runtime also closes tracked buses when the runtime lifetime ends.
destination(name: string): RemoteDestinationSelects a remote D-Bus destination.
signals(): SignalBuilderCreates a signal subscription builder.
bus
.destination("org.freedesktop.DBus")
.object("/org/freedesktop/DBus")
.interface("org.freedesktop.DBus")
.method("GetId")
.out("s")
.call();
RemoteDestination.object(path: string): RemoteObjectSelects an object path. Invalid object paths throw immediately.
RemoteObject.interface(name: string): RemoteInterfaceSelects a D-Bus interface.
RemoteInterface.method(name: string): MethodCallBuilderSelects a method member.
MethodCallBuilder.in(signature: string, value: any): MethodCallBuilderAdds one input argument. Use typed helpers for ambiguous values.
MethodCallBuilder.out(signature: string): MethodCallBuilderDeclares the expected output signature. The current unmarshal path validates the signature and returns a single value, an array of values, or null/undefined equivalent when the reply body is empty.
MethodCallBuilder.timeout(ms: number): MethodCallBuilderOverrides the bus default timeout for this method call.
MethodCallBuilder.call(): Promise<any>Executes the D-Bus method call.
interface DBusTypedValue {
readonly __dbusTyped: true;
readonly signature: string;
readonly value: any;
}
dbus.u32(value: number): DBusTypedValuedbus.i32(value: number): DBusTypedValuedbus.path(value: string): DBusTypedValuedbus.signature(value: string): DBusTypedValuedbus.variant(signature: string, value: any): DBusTypedValuedbus.array(signature: string, values: any[]): DBusTypedValuedbus.dict(signature: string, values: Record<string, any>): DBusTypedValuedbus.struct(signature: string, values: any[]): DBusTypedValueThe current codec supports common arrays (as, au, ai, ao, av), a{sv}, and flat structs such as (su). Unsupported signatures fail explicitly.
interface SignalPayload {
sender: string;
path: string;
name: string;
body: any[];
}
interface SignalSubscription {
close(): Promise<void>;
}
SignalBuilder.sender(name: string): SignalBuilderAdds a sender match.
SignalBuilder.path(path: string): SignalBuilderAdds an object path match. Invalid object paths throw immediately.
SignalBuilder.interface(name: string): SignalBuilderAdds an interface match.
SignalBuilder.member(name: string): SignalBuilderAdds a signal member match.
SignalBuilder.listen(emitter: EventEmitter): Promise<SignalSubscription>Installs the match rule and emits matching signals through emitter.emit("signal", payload). The emitter must come from require("events").
| Problem | Cause | Solution |
|---|---|---|
dbus.variant("v", value) is confusing | Variants should usually wrap a concrete inner signature, not another generic variant | Use a concrete signature such as s, u, or a{sv} |
a{sv} rejects values | Each map value must be a D-Bus variant helper | Wrap values with dbus.variant(signature, value) |
| Struct marshaling fails | Only flat struct signatures are currently supported | Keep structs simple or add codec support before using nested structs |
| System bus is denied | Default policy blocks it | Use session bus or implement reviewed host policy widening |
xgoja help getting-startedxgoja help user-guidexgoja help xgoja-v2-reference