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

The scanningfinished event is emitted at the wrong time (as far as I can tell). #89

Open
phckr opened this issue Oct 7, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@phckr
Copy link

phckr commented Oct 7, 2021

Describe the bug
The scanningfinished event seems to be emitted at the wrong time. It seems to be emitted before the scanning actually starts.

Expected behavior
In particular if I start scanning and then click cancel on the chrome window to stop scanning, then I would expect to get a scanningfinished when that happens.

Example

https://phckr.github.io/testScanning.html

This is a very crude webpage that is based around the documented examples. This is using 1.0.14 as the 1.0.15 doesn't load.

At the bottom of the page, the event log is displayed. The output below was generated from loading the webpage and then clicking on click to start scanning and then clicking cancel on the popup. This latter event did not trigger any log message.

1633627392080: Init start
1633627392112: Waiting for connect
1633627392121: adding listeners
1633627406036: Scanning finished
1633627406036: Scanning started

Additional context
Running on Chrome 94 on Linux.

@phckr phckr added the bug Something isn't working label Oct 7, 2021
@qdot
Copy link
Member

qdot commented Oct 7, 2021

Thanks for pointing this out! This is a tough issue with how WebBluetooth works because we're essentially popping the device select dialog then saying "Ok we're done", which is different than every other system. I'll see if I can delay the scanningfinished event until after the promise for device select resolves.

@phckr
Copy link
Author

phckr commented Oct 7, 2021

My workflow is that the user is asked to pair a device, but if the device is already paired, when you press 'pair', you don't get either a scanningfinished or deviceadded message. I guess that this is because the device is already added. Maybe either send another deviceadded event, or send a devicerepaired event instead. You can test this with the same page that I posted above.

I'm trying to keep track of what is going on by reading the event stream.

@phckr
Copy link
Author

phckr commented Feb 26, 2022

After more research, I suspected that the root cause is that the JS implemention only uses the buttplug 5.1.4 library. Unfortunately, upgrading this to 5.1.7 doesn't work easily as the introduction of jsonschema somehow pulls in socket2 which doesn't compile on a wasm32 target. There are github issues on socket2 about making this work (at least to build without error): rust-lang/socket2#268

However, I don't actually think that 5.1.7 will fix the problem.

I'm wondering whether to just add a new event for scanningDone that maybe is only sent by the webbluetooth_manager.rs when the user press cancel in the browser popup.

I understand that this is difficult to solve in a platform independent way -- especially since the WASM version can't even use the current buttplug library version.

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

2 participants