@wisdomgarden/capacitor-plugin-beacon
v0.0.4
Published
Capacitor plugin for Bluetooth beacon broadcasting and monitoring
Downloads
12
Readme
Capacitor Beacon Plugin
A Capacitor plugin for Bluetooth beacon functionality.
Installation
npm install @wisdomgarden/capacitor-plugin-beacon
npx cap syncAPI
initialize
Initialize the beacon plugin.
await Beacon.initialize({ allowDuplicatesKey: true });startBroadcasting
Start broadcasting as a beacon. You can either provide a complete message or individual components.
await Beacon.startBroadcasting({
rollcallId: 123,
nonce: "ZABC"
});stopBroadcasting
Stop broadcasting as a beacon.
await Beacon.stopBroadcasting();startMonitoring
Start monitoring for nearby beacons.
await Beacon.startMonitoring();stopMonitoring
Stop monitoring for nearby beacons.
await Beacon.stopMonitoring();cleanup
Clean up all beacon-related resources.
await Beacon.cleanup();parseMessage
Parse a beacon message into its components.
const result = await Beacon.parseMessage({ message: "xxxxxx" });
// Returns: { rollcallId: number, nonce: string }Events
beaconReceived
Emitted when a beacon is discovered.
Beacon.addListener('beaconReceived', (data) => {
console.log('Received beacon:', data);
// data: { message: string, rssi: number, peripheralId: string, timestamp: number }
});stateUpdated
Emitted when the peripheral state changes.
Beacon.addListener('stateUpdated', (data) => {
console.log('State updated:', data);
// data: { type: 'peripheral', state: 'poweredOn' | 'poweredOff' | 'unauthorized' | 'unsupported' | number }
});stateError
Emitted when there's an error with the beacon state.
Beacon.addListener('stateError', (data) => {
console.log('State error:', data);
// data: { type: 'peripheral' | 'central', state: string }
});bluetoothStateChanged
Emitted when the Bluetooth state changes.
Beacon.addListener('bluetoothStateChanged', (data) => {
console.log('Bluetooth state changed:', data);
// data: { enabled: boolean, error?: string }
});Platform Support
- iOS ✅
- Android ✅
- Web ❌ (Not supported)
Platform Specific Notes
iOS
- Requires
NSBluetoothAlwaysUsageDescriptionandNSBluetoothPeripheralUsageDescriptionin Info.plist - Minimum iOS version: 11.0
Android
- Requires
BLUETOOTH,BLUETOOTH_ADMIN,BLUETOOTH_SCAN,BLUETOOTH_CONNECT, andBLUETOOTH_ADVERTISEpermissions - Minimum Android version: API level 21 (Android 5.0)
- Requires location services to be enabled for scanning beacons
License
Apache-2.0
