Uses Bluetooth LE to scan and advertise for nearby devices
Install
npm install @capacitor-community/capacitor-nearby
npx cap sync
API
initialize(...)
initialize(options: InitializeOptions) => Promise<void>
Initializes Bluetooth LE for advertising and scanning of nearby tokens.
Since: 1.0.0
reset()
reset() => Promise<void>
Stops and resets advertising and scanning of nearby tokens.
Since: 1.0.0
publish(...)
publish(options: PublishOptions) => Promise<void>
Start publishing nearby token.
Since: 1.0.0
unpublish()
unpublish() => Promise<void>
Stop publishing nearby token.
Since: 1.0.0
subscribe(...)
subscribe(options: SubscribeOptions) => Promise<void>
Start listening to nearby tokens.
Since: 1.0.0
unsubscribe()
unsubscribe() => Promise<void>
Stop listening to nearby tokens.
Since: 1.0.0
status()
status() => Promise<Status>
Returns status of operations and found tokens.
Returns: Promise<Status>
Since: 1.0.0
addListener('onPermissionChanged', ...)
addListener(eventName: 'onPermissionChanged', listenerFunc: (granted: boolean) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when permission is granted or revoked for this app to use Nearby.
Param | Type |
---|
eventName | 'onPermissionChanged' |
listenerFunc | (granted: boolean) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
addListener('onBluetoothStateChanged', ...)
addListener(eventName: 'onBluetoothStateChanged', listenerFunc: (state: BluetoothState) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when state of Bluetooth has changed.
Param | Type |
---|
eventName | 'onBluetoothStateChanged' |
listenerFunc | (state: BluetoothState) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
addListener('onFound', ...)
addListener(eventName: 'onFound', listenerFunc: BeaconCallback) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when beacons are found.
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.1.0
addListener('onLost', ...)
addListener(eventName: 'onLost', listenerFunc: BeaconCallback) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when a beacon is no longer detectable nearby.
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.1.0
addListener('onPublishExpired', ...)
addListener(eventName: 'onPublishExpired', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
The published token has expired.
Param | Type |
---|
eventName | 'onPublishExpired' |
listenerFunc | () => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
addListener('onSubscribeExpired', ...)
addListener(eventName: 'onSubscribeExpired', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
The subscription has expired.
Param | Type |
---|
eventName | 'onSubscribeExpired' |
listenerFunc | () => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
Interfaces
InitializeOptions
Prop | Type | Description | Default | Since |
---|
serviceUUID | UUID | Sets the service UUID for the nearby token. | | 1.0.0 |
scanMode | ScanMode | Sets the scan mode. Default: Perform Bluetooth LE scan in balanced power mode. | ScanMode.BALANCED | 1.0.0 |
advertiseMode | AdvertiseMode | Sets the advertise mode. Default: Perform Bluetooth LE advertising in low latency, high power mode. | AdvertiseMode.LOW_LATENCY | 1.0.0 |
txPowerLevel | TxPowerLevel | Sets the TX power level for advertising. Default: Advertise using high TX power level. | TxPowerLevel.HIGH | 1.0.0 |
PublishOptions
Prop | Type | Description | Since |
---|
uuid | UUID | Sets the beacon UUID for the publish operation. | 1.1.0 |
ttlSeconds | TTLSeconds | Sets the time to live in seconds for the publish operation. | 1.0.0 |
SubscribeOptions
Prop | Type | Description | Since |
---|
ttlSeconds | TTLSeconds | Sets the time to live in seconds for the subscribe operation. | 1.0.0 |
PluginListenerHandle
Prop | Type |
---|
remove | () => Promise<void> |
Type Aliases
UUID
string
Status
{ isPublishing: boolean; isSubscribing: boolean; uuids: UUID[]; }
BeaconCallback
(uuid: string, rssi?: string | number): void
Enums
ScanMode
Members | Value |
---|
LOW_POWER | 0 |
BALANCED | 1 |
LOW_LATENCY | 2 |
OPPORTUNISTIC | -1 |
AdvertiseMode
Members | Value |
---|
LOW_POWER | 0 |
BALANCED | 1 |
LOW_LATENCY | 2 |
TxPowerLevel
Members | Value |
---|
ULTRA_LOW | 0 |
LOW | 1 |
MEDIUM | 2 |
HIGH | 3 |
TTLSeconds
Members | Value |
---|
TTL_SECONDS_DEFAULT | 300 |
TTL_SECONDS_MAX | 86400 |
TTL_SECONDS_INFINITE | 2147483647 |
BluetoothState
Members | Value |
---|
UNKNOWN | 'unknown' |
RESETTING | 'resetting' |
UNSUPPORTED | 'unsupported' |
UNAUTHORIZED | 'unauthorized' |
POWERED_OFF | 'poweredOff' |
POWERED_ON | 'poweredOn' |