npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alexgyver/ble

v1.0.10

Published

Web BLE Serial

Downloads

128

Readme

BLE.js

Обёртка на Web Bluetooth API

  • Автоматическое переподключение
  • Последовательная отправка без пересечения записей
  • Настраиваемое дробление больших отправок
  • Отдельная атомарная отправка одного BLE frame

demo

Browser: https://gyverlibs.github.io/BLE.js/BLE.min.js

Node: npm i @alexgyver/ble

Дока

constructor(params = {});
config(params = {});
// serviceUUID: '0000ffe0-0000-1000-8000-00805f9b34fb'
// rxUUID: '0000ffe1-0000-1000-8000-00805f9b34fb'
// txUUID: '0000ffe2-0000-1000-8000-00805f9b34fb'
// auto_open: false
// reconnect: 1000
// chunkSize: 500
// chunkDelay: 0
// withResponse: false

onbin(b);
ontext(t);

onopen():
onclose():
onchange(s):
onselect(name);
onerror(e);

static supported();
opened();
selected();
getName();
getRxProperties();
getTxProperties();
canWriteWithResponse();
canWriteWithoutResponse();
canIndicate();

select();
open();
close();

sendBin(data, options = {});
sendText(text, options = {});

Все методы отправки возвращают Promise<boolean>.

Дробление отправки

sendBin() делит данные на несколько BLE characteristic writes по chunkSize. Задержка между записями задаётся через chunkDelay:

const ble = new BLEJS({
    chunkSize: 100,
    chunkDelay: 5,
});

await ble.sendBin(data);

chunkSize <= 0 отключает дробление и выполняет одну characteristic write:

await ble.sendBin(data, { chunkSize: 0 });

Для протоколов, где одна BLE write является одним транспортным frame, отключите дробление для конкретной отправки:

const ok = await ble.sendBin(frame, { chunkSize: 0 });

Опция withResponse едина для всех методов отправки:

await ble.sendBin(data, { withResponse: true });
await ble.sendText('hello', { withResponse: true });

Для атомарного фрейма с GATT response обе опции можно совместить:

await ble.sendBin(frame, { withResponse: true, chunkSize: 0 });

При withResponse: true используется writeValueWithResponse(). Promise отправки завершается после ответа GATT-сервера, поэтому режим подходит для последовательной передачи с транспортным backpressure. Значение по умолчанию задаётся одноимённой настройкой конструктора.

Для обратной совместимости второй boolean-аргумент продолжает трактоваться как старый fast: true выбирает Write without Response, false — Write with Response. Третий аргумент старой формы задаёт chunkSize:

await ble.sendBin(data, false, 100);

Перед использованием можно проверить свойства найденных характеристик:

if (!ble.canWriteWithResponse()) throw new Error('Write with Response is unavailable');
if (!ble.canWriteWithoutResponse()) throw new Error('Write without Response is unavailable');
if (!ble.canIndicate()) throw new Error('Indications are unavailable');

getRxProperties() и getTxProperties() возвращают объект BluetoothCharacteristicProperties либо null, пока соединение не открыто. startNotifications() включает доступный режим, но не позволяет JavaScript принудительно выбрать Indication вместо Notification. Если протоколу нужны именно Indication, TX characteristic на устройстве следует объявлять как indicate-only.

Проверка поддержки выбранного способа записи выполняется внутри sendBin(). При несовместимой RX characteristic метод вызывает onerror и возвращает false.