Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tkomde/electron-webbluetooth

Connection sample of webbluetooth in electron
https://github.com/tkomde/electron-webbluetooth

electron electron-webbluetooth webbluetooth

Last synced: about 1 month ago
JSON representation

Connection sample of webbluetooth in electron

Awesome Lists containing this project

README

        

# electron-WebBluetooth

WebBluetooth integration sample with electron.
Supports selecting multiple device.

## Prerequisites

- electron(>=3 will work)
- bootstrap(included)

## Run

- npm i
- npx electron .

## How it works

1. In renderer, scan() to get device list.
1. The devices list is notified periodically via IPC to main process.
1. If you find the deviceId you want to connect, select and notify to main.
1. Connection callback called only once in main.
1. When disconnected, automatically reconnect former connected device.

## Restrictions to implement WebBluetooth in electron

- If event.preventDefault is not called, first available device will be selected.
- Callback should be called with deviceId to be selected, passing empty string to callback will **cancel** the request.
- Calling requestDevice twice causes automatically cancel the former one.

## Link

[Electron Documentation - webContents - select-bluetooth-device](https://electronjs.org/docs/api/web-contents#event-select-bluetooth-device)
[Electron Documentation - webContents - executejavascriptcode-usergesture](https://electronjs.org/docs/api/web-contents#contentsexecutejavascriptcode-usergesture)

## License

MIT