@wisdomgarden/capacitor-plugin-beacon
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Capacitor Beacon Plugin

A Capacitor plugin for Bluetooth beacon functionality.

Installation

npm install @wisdomgarden/capacitor-plugin-beacon
npx cap sync

API

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 NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription in Info.plist
  • Minimum iOS version: 11.0

Android

  • Requires BLUETOOTH, BLUETOOTH_ADMIN, BLUETOOTH_SCAN, BLUETOOTH_CONNECT, and BLUETOOTH_ADVERTISE permissions
  • Minimum Android version: API level 21 (Android 5.0)
  • Requires location services to be enabled for scanning beacons

License

Apache-2.0

Readme

Keywords

Package Sidebar

Install

npm i @wisdomgarden/capacitor-plugin-beacon

Weekly Downloads

11

Version

0.0.1

License

Apache-2.0

Unpacked Size

299 kB

Total Files

84

Last publish

Collaborators

  • chenzhiyuan01
  • chenyunjie1
  • peixin
  • wg-kevinlin
  • dengzhirong93
  • zihning
  • yaoxiangyi