Module: interface

A module for exporting interfaces on a name on the message bus.

Source:

Classes

Interface

Members

(static, constant) ACCESS_READ

Used for Interface property options to specify that clients have read access to the property.

Source:

(static, constant) ACCESS_READWRITE

Used for Interface property options to specify that clients have read and write access to the property.

Source:

(static, constant) ACCESS_WRITE

Used for Interface property options to specify that clients have write access to the property.

Source:

Methods

(static) method(options)

A decorator function to define an Interface class member as a method. The method will be called when the client calls it on the bus with the given arguments with types specified by the inSignature in the method options. The method should return a result specified by the outSignature which will be returned to the client over the message bus. If multiple output parameters are specified in the outSignature, they should be returned within an array.

The method may also be async or return a Promise with the result and the reply will be sent once the promise returns with a response body.

The method may throw a DBusError with an error name and message to return the error to the client.

Parameters:
Name Type Description
options object

The options for this method.

Properties
Name Type Attributes Default Description
inSignature string <optional>
""

The DBus type signature for the input to this method.

outSignature string <optional>
""

The DBus type signature for the output of this method.

name string <optional>

The name of this method on the bus. Defaults to the name of the class member being decorated.

disabled bool <optional>
false

Whether or not this property will be advertised on the bus.

Source:
See:
Example
// uncomment the decorators to use them (jsdoc bug)

class MyInterface extends Interface {
  //@method({inSignature: 's', outSignature: 's'})
  async Echo(what) {
    return what;
  }

  //@method({inSignature: 'ss', outSignature: 'vv'})
  ReturnsMultiple(what, what2) {
    return [
      new Variant('s', what),
      new Variant('s', what2)
    ];
  }

  //@method({inSignature: '', outSignature: ''})
  ThrowsError() {
    // the error is returned to the client
    throw new DBusError('org.test.iface.Error', 'something went wrong');
  }
}

(static) property(options)

A decorator function to define an Interface class member as a property. The property will be gotten and set from the class when users call the standard DBus methods org.freedesktop.DBus.Properties.Get, org.freedesktop.DBus.Properties.Set, and org.freedesktop.DBus.Properties.GetAll. The property getters and setters may throw a DBusError with an error name and message to return the error to the client.

Parameters:
Name Type Description
options object

The options for this property.

Properties
Name Type Attributes Default Description
signature string

The DBus type signature for this property.

access access <optional>
ACCESS_READWRITE

The read and write access of the property for clients (effects Get and Set property methods).

name string <optional>

The name of this property on the bus. Defaults to the name of the class member being decorated.

disabled bool <optional>
false

Whether or not this property will be advertised on the bus.

Source:
See:
Example
class MyInterface extends Interface {
  // uncomment below to use the decorator (jsdoc bug)
  //@property({signature: 's'})
  get MyProp() {
    return this.myProp;
  }
  set MyProp(value) {
    this.myProp = value;
  }
}

(static) signal(options)

A decorator function to define an Interface class member as a signal. To emit the signal on the bus to listeners, just call the decorated method and the signal will be emitted with the returned value with types specified by the signature in the signal options. If the signal has multiple output parameters, they should be returned in an array.

Parameters:
Name Type Description
options object

The options for this property.

Properties
Name Type Attributes Default Description
signature string

The DBus type signature for this signal.

name string <optional>

The name of this signal on the bus. Defaults to the name of the class member being decorated.

disabled bool <optional>
false

Whether or not this property will be advertised on the bus.

Source:
See:
Example
// uncomment the decorators to use them (jsdoc bug)
class MyInterface extends Interface {
  //@signal({signature: 's'})
  HelloWorld(value) {
    return value;
  }

  //@signal({signature: 'ss'})
  SignalMultiple(x) {
    return [
      'hello',
      'world'
    ];
  }
}