thegecko / webbluetooth

Node.js implementation of the Web Bluetooth Specification
https://thegecko.github.io/webbluetooth/
MIT License
150 stars 23 forks source link

Get the MTU #263

Open maelp opened 1 week ago

maelp commented 1 week ago

Is there a way to get the peripheral MTU?

thegecko commented 1 week ago

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

maelp commented 1 week ago

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

thegecko commented 1 week ago

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

maelp commented 1 week ago

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)

thegecko commented 1 week ago

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.