webbluetooth icon indicating copy to clipboard operation
webbluetooth copied to clipboard

Get the MTU

Open maelp opened this issue 1 year ago • 5 comments

Is there a way to get the peripheral MTU?

maelp avatar Oct 17 '24 23:10 maelp

Since switching to SimpleBLE, we are reliant on what that exposes, so that needs cheking.

I'm not sure where we would expose it, I can't see the Webbluetooth specification mentions exposing it

thegecko avatar Oct 19 '24 17:10 thegecko

Hmmm... but if you don't expose MTU, how do I know how many bytes can fit in a packet?

maelp avatar Oct 20 '24 00:10 maelp

https://github.com/WebBluetoothCG/web-bluetooth/issues/383

thegecko avatar Oct 20 '24 07:10 thegecko

BTW when using your library in a browser environment, does your library automatically switch to the underlying Webbluetooth backend? Or does the user have to do something like

const ble = env.NODE ? import "webbluetooth" : new window.WebBluetooth()

or equivalent? And would that be complicated to implement other third-party backends (I'm thinking about https://github.com/capacitor-community/bluetooth-le)

(if this was done "transparently" it would allow me to use your lib in a third-party lib that could be used both in Node and in the browser, and in a Capacitor iOS / Android app, which would be really convenient)

maelp avatar Oct 20 '24 09:10 maelp

This library requires native modules, so would never work in a browser. Ideally you should be creating different builds for web and desktop and depending on your packaging environment you should be able to trivially swap this in when building on desktop. It aims to follow the webbluetooth spec so the API is the same as the native web one.

thegecko avatar Oct 20 '24 09:10 thegecko

There is a hidden property on the peripheral named _adData which isn't in the webbluetooth specification. This is used to access advertisement data not present in the spec.

I've exposed the mtu value in that property in: https://github.com/thegecko/webbluetooth/pull/300

thegecko avatar Feb 18 '25 22:02 thegecko

Released in v3.3.2

thegecko avatar Mar 09 '25 02:03 thegecko