Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing CancelNotifyAsync() #14

Open
mheyman opened this issue Nov 14, 2021 · 3 comments
Open

Missing CancelNotifyAsync() #14

mheyman opened this issue Nov 14, 2021 · 3 comments

Comments

@mheyman
Copy link

mheyman commented Nov 14, 2021

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...

@EngstromJimmy
Copy link
Owner

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

@LeagueRaINi
Copy link

Is this still being worked on?
I'm also wondering what NotificationHandlers is for and why there is one being created for every call to SetupNotifyAsync, shouldnt one handler be enough?

@EngstromJimmy
Copy link
Owner

It it not on top of my to-do list right now, but it is not abandoned :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants