Expand description
Web Bluetooth for Node.js and Deno.
Neither runtime has navigator.bluetooth — that is a browser API, and a
server-side JavaScript runtime has no device picker and no permission
prompt to build one on. So unlike the WebAssembly backend, which uses
the browser’s Web Bluetooth, this one provides it: the same
CoreBluetooth, BlueZ, WinRT and HCI implementations the Rust crate uses,
exposed to JavaScript.
§Why not neon, or napi-rs
Node-API is a C ABI with an explicit stability guarantee — that is the entire reason it exists. A module built against it keeps working across Node major versions without recompiling, and Deno and Bun implement the same ABI. Declaring it is no more exotic than the JNI, COM and Objective-C-runtime declarations elsewhere in this workspace, and it keeps the dependency count where the rest of the project keeps it: zero.
§One addon, both runtimes
Deno implements Node-API, so the same .node file loads in both:
// Node
const bluetooth = require('./webbluetooth.node');
// Deno — needs --allow-ffi --unstable-ffi
import { createRequire } from 'node:module';
const bluetooth = createRequire(import.meta.url)('./webbluetooth.node');§The consent problem
In a browser requestDevice shows the user a picker. Here there is nobody
to show. The default is webbluetooth::chooser::FirstMatch, which takes
the first device matching the filters — convenient, automatic, and a
removal of the consent step the Web Bluetooth security model is built on.
A caller that has a user to ask should pass a chooser callback and ask
them.
Macros§
- methods
- A method name and the callback behind it.
Structs§
- Instance
- The runtime, and the state that outlives a single call.
Functions§
- napi_
register_ ⚠module_ v1 - What Node calls when it loads the addon.