From f18e5771de8a5f3d5433d6dbbab2776cb23b270d Mon Sep 17 00:00:00 2001 From: Marco Crespi Date: Mon, 12 Apr 2021 18:12:33 +0200 Subject: [PATCH] feat: Improve mac bindings --- lib/bindings/mac/Adapter.d.ts | 5 +- lib/bindings/mac/Adapter.d.ts.map | 2 +- lib/bindings/mac/Adapter.js | 31 ++++- lib/bindings/mac/Adapter.js.map | 2 +- lib/bindings/mac/Peripheral.d.ts | 6 +- lib/bindings/mac/Peripheral.d.ts.map | 2 +- lib/bindings/mac/Peripheral.js | 14 +-- lib/bindings/mac/Peripheral.js.map | 2 +- lib/bindings/mac/gatt/Characteristic.d.ts | 10 +- lib/bindings/mac/gatt/Characteristic.d.ts.map | 2 +- lib/bindings/mac/gatt/Characteristic.js | 64 ++++++++-- lib/bindings/mac/gatt/Characteristic.js.map | 2 +- lib/bindings/mac/gatt/Descriptor.d.ts | 9 ++ lib/bindings/mac/gatt/Descriptor.d.ts.map | 1 + lib/bindings/mac/gatt/Descriptor.js | 40 ++++++ lib/bindings/mac/gatt/Descriptor.js.map | 1 + lib/bindings/mac/gatt/Gatt.d.ts | 4 +- lib/bindings/mac/gatt/Gatt.d.ts.map | 2 +- lib/bindings/mac/gatt/Gatt.js | 6 +- lib/bindings/mac/gatt/Gatt.js.map | 2 +- lib/bindings/mac/gatt/Service.d.ts | 7 +- lib/bindings/mac/gatt/Service.d.ts.map | 2 +- lib/bindings/mac/gatt/Service.js | 10 +- lib/bindings/mac/gatt/Service.js.map | 2 +- lib/bindings/mac/gatt/index.d.ts | 1 + lib/bindings/mac/gatt/index.d.ts.map | 2 +- lib/bindings/mac/gatt/index.js | 1 + lib/bindings/mac/gatt/index.js.map | 2 +- lib/bindings/mac/index.d.ts | 1 + lib/bindings/mac/index.d.ts.map | 2 +- lib/bindings/mac/index.js | 1 + lib/bindings/mac/index.js.map | 2 +- src/bindings/mac/Adapter.ts | 56 +++++++-- src/bindings/mac/Peripheral.ts | 61 +++++---- src/bindings/mac/gatt/Characteristic.ts | 119 +++++++++++++----- src/bindings/mac/gatt/Descriptor.ts | 60 +++++++++ src/bindings/mac/gatt/Gatt.ts | 44 +++---- src/bindings/mac/gatt/Service.ts | 54 ++++---- src/bindings/mac/gatt/index.ts | 3 +- src/bindings/mac/index.ts | 1 + 40 files changed, 457 insertions(+), 181 deletions(-) create mode 100644 lib/bindings/mac/gatt/Descriptor.d.ts create mode 100644 lib/bindings/mac/gatt/Descriptor.d.ts.map create mode 100644 lib/bindings/mac/gatt/Descriptor.js create mode 100644 lib/bindings/mac/gatt/Descriptor.js.map create mode 100644 src/bindings/mac/gatt/Descriptor.ts diff --git a/lib/bindings/mac/Adapter.d.ts b/lib/bindings/mac/Adapter.d.ts index 8845f247..24fbd751 100644 --- a/lib/bindings/mac/Adapter.d.ts +++ b/lib/bindings/mac/Adapter.d.ts @@ -10,11 +10,12 @@ export declare class MacAdapter extends Adapter { dispose(): void; startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean): Promise; private onDiscover; + private onNotification; stopScanning(): Promise; getScannedPeripherals(): Promise; isAdvertising(): Promise; - startAdvertising(deviceName: string, serviceUUIDs?: string[]): Promise; + startAdvertising(): Promise; stopAdvertising(): Promise; - setupGatt(maxMtu?: number): Promise; + setupGatt(): Promise; } //# sourceMappingURL=Adapter.d.ts.map \ No newline at end of file diff --git a/lib/bindings/mac/Adapter.d.ts.map b/lib/bindings/mac/Adapter.d.ts.map index 1653812d..a97d2a3e 100644 --- a/lib/bindings/mac/Adapter.d.ts.map +++ b/lib/bindings/mac/Adapter.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Adapter.d.ts","sourceRoot":"","sources":["../../../src/bindings/mac/Adapter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAe,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAOpF,qBAAa,UAAW,SAAQ,OAAO;IACtC,SAAgB,KAAK,EAAE,GAAG,CAAQ;IAClC,OAAO,CAAC,QAA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AAI;IAKT,aAAa,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7F,OAAO,CAAC,UAAU,CAwBhB;IAEF,OAAO,CAAC,cAAc,CAmBpB;IAEW,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7B,qBAAqB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAIpD,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;CAGtC"} \ No newline at end of file diff --git a/lib/bindings/mac/Adapter.js b/lib/bindings/mac/Adapter.js index 81651ac0..82e75354 100644 --- a/lib/bindings/mac/Adapter.js +++ b/lib/bindings/mac/Adapter.js @@ -8,15 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.MacAdapter = void 0; -const events = require('events'); -const util = require('util'); +const events_1 = __importDefault(require("events")); +const util_1 = __importDefault(require("util")); const models_1 = require("../../models"); const Peripheral_1 = require("./Peripheral"); // eslint-disable-next-line @typescript-eslint/no-var-requires const NobleMac = require('./native').NobleMac; -util.inherits(NobleMac, events.EventEmitter); +util_1.default.inherits(NobleMac, events_1.default.EventEmitter); class MacAdapter extends models_1.Adapter { constructor(modblue, id, name) { super(modblue, id, name); @@ -35,6 +38,20 @@ class MacAdapter extends models_1.Adapter { } this.emit('discover', peripheral); }; + this.onNotification = (uuid, serviceUUID, charUUID, data, isNotification) => { + if (isNotification) { + const peripheral = this.peripherals.get(uuid); + if (peripheral) { + const service = peripheral.gatt.services.get(serviceUUID); + if (service) { + const char = service.characteristics.get(charUUID); + if (char) { + char.emit('notification', data); + } + } + } + } + }; this.noble = new NobleMac(); } isScanning() { @@ -58,10 +75,12 @@ class MacAdapter extends models_1.Adapter { }); this.noble.init(); }); + this.noble.on('read', this.onNotification); this.initDone = true; }); } dispose() { + this.noble.removeAllListeners(); this.noble.stop(); } startScanning(serviceUUIDs, allowDuplicates) { @@ -69,7 +88,7 @@ class MacAdapter extends models_1.Adapter { yield this.init(); this.peripherals.clear(); this.noble.startScanning(serviceUUIDs, allowDuplicates); - this.noble.on("discover", this.onDiscover); + this.noble.on('discover', this.onDiscover); this.scanning = true; }); } @@ -87,13 +106,13 @@ class MacAdapter extends models_1.Adapter { isAdvertising() { throw new Error('Method not implemented.'); } - startAdvertising(deviceName, serviceUUIDs) { + startAdvertising() { throw new Error('Method not implemented.'); } stopAdvertising() { throw new Error('Method not implemented.'); } - setupGatt(maxMtu) { + setupGatt() { throw new Error('Method not implemented.'); } } diff --git a/lib/bindings/mac/Adapter.js.map b/lib/bindings/mac/Adapter.js.map index 38d68512..7ce3e958 100644 --- a/lib/bindings/mac/Adapter.js.map +++ b/lib/bindings/mac/Adapter.js.map @@ -1 +1 @@ -{"version":3,"file":"Adapter.js","sourceRoot":"","sources":["../../../src/bindings/mac/Adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B,yCAAoF;AACpF,6CAA6C;AAE7C,8DAA8D;AAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC;AAC9C,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;AAE7C,MAAa,UAAW,SAAQ,gBAAO;IAWtC,YAAmB,OAAgB,EAAE,EAAU,EAAE,IAAY;QAC5D,KAAK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C;QACtB,CAAC;KAAA;IAEM,OAAO;QACb,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAChC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAEY,aAAa,CAAC,YAAuB,EAAE,eAAyB;;YAC5E,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;YACxD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACtB,CAAC;KAAA;IAiDY,YAAY;;YACxB,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACvB,CAAC;KAAA;IAEY,qBAAqB;;YACjC,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QACvC,CAAC;KAAA;IAEM,aAAa;QACnB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAEM,gBAAgB;QACtB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAEM,eAAe;QACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAEM,SAAS;QACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;CACD;AA3HD,gCA2HC"} \ No newline at end of file diff --git a/lib/bindings/mac/Peripheral.d.ts b/lib/bindings/mac/Peripheral.d.ts index 11684f99..7a210e54 100644 --- a/lib/bindings/mac/Peripheral.d.ts +++ b/lib/bindings/mac/Peripheral.d.ts @@ -1,10 +1,10 @@ /// -import { AddressType, ConnectOptions, GattRemote, Peripheral } from "../../models"; -import { MacAdapter } from "./Adapter"; +import { AddressType, GattRemote, Peripheral } from '../../models'; +import { MacAdapter } from './Adapter'; export declare class MacPeripheral extends Peripheral { readonly adapter: MacAdapter; constructor(adapter: MacAdapter, uuid: string, name: string, addressType: AddressType, address: string, manufacturerData: Buffer, rssi: number); - connect(options?: ConnectOptions): Promise; + connect(): Promise; disconnect(): Promise; } //# sourceMappingURL=Peripheral.d.ts.map \ No newline at end of file diff --git a/lib/bindings/mac/Peripheral.d.ts.map b/lib/bindings/mac/Peripheral.d.ts.map index 988858c3..af2213d0 100644 --- a/lib/bindings/mac/Peripheral.d.ts.map +++ b/lib/bindings/mac/Peripheral.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Peripheral.d.ts","sourceRoot":"","sources":["../../../src/bindings/mac/Peripheral.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,qBAAa,aAAc,SAAQ,UAAU;IAEzC,SAAgB,OAAO,EAAE,UAAU,CAAC;gBAEjB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAIxI,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAoBtD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAiB3C"} \ No newline at end of file +{"version":3,"file":"Peripheral.d.ts","sourceRoot":"","sources":["../../../src/bindings/mac/Peripheral.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,qBAAa,aAAc,SAAQ,UAAU;IAC5C,SAAgB,OAAO,EAAE,UAAU,CAAC;gBAGnC,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,MAAM;IAKA,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAoB9B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAiBxC"} \ No newline at end of file diff --git a/lib/bindings/mac/Peripheral.js b/lib/bindings/mac/Peripheral.js index d7320ada..a7d45ba6 100644 --- a/lib/bindings/mac/Peripheral.js +++ b/lib/bindings/mac/Peripheral.js @@ -16,18 +16,18 @@ class MacPeripheral extends models_1.Peripheral { constructor(adapter, uuid, name, addressType, address, manufacturerData, rssi) { super(adapter, uuid, name, addressType, address, manufacturerData, rssi); } - connect(options) { + connect() { return __awaiter(this, void 0, void 0, function* () { this._state = 'connecting'; this.adapter.noble.connect(this.uuid); - yield new Promise((resolve, reject) => { + yield new Promise((resolve) => { const connHandler = (uuid) => { if (uuid === this.uuid) { - this.adapter.noble.off("connect", connHandler); + this.adapter.noble.off('connect', connHandler); resolve(); } }; - this.adapter.noble.on("connect", connHandler); + this.adapter.noble.on('connect', connHandler); }); this._gatt = new gatt_1.MacGatt(this); this._state = 'connected'; @@ -38,14 +38,14 @@ class MacPeripheral extends models_1.Peripheral { return __awaiter(this, void 0, void 0, function* () { this._state = 'disconnecting'; this.adapter.noble.disconnect(this.uuid); - yield new Promise((resolve, reject) => { + yield new Promise((resolve) => { const disconnHandler = (uuid) => { if (uuid === this.uuid) { - this.adapter.noble.off("disconnect", disconnHandler); + this.adapter.noble.off('disconnect', disconnHandler); resolve(); } }; - this.adapter.noble.on("disconnect", disconnHandler); + this.adapter.noble.on('disconnect', disconnHandler); }); this._state = 'disconnected'; }); diff --git a/lib/bindings/mac/Peripheral.js.map b/lib/bindings/mac/Peripheral.js.map index 72de0e6a..ea66367e 100644 --- a/lib/bindings/mac/Peripheral.js.map +++ b/lib/bindings/mac/Peripheral.js.map @@ -1 +1 @@ -{"version":3,"file":"Peripheral.js","sourceRoot":"","sources":["../../../src/bindings/mac/Peripheral.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmF;AAGnF,iCAAiC;AAEjC,MAAa,aAAc,SAAQ,mBAAU;IAIzC,YAAmB,OAAmB,EAAE,IAAY,EAAE,IAAY,EAAE,WAAwB,EAAE,OAAe,EAAE,gBAAwB,EAAE,IAAY;QACjJ,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;IAEY,OAAO,CAAC,OAAwB;;YACzC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;YAEjC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEtC,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC3C,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;oBACpC,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;wBACvB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;wBAC/C,OAAO,EAAE,CAAC;qBACV;gBACF,CAAC,CAAC;gBACF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;YAEG,IAAI,CAAC,KAAK,GAAG,IAAI,cAAO,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;YAC1B,OAAO,IAAI,CAAC,KAA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100644 --- a/lib/bindings/mac/gatt/Characteristic.d.ts +++ b/lib/bindings/mac/gatt/Characteristic.d.ts @@ -1,13 +1,13 @@ /// -import { GattCharacteristic, GattDescriptor } from "../../../models"; -import { MacGattService } from "./Service"; +import { GattCharacteristic, GattDescriptor } from '../../../models'; +import { MacGattService } from './Service'; export declare class MacGattCharacteristic extends GattCharacteristic { readonly service: MacGattService; discoverDescriptors(): Promise; read(): Promise; - write(data: Buffer, withoutResponse: boolean): Promise; - broadcast(broadcast: boolean): Promise; + write(value: Buffer): Promise; + broadcast(): Promise; notify(notify: boolean): Promise; - addDescriptor(uuid: string, value: Buffer): Promise; + addDescriptor(): Promise; } //# sourceMappingURL=Characteristic.d.ts.map \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Characteristic.d.ts.map b/lib/bindings/mac/gatt/Characteristic.d.ts.map index b3e60531..804f68d4 100644 --- a/lib/bindings/mac/gatt/Characteristic.d.ts.map +++ b/lib/bindings/mac/gatt/Characteristic.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Characteristic.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Characteristic.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAa,qBAAsB,SAAQ,kBAAkB;IACzD,SAAgB,OAAO,EAAE,cAAc,CAAC;IAEjC,mBAAmB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAGhD,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAevB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAG5D,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAG5C,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAGtC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CAG7E"} \ No newline at end of file +{"version":3,"file":"Characteristic.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Characteristic.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGrE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAa,qBAAsB,SAAQ,kBAAkB;IAC5D,SAAgB,OAAO,EAAE,cAAc,CAAC;IAEjC,mBAAmB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAoBhD,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAqBvB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBtC,aAAa,IAAI,OAAO,CAAC,cAAc,CAAC;CAG/C"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Characteristic.js b/lib/bindings/mac/gatt/Characteristic.js index b2be78cd..9778811d 100644 --- a/lib/bindings/mac/gatt/Characteristic.js +++ b/lib/bindings/mac/gatt/Characteristic.js @@ -2,34 +2,72 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.MacGattCharacteristic = void 0; const models_1 = require("../../../models"); +const Descriptor_1 = require("./Descriptor"); class MacGattCharacteristic extends models_1.GattCharacteristic { discoverDescriptors() { - throw new Error("Method not implemented."); + const noble = this.service.gatt.peripheral.adapter.noble; + this.descriptors.clear(); + noble.discoverDescriptors(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid); + return new Promise((resolve) => { + const handler = (dev, srv, char, descUUIDs) => { + if (dev === this.service.gatt.peripheral.uuid && srv === this.service.uuid && char === this.uuid) { + noble.off('descriptorsDiscover', handler); + for (const descUUID of descUUIDs) { + this.descriptors.set(descUUID, new Descriptor_1.MacGattDescriptor(this, descUUID, true)); + } + resolve([...this.descriptors.values()]); + } + }; + noble.on('descriptorsDiscover', handler); + }); } read() { const noble = this.service.gatt.peripheral.adapter.noble; noble.read(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid); - return new Promise((resolve, reject) => { - const handler = (uuid, serviceUUID, charUUID, data) => { - if (uuid === this.service.gatt.peripheral.uuid && serviceUUID === this.service.uuid && charUUID === this.uuid) { - noble.off("read", handler); + return new Promise((resolve) => { + const handler = (dev, srv, char, data, isNotification) => { + if (dev === this.service.gatt.peripheral.uuid && + srv === this.service.uuid && + char === this.uuid && + isNotification) { + noble.off('read', handler); resolve(data); } }; - noble.on("read", handler); + noble.on('read', handler); }); } - write(data, withoutResponse) { - throw new Error("Method not implemented."); + write(value) { + const noble = this.service.gatt.peripheral.adapter.noble; + noble.write(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid, value); + return new Promise((resolve) => { + const handler = (dev, srv, char) => { + if (dev === this.service.gatt.peripheral.uuid && srv === this.service.uuid && char === this.uuid) { + noble.off('write', handler); + resolve(); + } + }; + noble.on('write', handler); + }); } - broadcast(broadcast) { - throw new Error("Method not implemented."); + broadcast() { + throw new Error('Method not implemented.'); } notify(notify) { - throw new Error("Method not implemented."); + const noble = this.service.gatt.peripheral.adapter.noble; + noble.notify(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid, notify); + return new Promise((resolve) => { + const handler = (dev, srv, char) => { + if (dev === this.service.gatt.peripheral.uuid && srv === this.service.uuid && char === this.uuid) { + noble.off('notify', handler); + resolve(); + } + }; + noble.on('notify', handler); + }); } - addDescriptor(uuid, value) { - throw new Error("Method not implemented."); + addDescriptor() { + throw new Error('Method not implemented.'); } } exports.MacGattCharacteristic = MacGattCharacteristic; diff --git a/lib/bindings/mac/gatt/Characteristic.js.map b/lib/bindings/mac/gatt/Characteristic.js.map index a476dfa8..6c59e549 100644 --- a/lib/bindings/mac/gatt/Characteristic.js.map +++ b/lib/bindings/mac/gatt/Characteristic.js.map @@ -1 +1 @@ -{"version":3,"file":"Characteristic.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Characteristic.ts"],"names":[],"mappings":";;;AAAA,4CAAqE;AAIrE,MAAa,qBAAsB,SAAQ,2BAAkB;IAGlD,mBAAmB;QACtB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IACM,IAAI;QACP,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;QAEzD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAE5E,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAE,QAAgB,EAAE,IAAY,EAAE,EAAE;gBAClF,IAAI,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,WAAW,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,QAAQ,KAAK,IAAI,CAAC,IAAI,EAAE;oBAC3G,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;oBAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;iBACjB;YACL,CAAC,CAAA;YACD,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACP,CAAC;IACM,KAAK,CAAC,IAAY,EAAE,eAAwB;QAC/C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IACM,SAAS,CAAC,SAAkB;QAC/B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IACM,MAAM,CAAC,MAAe;QACzB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IACM,aAAa,CAAC,IAAY,EAAE,KAAa;QAC5C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CACJ;AAjCD,sDAiCC"} \ No newline at end of file +{"version":3,"file":"Characteristic.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Characteristic.ts"],"names":[],"mappings":";;;AAAA,4CAAqE;AACrE,6CAAiD;AAIjD,MAAa,qBAAsB,SAAQ,2BAAkB;IAGrD,mBAAmB;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;QAEzD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAE3F,OAAO,IAAI,OAAO,CAAmB,CAAC,OAAO,EAAE,EAAE;YAChD,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,IAAY,EAAE,SAAmB,EAAE,EAAE;gBAC/E,IAAI,GAAG,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,GAAG,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;oBACjG,KAAK,CAAC,GAAG,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;oBAC1C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;wBACjC,IAAI,CAAC,WAAW,CAAC,GAA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IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,GAAG,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;oBACjG,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;oBAC7B,OAAO,EAAE,CAAC;iBACV;YACF,CAAC,CAAC;YACF,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACJ,CAAC;IAEM,aAAa;QACnB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;CACD;AAnFD,sDAmFC"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Descriptor.d.ts b/lib/bindings/mac/gatt/Descriptor.d.ts new file mode 100644 index 00000000..e5bc3321 --- /dev/null +++ b/lib/bindings/mac/gatt/Descriptor.d.ts @@ -0,0 +1,9 @@ +/// +import { GattDescriptor } from '../../../models'; +import { MacGattCharacteristic } from './Characteristic'; +export declare class MacGattDescriptor extends GattDescriptor { + readonly characteristic: MacGattCharacteristic; + read(): Promise; + write(value: Buffer): Promise; +} +//# sourceMappingURL=Descriptor.d.ts.map \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Descriptor.d.ts.map b/lib/bindings/mac/gatt/Descriptor.d.ts.map new file mode 100644 index 00000000..ff5d3fad --- /dev/null +++ b/lib/bindings/mac/gatt/Descriptor.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Descriptor.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Descriptor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,qBAAa,iBAAkB,SAAQ,cAAc;IACpD,SAAgB,cAAc,EAAE,qBAAqB,CAAC;IAE/C,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IA0BvB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA0B1C"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Descriptor.js b/lib/bindings/mac/gatt/Descriptor.js new file mode 100644 index 00000000..d14a224f --- /dev/null +++ b/lib/bindings/mac/gatt/Descriptor.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MacGattDescriptor = void 0; +const models_1 = require("../../../models"); +class MacGattDescriptor extends models_1.GattDescriptor { + read() { + const noble = this.characteristic.service.gatt.peripheral.adapter.noble; + noble.readValue(this.characteristic.service.gatt.peripheral.uuid, this.characteristic.service.uuid, this.characteristic.uuid, this.uuid); + return new Promise((resolve) => { + const handler = (dev, srv, char, desc, data) => { + if (dev === this.characteristic.service.gatt.peripheral.uuid && + srv === this.characteristic.service.uuid && + char === this.characteristic.uuid && + desc === this.uuid) { + noble.off('valueRead', handler); + resolve(data); + } + }; + noble.on('valueRead', handler); + }); + } + write(value) { + const noble = this.characteristic.service.gatt.peripheral.adapter.noble; + noble.writeValue(this.characteristic.service.gatt.peripheral.uuid, this.characteristic.service.uuid, this.characteristic.uuid, this.uuid, value); + return new Promise((resolve) => { + const handler = (dev, srv, char, desc) => { + if (dev === this.characteristic.service.gatt.peripheral.uuid && + srv === this.characteristic.service.uuid && + char === this.characteristic.uuid && + desc === this.uuid) { + noble.off('valueWrite', handler); + resolve(); + } + }; + noble.on('valueWrite', handler); + }); + } +} +exports.MacGattDescriptor = MacGattDescriptor; +//# sourceMappingURL=Descriptor.js.map \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Descriptor.js.map b/lib/bindings/mac/gatt/Descriptor.js.map new file mode 100644 index 00000000..809ffbbf --- /dev/null +++ b/lib/bindings/mac/gatt/Descriptor.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Descriptor.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Descriptor.ts"],"names":[],"m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ChD,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAChC,IAAI,CAAC,cAAc,CAAC,IAAI,EACxB,IAAI,CAAC,IAAI,EACT,KAAK,CACL,CAAC;QAEF,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACpC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,IAAY,EAAE,IAAY,EAAE,EAAE;gBACxE,IACC,GAAG,KAAK,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI;oBACxD,GAAG,KAAK,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;oBACxC,IAAI,KAAK,IAAI,CAAC,cAAc,CAAC,IAAI;oBACjC,IAAI,KAAK,IAAI,CAAC,IAAI,EACjB;oBACD,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBACjC,OAAO,EAAE,CAAC;iBACV;YACF,CAAC,CAAC;YACF,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAvDD,8CAuDC"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Gatt.d.ts b/lib/bindings/mac/gatt/Gatt.d.ts index 97ddfbe3..0f74a730 100644 --- a/lib/bindings/mac/gatt/Gatt.d.ts +++ b/lib/bindings/mac/gatt/Gatt.d.ts @@ -1,5 +1,5 @@ -import { GattRemote, GattService } from "../../../models"; -import { MacPeripheral } from "../Peripheral"; +import { GattRemote, GattService } from '../../../models'; +import { MacPeripheral } from '../Peripheral'; export declare class MacGatt extends GattRemote { readonly peripheral: MacPeripheral; discoverServices(): Promise; diff --git a/lib/bindings/mac/gatt/Gatt.d.ts.map b/lib/bindings/mac/gatt/Gatt.d.ts.map index 31b55684..22c0a8b3 100644 --- a/lib/bindings/mac/gatt/Gatt.d.ts.map +++ b/lib/bindings/mac/gatt/Gatt.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Gatt.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Gatt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,qBAAa,OAAQ,SAAQ,UAAU;IACnC,SAAgB,UAAU,EAAE,aAAa,CAAC;IAEnC,gBAAgB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAmBpD"} \ No newline at end of file +{"version":3,"file":"Gatt.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Gatt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,qBAAa,OAAQ,SAAQ,UAAU;IACtC,SAAgB,UAAU,EAAE,aAAa,CAAC;IAEnC,gBAAgB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAmBjD"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Gatt.js b/lib/bindings/mac/gatt/Gatt.js index 5a453fb5..7bc2a643 100644 --- a/lib/bindings/mac/gatt/Gatt.js +++ b/lib/bindings/mac/gatt/Gatt.js @@ -8,17 +8,17 @@ class MacGatt extends models_1.GattRemote { const noble = this.peripheral.adapter.noble; this.services.clear(); noble.discoverServices(this.peripheral.uuid); - return new Promise((resolve, reject) => { + return new Promise((resolve) => { const handler = (uuid, serviceUUIDs) => { if (uuid === this.peripheral.uuid) { - noble.off("servicesDiscover", handler); + noble.off('servicesDiscover', handler); for (const srvUUID of serviceUUIDs) { this.services.set(srvUUID, new Service_1.MacGattService(this, srvUUID, true)); } resolve([...this.services.values()]); } }; - noble.on("servicesDiscover", handler); + noble.on('servicesDiscover', handler); }); } } diff --git a/lib/bindings/mac/gatt/Gatt.js.map b/lib/bindings/mac/gatt/Gatt.js.map index 7eff8154..293d211c 100644 --- a/lib/bindings/mac/gatt/Gatt.js.map +++ b/lib/bindings/mac/gatt/Gatt.js.map @@ -1 +1 @@ -{"version":3,"file":"Gatt.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Gatt.ts"],"names":[],"mappings":";;;AAAA,4CAAyD;AAGzD,uCAA2C;AAE3C,MAAa,OAAQ,SAAQ,mBAAU;IAG5B,gBAAgB;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;QAE5C,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAE7C,OAAO,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,YAAsB,EAAE,EAAE;gBACrD,IAAI,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;oBAC/B,KAAK,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;oBACvC,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE;wBAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,wBAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;qBACvE;oBACD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;iBACxC;YACL,CAAC,CAAA;YACD,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAtBD,0BAsBC"} \ No newline at end of file +{"version":3,"file":"Gatt.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Gatt.ts"],"names":[],"mappings":";;;AAAA,4CAA0D;AAG1D,uCAA2C;AAE3C,MAAa,OAAQ,SAAQ,mBAAU;IAG/B,gBAAgB;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;QAE5C,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAE7C,OAAO,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,EAAE;YAC7C,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,YAAsB,EAAE,EAAE;gBACxD,IAAI,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;oBAClC,KAAK,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;oBACvC,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE;wBACnC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,wBAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;qBACpE;oBACD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;iBACrC;YACF,CAAC,CAAC;YACF,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAtBD,0BAsBC"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Service.d.ts b/lib/bindings/mac/gatt/Service.d.ts index 9c1af986..ee1f90e1 100644 --- a/lib/bindings/mac/gatt/Service.d.ts +++ b/lib/bindings/mac/gatt/Service.d.ts @@ -1,9 +1,8 @@ -/// -import { GattCharacteristic, GattCharacteristicProperty, GattService, ReadFunction, WriteFunction } from "../../../models"; -import { MacGatt } from "./Gatt"; +import { GattCharacteristic, GattService } from '../../../models'; +import { MacGatt } from './Gatt'; export declare class MacGattService extends GattService { readonly gatt: MacGatt; - addCharacteristic(uuid: string, props: GattCharacteristicProperty[], secure: GattCharacteristicProperty[], readFuncOrValue?: Buffer | ReadFunction, writeFunc?: WriteFunction): Promise; + addCharacteristic(): Promise; discoverCharacteristics(): Promise; } //# sourceMappingURL=Service.d.ts.map \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Service.d.ts.map b/lib/bindings/mac/gatt/Service.d.ts.map index 3e06e832..931e0007 100644 --- a/lib/bindings/mac/gatt/Service.d.ts.map +++ b/lib/bindings/mac/gatt/Service.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG3H,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,qBAAa,cAAe,SAAQ,WAAW;IAC3C,SAAgB,IAAI,EAAE,OAAO,CAAC;IAEvB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,0BAA0B,EAAE,EAAE,MAAM,EAAE,0BAA0B,EAAE,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI3M,uBAAuB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAmBlE"} \ No newline at end of file +{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA8B,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9F,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,qBAAa,cAAe,SAAQ,WAAW;IAC9C,SAAgB,IAAI,EAAE,OAAO,CAAC;IAEvB,iBAAiB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAIhD,uBAAuB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAuB/D"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/Service.js b/lib/bindings/mac/gatt/Service.js index 8cff25b3..17d34c22 100644 --- a/lib/bindings/mac/gatt/Service.js +++ b/lib/bindings/mac/gatt/Service.js @@ -4,24 +4,24 @@ exports.MacGattService = void 0; const models_1 = require("../../../models"); const Characteristic_1 = require("./Characteristic"); class MacGattService extends models_1.GattService { - addCharacteristic(uuid, props, secure, readFuncOrValue, writeFunc) { - throw new Error("Method not implemented."); + addCharacteristic() { + throw new Error('Method not implemented.'); } discoverCharacteristics() { const noble = this.gatt.peripheral.adapter.noble; this.characteristics.clear(); noble.discoverCharacteristics(this.gatt.peripheral.uuid, this.uuid); - return new Promise((resolve, reject) => { + return new Promise((resolve) => { const handler = (uuid, serviceUUID, characteristics) => { if (uuid === this.gatt.peripheral.uuid && serviceUUID === this.uuid) { - noble.off("characteristicsDiscover", handler); + noble.off('characteristicsDiscover', handler); for (const char of characteristics) { this.characteristics.set(char.uuid, new Characteristic_1.MacGattCharacteristic(this, char.uuid, true, char.properties, [])); } resolve([...this.characteristics.values()]); } }; - noble.on("characteristicsDiscover", handler); + noble.on('characteristicsDiscover', handler); }); } } diff --git a/lib/bindings/mac/gatt/Service.js.map b/lib/bindings/mac/gatt/Service.js.map index 094d5aaa..42d4c4e9 100644 --- a/lib/bindings/mac/gatt/Service.js.map +++ b/lib/bindings/mac/gatt/Service.js.map @@ -1 +1 @@ -{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/Service.ts"],"names":[],"mappings":";;;AAAA,4CAA2H;AAE3H,qDAAyD;AAGzD,MAAa,cAAe,SAAQ,oBAAW;IAGpC,iBAAiB,CAAC,IAAY,EAAE,KAAmC,EAAE,MAAoC,EAAE,eAAuC,EAAE,SAAyB;QAChL,MAAM,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mac/gatt/index.d.ts +++ b/lib/bindings/mac/gatt/index.d.ts @@ -1,4 +1,5 @@ export * from './Characteristic'; +export * from './Descriptor'; export * from './Gatt'; export * from './Service'; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib/bindings/mac/gatt/index.d.ts.map b/lib/bindings/mac/gatt/index.d.ts.map index 808a0c70..f7d74a40 100644 --- a/lib/bindings/mac/gatt/index.d.ts.map +++ b/lib/bindings/mac/gatt/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC"} \ No newline at end of file diff --git a/lib/bindings/mac/gatt/index.js b/lib/bindings/mac/gatt/index.js index 5c2e7d74..2da1569d 100644 --- a/lib/bindings/mac/gatt/index.js +++ b/lib/bindings/mac/gatt/index.js @@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { }; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./Characteristic"), exports); +__exportStar(require("./Descriptor"), exports); __exportStar(require("./Gatt"), exports); __exportStar(require("./Service"), exports); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/bindings/mac/gatt/index.js.map b/lib/bindings/mac/gatt/index.js.map index 9191cf64..689ee544 100644 --- a/lib/bindings/mac/gatt/index.js.map +++ b/lib/bindings/mac/gatt/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AACjC,yCAAuB;AACvB,4CAA0B"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/bindings/mac/gatt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AACjC,+CAA6B;AAC7B,yCAAuB;AACvB,4CAA0B"} \ No newline at end of file diff --git a/lib/bindings/mac/index.d.ts b/lib/bindings/mac/index.d.ts index 80bae48c..42d71974 100644 --- a/lib/bindings/mac/index.d.ts +++ b/lib/bindings/mac/index.d.ts @@ -1,3 +1,4 @@ export * from './Adapter'; export * from './MODblue'; +export * from './Peripheral'; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib/bindings/mac/index.d.ts.map b/lib/bindings/mac/index.d.ts.map index e2b1b41f..6d86f7ae 100644 --- a/lib/bindings/mac/index.d.ts.map +++ b/lib/bindings/mac/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bindings/mac/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bindings/mac/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"} \ No newline at end of file diff --git a/lib/bindings/mac/index.js b/lib/bindings/mac/index.js index a7808087..d2d9b004 100644 --- a/lib/bindings/mac/index.js +++ b/lib/bindings/mac/index.js @@ -12,4 +12,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./Adapter"), exports); __exportStar(require("./MODblue"), exports); +__exportStar(require("./Peripheral"), exports); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/bindings/mac/index.js.map b/lib/bindings/mac/index.js.map index 25b761f4..ea35d717 100644 --- a/lib/bindings/mac/index.js.map +++ b/lib/bindings/mac/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bindings/mac/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bindings/mac/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B"} \ No newline at end of file diff --git a/src/bindings/mac/Adapter.ts b/src/bindings/mac/Adapter.ts index 3ea6f9b3..444407fd 100644 --- a/src/bindings/mac/Adapter.ts +++ b/src/bindings/mac/Adapter.ts @@ -1,5 +1,5 @@ -const events = require('events'); -const util = require('util'); +import events from 'events'; +import util from 'util'; import { Adapter, AddressType, GattLocal, MODblue, Peripheral } from '../../models'; import { MacPeripheral } from './Peripheral'; @@ -10,6 +10,7 @@ util.inherits(NobleMac, events.EventEmitter); export class MacAdapter extends Adapter { public readonly noble: any = null; + private initDone = false; private scanning = false; @@ -41,10 +42,13 @@ export class MacAdapter extends Adapter { this.noble.init(); }); + this.noble.on('read', this.onNotification); + this.initDone = true; } public dispose(): void { + this.noble.removeAllListeners(); this.noble.stop(); } @@ -52,20 +56,56 @@ export class MacAdapter extends Adapter { await this.init(); this.peripherals.clear(); this.noble.startScanning(serviceUUIDs, allowDuplicates); - this.noble.on("discover", this.onDiscover); + this.noble.on('discover', this.onDiscover); this.scanning = true; } - private onDiscover = (uuid: string, address: string, addressType: AddressType, connectable: boolean, advertisement: {localName?: string; manufacturerData?: Buffer}, rssi: number) => { + private onDiscover = ( + uuid: string, + address: string, + addressType: AddressType, + connectable: boolean, + advertisement: { localName?: string; manufacturerData?: Buffer }, + rssi: number + ) => { let peripheral = this.peripherals.get(uuid); if (!peripheral) { - peripheral = new MacPeripheral(this, uuid, advertisement.localName, addressType, address, advertisement.manufacturerData, rssi); + peripheral = new MacPeripheral( + this, + uuid, + advertisement.localName, + addressType, + address, + advertisement.manufacturerData, + rssi + ); } else { peripheral.name = advertisement.localName; peripheral.manufacturerData = advertisement.manufacturerData; } this.emit('discover', peripheral); - } + }; + + private onNotification = ( + uuid: string, + serviceUUID: string, + charUUID: string, + data: Buffer, + isNotification: boolean + ) => { + if (isNotification) { + const peripheral = this.peripherals.get(uuid); + if (peripheral) { + const service = peripheral.gatt.services.get(serviceUUID); + if (service) { + const char = service.characteristics.get(charUUID); + if (char) { + char.emit('notification', data); + } + } + } + } + }; public async stopScanning(): Promise { this.noble.stopScanning(); @@ -80,7 +120,7 @@ export class MacAdapter extends Adapter { throw new Error('Method not implemented.'); } - public startAdvertising(deviceName: string, serviceUUIDs?: string[]): Promise { + public startAdvertising(): Promise { throw new Error('Method not implemented.'); } @@ -88,7 +128,7 @@ export class MacAdapter extends Adapter { throw new Error('Method not implemented.'); } - public setupGatt(maxMtu?: number): Promise { + public setupGatt(): Promise { throw new Error('Method not implemented.'); } } diff --git a/src/bindings/mac/Peripheral.ts b/src/bindings/mac/Peripheral.ts index 3b134ffb..4147ea09 100644 --- a/src/bindings/mac/Peripheral.ts +++ b/src/bindings/mac/Peripheral.ts @@ -1,51 +1,58 @@ -import { AddressType, ConnectOptions, GattRemote, Peripheral } from "../../models"; +import { AddressType, GattRemote, Peripheral } from '../../models'; -import { MacAdapter } from "./Adapter"; -import { MacGatt } from "./gatt"; +import { MacAdapter } from './Adapter'; +import { MacGatt } from './gatt'; export class MacPeripheral extends Peripheral { - - public readonly adapter: MacAdapter; - - public constructor(adapter: MacAdapter, uuid: string, name: string, addressType: AddressType, address: string, manufacturerData: Buffer, rssi: number) { - super(adapter, uuid, name, addressType, address, manufacturerData, rssi); - } - - public async connect(options?: ConnectOptions): Promise { - this._state = 'connecting'; + public readonly adapter: MacAdapter; + + public constructor( + adapter: MacAdapter, + uuid: string, + name: string, + addressType: AddressType, + address: string, + manufacturerData: Buffer, + rssi: number + ) { + super(adapter, uuid, name, addressType, address, manufacturerData, rssi); + } + + public async connect(): Promise { + this._state = 'connecting'; this.adapter.noble.connect(this.uuid); - await new Promise((resolve, reject) => { + await new Promise((resolve) => { const connHandler = (uuid: string) => { if (uuid === this.uuid) { - this.adapter.noble.off("connect", connHandler); + this.adapter.noble.off('connect', connHandler); resolve(); } }; - this.adapter.noble.on("connect", connHandler); + this.adapter.noble.on('connect', connHandler); }); - this._gatt = new MacGatt(this); - this._state = 'connected'; - return this._gatt; - } + this._gatt = new MacGatt(this); + this._state = 'connected'; + return this._gatt; + } - public async disconnect(): Promise { - this._state = 'disconnecting'; + public async disconnect(): Promise { + this._state = 'disconnecting'; this.adapter.noble.disconnect(this.uuid); - await new Promise((resolve, reject) => { + await new Promise((resolve) => { const disconnHandler = (uuid: string) => { if (uuid === this.uuid) { - this.adapter.noble.off("disconnect", disconnHandler); + this.adapter.noble.off('disconnect', disconnHandler); resolve(); } }; - this.adapter.noble.on("disconnect", disconnHandler); + this.adapter.noble.on('disconnect', disconnHandler); }); - this._state = 'disconnected'; - } -} \ No newline at end of file + this._state = 'disconnected'; + } +} diff --git a/src/bindings/mac/gatt/Characteristic.ts b/src/bindings/mac/gatt/Characteristic.ts index 33c3f199..774d2687 100644 --- a/src/bindings/mac/gatt/Characteristic.ts +++ b/src/bindings/mac/gatt/Characteristic.ts @@ -1,38 +1,89 @@ -import { GattCharacteristic, GattDescriptor } from "../../../models"; +import { GattCharacteristic, GattDescriptor } from '../../../models'; +import { MacGattDescriptor } from './Descriptor'; -import { MacGattService } from "./Service"; +import { MacGattService } from './Service'; export class MacGattCharacteristic extends GattCharacteristic { - public readonly service: MacGattService; - - public discoverDescriptors(): Promise { - throw new Error("Method not implemented."); - } - public read(): Promise { - const noble = this.service.gatt.peripheral.adapter.noble; - - noble.read(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid); - - return new Promise((resolve, reject) => { - const handler = (uuid: string, serviceUUID: string, charUUID: string, data: Buffer) => { - if (uuid === this.service.gatt.peripheral.uuid && serviceUUID === this.service.uuid && charUUID === this.uuid) { - noble.off("read", handler); - resolve(data); - } - } - noble.on("read", handler); - }); - } - public write(data: Buffer, withoutResponse: boolean): Promise { - throw new Error("Method not implemented."); - } - public broadcast(broadcast: boolean): Promise { - throw new Error("Method not implemented."); - } - public notify(notify: boolean): Promise { - throw new Error("Method not implemented."); - } - public addDescriptor(uuid: string, value: Buffer): Promise { - throw new Error("Method not implemented."); - } + public readonly service: MacGattService; + + public discoverDescriptors(): Promise { + const noble = this.service.gatt.peripheral.adapter.noble; + + this.descriptors.clear(); + noble.discoverDescriptors(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid); + + return new Promise((resolve) => { + const handler = (dev: string, srv: string, char: string, descUUIDs: string[]) => { + if (dev === this.service.gatt.peripheral.uuid && srv === this.service.uuid && char === this.uuid) { + noble.off('descriptorsDiscover', handler); + for (const descUUID of descUUIDs) { + this.descriptors.set(descUUID, new MacGattDescriptor(this, descUUID, true)); + } + resolve([...this.descriptors.values()]); + } + }; + noble.on('descriptorsDiscover', handler); + }); + } + + public read(): Promise { + const noble = this.service.gatt.peripheral.adapter.noble; + + noble.read(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid); + + return new Promise((resolve) => { + const handler = (dev: string, srv: string, char: string, data: Buffer, isNotification: boolean) => { + if ( + dev === this.service.gatt.peripheral.uuid && + srv === this.service.uuid && + char === this.uuid && + isNotification + ) { + noble.off('read', handler); + resolve(data); + } + }; + noble.on('read', handler); + }); + } + + public write(value: Buffer): Promise { + const noble = this.service.gatt.peripheral.adapter.noble; + + noble.write(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid, value); + + return new Promise((resolve) => { + const handler = (dev: string, srv: string, char: string) => { + if (dev === this.service.gatt.peripheral.uuid && srv === this.service.uuid && char === this.uuid) { + noble.off('write', handler); + resolve(); + } + }; + noble.on('write', handler); + }); + } + + public broadcast(): Promise { + throw new Error('Method not implemented.'); + } + + public notify(notify: boolean): Promise { + const noble = this.service.gatt.peripheral.adapter.noble; + + noble.notify(this.service.gatt.peripheral.uuid, this.service.uuid, this.uuid, notify); + + return new Promise((resolve) => { + const handler = (dev: string, srv: string, char: string) => { + if (dev === this.service.gatt.peripheral.uuid && srv === this.service.uuid && char === this.uuid) { + noble.off('notify', handler); + resolve(); + } + }; + noble.on('notify', handler); + }); + } + + public addDescriptor(): Promise { + throw new Error('Method not implemented.'); + } } diff --git a/src/bindings/mac/gatt/Descriptor.ts b/src/bindings/mac/gatt/Descriptor.ts new file mode 100644 index 00000000..fa506816 --- /dev/null +++ b/src/bindings/mac/gatt/Descriptor.ts @@ -0,0 +1,60 @@ +import { GattDescriptor } from '../../../models'; + +import { MacGattCharacteristic } from './Characteristic'; + +export class MacGattDescriptor extends GattDescriptor { + public readonly characteristic: MacGattCharacteristic; + + public read(): Promise { + const noble = this.characteristic.service.gatt.peripheral.adapter.noble; + + noble.readValue( + this.characteristic.service.gatt.peripheral.uuid, + this.characteristic.service.uuid, + this.characteristic.uuid, + this.uuid + ); + + return new Promise((resolve) => { + const handler = (dev: string, srv: string, char: string, desc: string, data: Buffer) => { + if ( + dev === this.characteristic.service.gatt.peripheral.uuid && + srv === this.characteristic.service.uuid && + char === this.characteristic.uuid && + desc === this.uuid + ) { + noble.off('valueRead', handler); + resolve(data); + } + }; + noble.on('valueRead', handler); + }); + } + + public write(value: Buffer): Promise { + const noble = this.characteristic.service.gatt.peripheral.adapter.noble; + + noble.writeValue( + this.characteristic.service.gatt.peripheral.uuid, + this.characteristic.service.uuid, + this.characteristic.uuid, + this.uuid, + value + ); + + return new Promise((resolve) => { + const handler = (dev: string, srv: string, char: string, desc: string) => { + if ( + dev === this.characteristic.service.gatt.peripheral.uuid && + srv === this.characteristic.service.uuid && + char === this.characteristic.uuid && + desc === this.uuid + ) { + noble.off('valueWrite', handler); + resolve(); + } + }; + noble.on('valueWrite', handler); + }); + } +} diff --git a/src/bindings/mac/gatt/Gatt.ts b/src/bindings/mac/gatt/Gatt.ts index 81c921e1..3f2f25ad 100644 --- a/src/bindings/mac/gatt/Gatt.ts +++ b/src/bindings/mac/gatt/Gatt.ts @@ -1,28 +1,28 @@ -import { GattRemote, GattService } from "../../../models" +import { GattRemote, GattService } from '../../../models'; -import { MacPeripheral } from "../Peripheral"; -import { MacGattService } from "./Service"; +import { MacPeripheral } from '../Peripheral'; +import { MacGattService } from './Service'; export class MacGatt extends GattRemote { - public readonly peripheral: MacPeripheral; + public readonly peripheral: MacPeripheral; - public discoverServices(): Promise { - const noble = this.peripheral.adapter.noble; - - this.services.clear(); - noble.discoverServices(this.peripheral.uuid); + public discoverServices(): Promise { + const noble = this.peripheral.adapter.noble; - return new Promise((resolve, reject) => { - const handler = (uuid: string, serviceUUIDs: string[]) => { - if (uuid === this.peripheral.uuid) { - noble.off("servicesDiscover", handler); - for (const srvUUID of serviceUUIDs) { - this.services.set(srvUUID, new MacGattService(this, srvUUID, true)); - } - resolve([...this.services.values()]); - } - } - noble.on("servicesDiscover", handler); - }); - } + this.services.clear(); + noble.discoverServices(this.peripheral.uuid); + + return new Promise((resolve) => { + const handler = (uuid: string, serviceUUIDs: string[]) => { + if (uuid === this.peripheral.uuid) { + noble.off('servicesDiscover', handler); + for (const srvUUID of serviceUUIDs) { + this.services.set(srvUUID, new MacGattService(this, srvUUID, true)); + } + resolve([...this.services.values()]); + } + }; + noble.on('servicesDiscover', handler); + }); + } } diff --git a/src/bindings/mac/gatt/Service.ts b/src/bindings/mac/gatt/Service.ts index 4f824aef..dc364c99 100644 --- a/src/bindings/mac/gatt/Service.ts +++ b/src/bindings/mac/gatt/Service.ts @@ -1,32 +1,36 @@ -import { GattCharacteristic, GattCharacteristicProperty, GattService, ReadFunction, WriteFunction } from "../../../models"; +import { GattCharacteristic, GattCharacteristicProperty, GattService } from '../../../models'; -import { MacGattCharacteristic } from "./Characteristic"; -import { MacGatt } from "./Gatt"; +import { MacGattCharacteristic } from './Characteristic'; +import { MacGatt } from './Gatt'; export class MacGattService extends GattService { - public readonly gatt: MacGatt; + public readonly gatt: MacGatt; - public addCharacteristic(uuid: string, props: GattCharacteristicProperty[], secure: GattCharacteristicProperty[], readFuncOrValue?: Buffer | ReadFunction, writeFunc?: WriteFunction): Promise { - throw new Error("Method not implemented."); - } + public addCharacteristic(): Promise { + throw new Error('Method not implemented.'); + } - public discoverCharacteristics(): Promise { - const noble = this.gatt.peripheral.adapter.noble; - - this.characteristics.clear(); - noble.discoverCharacteristics(this.gatt.peripheral.uuid, this.uuid); + public discoverCharacteristics(): Promise { + const noble = this.gatt.peripheral.adapter.noble; - return new Promise((resolve, reject) => { - const handler = (uuid: string, serviceUUID: string, characteristics: { uuid: string, properties: GattCharacteristicProperty[] }[]) => { - if (uuid === this.gatt.peripheral.uuid && serviceUUID === this.uuid) { - noble.off("characteristicsDiscover", handler); - for (const char of characteristics) { - this.characteristics.set(char.uuid, new MacGattCharacteristic(this, char.uuid, true, char.properties, [])); - } - resolve([...this.characteristics.values()]); - } - } - noble.on("characteristicsDiscover", handler); - }); - } + this.characteristics.clear(); + noble.discoverCharacteristics(this.gatt.peripheral.uuid, this.uuid); + + return new Promise((resolve) => { + const handler = ( + uuid: string, + serviceUUID: string, + characteristics: { uuid: string; properties: GattCharacteristicProperty[] }[] + ) => { + if (uuid === this.gatt.peripheral.uuid && serviceUUID === this.uuid) { + noble.off('characteristicsDiscover', handler); + for (const char of characteristics) { + this.characteristics.set(char.uuid, new MacGattCharacteristic(this, char.uuid, true, char.properties, [])); + } + resolve([...this.characteristics.values()]); + } + }; + noble.on('characteristicsDiscover', handler); + }); + } } diff --git a/src/bindings/mac/gatt/index.ts b/src/bindings/mac/gatt/index.ts index e892b53f..8c368992 100644 --- a/src/bindings/mac/gatt/index.ts +++ b/src/bindings/mac/gatt/index.ts @@ -1,3 +1,4 @@ export * from './Characteristic'; +export * from './Descriptor'; export * from './Gatt'; -export * from './Service'; \ No newline at end of file +export * from './Service'; diff --git a/src/bindings/mac/index.ts b/src/bindings/mac/index.ts index 3ca162d8..f4d7316f 100644 --- a/src/bindings/mac/index.ts +++ b/src/bindings/mac/index.ts @@ -1,2 +1,3 @@ export * from './Adapter'; export * from './MODblue'; +export * from './Peripheral';