Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected CheckForCharacteristic(aEndpoint: Endpoints) {
if (this._characteristics.has(aEndpoint)) {
return;
}
const err = `Device ${this._device.advertisement.localName} has no endpoint named ${aEndpoint}`;
throw new ButtplugDeviceException(err);
}
public SubscribeToUpdatesInternal = async (aOptions: ButtplugDeviceReadOptions): Promise => {
this.CheckForCharacteristic(aOptions.Endpoint);
this._logger.Debug(`Subscripting to updates on noble device ${this._device.advertisement.localName}`);
const chr = this._characteristics.get(aOptions.Endpoint)!;
if (chr.properties.find((x) => x === "notify" || x === "indicate") === undefined) {
const err = `Device ${this._device.advertisement.localName} endpoint ${aOptions.Endpoint}` +
` does not have notify or indicate properties.`;
throw new ButtplugDeviceException(err);
}
this._notificationHandlers.set(aOptions.Endpoint, (aData: Buffer, aIsNotification: boolean) => {
this.CharacteristicValueChanged(aOptions.Endpoint, aData, aIsNotification);
});
await util.promisify(chr.subscribe.bind(chr))();
chr.on("data", this._notificationHandlers.get(aOptions.Endpoint)!);
}