A Capacitor plugin for Bluetooth beacon functionality.
npm install @wisdomgarden/capacitor-plugin-beacon
npx cap sync
Initialize the beacon plugin.
await Beacon.initialize({ allowDuplicatesKey: true });
Start broadcasting as a beacon. You can either provide a complete message or individual components.
await Beacon.startBroadcasting({
rollcallId: 123,
nonce: "ZABC"
});
Stop broadcasting as a beacon.
await Beacon.stopBroadcasting();
Start monitoring for nearby beacons.
await Beacon.startMonitoring();
Stop monitoring for nearby beacons.
await Beacon.stopMonitoring();
Clean up all beacon-related resources.
await Beacon.cleanup();
Parse a beacon message into its components.
const result = await Beacon.parseMessage({ message: "xxxxxx" });
// Returns: { rollcallId: number, nonce: string }
Emitted when a beacon is discovered.
Beacon.addListener('beaconReceived', (data) => {
console.log('Received beacon:', data);
// data: { message: string, rssi: number, peripheralId: string, timestamp: number }
});
Emitted when the peripheral state changes.
Beacon.addListener('stateUpdated', (data) => {
console.log('State updated:', data);
// data: { type: 'peripheral', state: 'poweredOn' | 'poweredOff' | 'unauthorized' | 'unsupported' | number }
});
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 }
});
Emitted when the Bluetooth state changes.
Beacon.addListener('bluetoothStateChanged', (data) => {
console.log('Bluetooth state changed:', data);
// data: { enabled: boolean, error?: string }
});
- iOS ✅
- Android ✅
- Web ❌ (Not supported)
- Requires
NSBluetoothAlwaysUsageDescription
andNSBluetoothPeripheralUsageDescription
in Info.plist - Minimum iOS version: 11.0
- Requires
BLUETOOTH
,BLUETOOTH_ADMIN
,BLUETOOTH_SCAN
,BLUETOOTH_CONNECT
, andBLUETOOTH_ADVERTISE
permissions - Minimum Android version: API level 21 (Android 5.0)
- Requires location services to be enabled for scanning beacons
Apache-2.0