UNPKG

@tanislav000/bluez

Version:

Bluez5 D-Bus bindings for easy to use bluetooth access in Node.js

40 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GattCharacteristic = void 0; const dbus_next_1 = require("dbus-next"); const GattCharacteristic1_1 = require("./dbus/GattCharacteristic1"); const gattDescriptor_1 = require("./gattDescriptor"); class GattCharacteristic extends GattCharacteristic1_1.OrgBluezGattCharacteristic1 { constructor(dbusObject, bluez) { super(dbusObject); this.bluez = bluez; } /** * Find a Gatt Descriptor by UUID * @param uuid * @throws {DBusError} org.bluez.Error.DoesNotExist */ async getDescriptor(uuid) { const chars = await this.listDescriptors(); for (const path in chars) { if (chars[path].UUID === uuid) { return this.bluez.getDbusObjectInterface(gattDescriptor_1.GattDescriptor, path); } } throw new dbus_next_1.DBusError("org.bluez.Error.DoesNotExist", "Descriptor not found"); } /** * Returns a list of known Gatt descriptors of this characteristic * It returns key value pairs for each descriptor. * The key is the object path and the value is a snapshot of the properties of the descriptor. * To get the full descriptor interface use `Bluez.getDbusObjectInterface(GattDescriptor, key)` */ async listDescriptors() { const objs = await this.bluez.getObjectManager().GetManagedObjects(); return Object.fromEntries(Object.entries(objs) .filter(([path, ifs]) => path.startsWith(this.dbusObject.path) && gattDescriptor_1.GattDescriptor.DbusInterfaceName in ifs) .map(([path, ifs]) => [path, ifs[gattDescriptor_1.GattDescriptor.DbusInterfaceName]])); } } exports.GattCharacteristic = GattCharacteristic; //# sourceMappingURL=gattCharacteristic.js.map