@ledgerhq/hw-transport-web-ble
Version:
Ledger Hardware Wallet Web Bluetooth implementation of the communication layer
23 lines • 977 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.monitorCharacteristic = void 0;
const rxjs_1 = require("rxjs");
const logs_1 = require("@ledgerhq/logs");
const monitorCharacteristic = (characteristic) => rxjs_1.Observable.create(o => {
(0, logs_1.log)("ble-verbose", "start monitor " + characteristic.uuid);
function onCharacteristicValueChanged(event) {
const characteristic = event.target;
if (characteristic.value) {
o.next(Buffer.from(characteristic.value.buffer));
}
}
characteristic.startNotifications().then(() => {
characteristic.addEventListener("characteristicvaluechanged", onCharacteristicValueChanged);
});
return () => {
(0, logs_1.log)("ble-verbose", "end monitor " + characteristic.uuid);
characteristic.stopNotifications();
};
});
exports.monitorCharacteristic = monitorCharacteristic;
//# sourceMappingURL=monitorCharacteristic.js.map