Blazm.Bluetooth icon indicating copy to clipboard operation
Blazm.Bluetooth copied to clipboard

Missing CancelNotifyAsync()

Open mheyman opened this issue 3 years ago • 3 comments

There is a SetupNotifyAsync() call but no matching CancelNotifyAsync() - the best workaround I can figure is to ignore the characteristic within the notify handler even long after that characteristic is no longer relevant.

I'm new to C#+javascript and bluetooth but a quick search leads me to believe the javascript could look like:

export async function cancelNotify(deviceId, serviceId, characteristicId)
{
    var device = getDevice(deviceId);
    var service = await device.gatt.getPrimaryService(serviceId);
    var characteristic = await service.getCharacteristic(characteristicId);
    characteristic.removeEventListener('characteristicvaluechanged', handleCharacteristicValueChanged);
    await characteristic.stopNotifications();
}

and the C# could be (in the BluetootNavigator class):

public async Task TeardownNotifyAsync(Device device, string serviceId, string characteristicId)
{
   var module = await moduleTask.Value;
   await module.InvokeVoidAsync("cancelNotify", device.Id, serviceId.ToLowerInvariant(), characteristicId.ToLowerInvariant());
}

but I really don't know how the List<DotNetObjectReference<Device>> NotificationHandlers in the setup notifications code fits in so am leery of trying this...

mheyman avatar Nov 14 '21 16:11 mheyman

I have totally missed this, kinda embarrassing =) I'll take a look and try to implement that. Thanks for the code!

EngstromJimmy avatar Feb 25 '23 12:02 EngstromJimmy