EngstromJimmy / Blazm.Bluetooth

82 stars 14 forks source link

Must be handling a user gesture to show a permission request #24

Open Bengkel opened 1 year ago

Bengkel commented 1 year ago

I added the NuGet package to my Blazor WASM App and get following error message:

_message 'Failed to execute 'requestDevice' on 'Bluetooth': Must be handling a user gesture to show a permission request.\n Error: Failed to execute 'requestDevice' on 'Bluetooth': Must be handling a user gesture to show a permission request.\n at Module.requestDevice (https://localhost:44398/_content/Blazm.Bluetooth/Blazm.Bluetooth.js:7:44)\n at https://localhost:44398/_framework/blazor.webassembly.js:1:3332\n at new Promise (<anonymous>)\n at Object.beginInvokeJSFromDotNet (https://localhost:4439…(https://localhost:44398/_framework/blazor.webassembly.js:1:59849)\n at _mono_wasm_invoke_js_blazor (https://localhost:44398/_framework/dotnet.6.0.18.gsaaqh5ry8.js:1:195300)\n at https://localhost:44398/_framework/dotnet.wasm:wasm-function[219]:0x1a4c1\n at https://localhost:44398/_framework/dotnet.wasm:wasm-function[167]:0xce8f\n at https://localhost:44398/_framework/dotnet.wasm:wasm-function[166]:0xbd73\n at https://localhost:44398/_framework/dotnet.wasm:wasm-function[2815]:0xabf2c' string

EngstromJimmy commented 1 year ago

You need to place the call in a button. It's a security thing in the web browser API.

Bengkel commented 1 year ago

I did, this only works once.

  1. The first time it shows me the pairing pop-up in my browser. I can select my device and pair the device.
  2. When I start the project with Visual Studio the second time, "no compatbile devices found" is shown and it throws this error message.
  3. When I can pair the SetupNotifyAsync throws an other error:

'User cancelled the requestDevice() chooser.\nundefined'

or

'GATT Server is disconnected. Cannot retrieve services. (Re)connect first withdevice.gatt.connect.\nundefined'

Checked all Ids with edge://bluetooth-internals/#devices, and they are correct.

When I "forget" the device I am able to pair again.

Bengkel commented 1 year ago

This is the error message in the output window


Setting up
BluetoothDevice {NotificationHandler: N, id: 'XbdpjsWpppJGnQgMi0aGnw==', name: 'Bluno', gatt: BluetoothRemoteGATTServer, ongattserverdisconnected: null}
> Bluetooth Device disconnected
[12:11:42] Connecting to Bluetooth Device... ```
Bengkel commented 1 year ago

I fixed some problems by updating the firmware of my device. Most of the functionality works now. Only exception left is that I get when attaching the notification handler: 'GATT Error: Not supported.\nundefined'

Could this be related to the device?

EngstromJimmy commented 1 year ago

It could be. I have noticed this kind of problem before, but I don't think (I'm really guessing here) it is related to the Blazor implementation. It might be the browser implementation, or it might be the device. I am going to record a couple of videos on this, so I will test the library a bit.