UNPKG

dbus-sdk

Version:

A Node.js SDK for interacting with DBus, enabling seamless service calling and exposure with TypeScript support

42 lines (41 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PeerInterface = void 0; const LocalInterface_1 = require("../../LocalInterface"); const native_machine_id_1 = require("native-machine-id"); const node_crypto_1 = require("node:crypto"); /** * A class representing the DBus Peer interface. * This interface provides basic peer-to-peer functionality for DBus connections, * including retrieving the machine ID and a simple ping method for testing connectivity. * Implements the 'org.freedesktop.DBus.Peer' interface. */ class PeerInterface extends LocalInterface_1.LocalInterface { /** * Constructor for the PeerInterface. * Initializes the interface with the name 'org.freedesktop.DBus.Peer' * and defines two methods: 'GetMachineId' to retrieve the machine UUID, * and 'Ping' for connectivity testing. */ constructor() { super('org.freedesktop.DBus.Peer'); this .defineMethod({ name: 'GetMachineId', outputArgs: [{ name: 'machine_uuid', type: 's' // String type for the machine UUID }], method: async () => (await (0, native_machine_id_1.getMachineId)({ raw: true })) || (0, node_crypto_1.randomUUID)() // Retrieves the machine ID using native-machine-id library. // If retrieval fails or returns an empty value, generates a random UUID as fallback. }) .defineMethod({ name: 'Ping', method: () => undefined // A no-op method used to test connectivity between peers. // Does not return any value or perform any action. }); } } exports.PeerInterface = PeerInterface;