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

Subscribe does not have the same behavior on Linux & WIndows #326

Open
TristonJ opened this issue Jul 27, 2023 · 1 comment
Open

Subscribe does not have the same behavior on Linux & WIndows #326

TristonJ opened this issue Jul 27, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@TristonJ
Copy link
Contributor

Describe the bug
Calling Peripheral.subscribe(char) has different behavior depending on if you are using the winrt backend or the bluez backend. On Windows each time you call subscribe a new stream of events is created (potentially resulting in duplicated events from a single characteristic). On linux, you can call subscribe as many times as you please, and each characteristic's events will only appear once in any stream returned from notifications().

This is actually pretty clear to see after looking at the Peripheral.subscribe impl for winrtble.

Expected behavior
I think, ideally, Windows would behave the same as Linux, allowing you to call subscribe multiple times for a single characteristic with no effect.

Actual behavior
Calling subscribe multiple times on windows will result in duplicated events in single stream returned by a call to notifications.

Additional context
None - but thank you for the great library!

@TristonJ TristonJ added the bug Something isn't working label Jul 27, 2023
@TristonJ
Copy link
Contributor Author

TristonJ commented Jul 27, 2023

In my limited testing, fixing this might be as simple as adding a check to the subscribe function in src/winrtble/ble/characteristic.rs:

pub async fn subscribe(&mut self, on_value_changed: NotifyEventHandler) -> Result<()> {
    if self.notify_token.is_some() {
        log::debug!("Already subscribed!");
        return Ok(())
    }
    ...

If that is a reasonable solution, I'm happy to raise a PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant