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.GattService = void 0; const GattService1_1 = require("./dbus/GattService1"); const dbus_next_1 = require("dbus-next"); const gattCharacteristic_1 = require("./gattCharacteristic"); class GattService extends GattService1_1.OrgBluezGattService1 { constructor(dbusObject, bluez) { super(dbusObject); this.bluez = bluez; } /** * Find a Gatt Characteristic by UUID * @param uuid * @throws {DBusError} org.bluez.Error.DoesNotExist */ async getCharacteristic(uuid) { const chars = await this.listCharacteristics(); for (const path in chars) { if (chars[path].UUID === uuid) { return this.bluez.getDbusObjectInterface(gattCharacteristic_1.GattCharacteristic, path); } } throw new dbus_next_1.DBusError("org.bluez.Error.DoesNotExist", "Service not found"); } /** * Returns a list of known Gatt characteristics of this service * It returns key value pairs for each characteristic. * The key is the object path and the value is a snapshot of the properties of the characteristic. * To get the full characteristic interface use `Bluez.getDbusObjectInterface(GattCharacteristic, key)` */ async listCharacteristics() { const objs = await this.bluez.getObjectManager().GetManagedObjects(); return Object.fromEntries(Object.entries(objs) .filter(([path, ifs]) => path.startsWith(this.dbusObject.path) && gattCharacteristic_1.GattCharacteristic.DbusInterfaceName in ifs) .map(([path, ifs]) => [path, ifs[gattCharacteristic_1.GattCharacteristic.DbusInterfaceName]])); } } exports.GattService = GattService; //# sourceMappingURL=gattService.js.map