Uses Bluetooth LE to scan and advertise for nearby devices
npm install capacitor-nearby
npx cap sync
initialize(...)
reset()
publish(...)
unpublish()
subscribe(...)
unsubscribe()
status()
addListener('onPermissionChanged', ...)
addListener('onBluetoothStateChanged', ...)
addListener('onFound', ...)
addListener('onLost', ...)
addListener('onPublishExpired', ...)
addListener('onSubscribeExpired', ...)
- Interfaces
- Type Aliases
- Enums
initialize(options: { options?: InitializeOptions; }) => Promise<void>
Initializes Bluetooth LE for advertising and scanning of nearby tokens.
Param | Type |
---|---|
options |
{ options?: InitializeOptions; } |
Since: 1.0.0
reset() => Promise<void>
Stops and resets advertising and scanning of nearby tokens.
Since: 1.0.0
publish(options: { message: Message; options?: PublishOptions; }) => Promise<void>
Start publishing nearby token.
Param | Type |
---|---|
options |
{ message: Message; options?: PublishOptions; } |
Since: 1.0.0
unpublish() => Promise<void>
Stop publishing nearby token.
Since: 1.0.0
subscribe(options: { options?: SubscribeOptions; }) => Promise<void>
Start listening to nearby tokens.
Param | Type |
---|---|
options |
{ options?: SubscribeOptions; } |
Since: 1.0.0
unsubscribe() => Promise<void>
Stop listening to nearby tokens.
Since: 1.0.0
status() => Promise<Status>
Returns status of operations and found tokens.
Returns: Promise<Status>
Since: 1.0.0
addListener(eventName: 'onPermissionChanged', listenerFunc: (permissionGranted: boolean) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when permission is granted or revoked for this app to use Nearby.
Param | Type |
---|---|
eventName |
'onPermissionChanged' |
listenerFunc |
(permissionGranted: boolean) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
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(eventName: 'onFound', listenerFunc: (uuid: UUID, content?: string | undefined) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when messages are found.
Param | Type |
---|---|
eventName |
'onFound' |
listenerFunc |
(uuid: string, content?: string) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
addListener(eventName: 'onLost', listenerFunc: (uuid: UUID, content?: string | undefined) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when a message is no longer detectable nearby.
Param | Type |
---|---|
eventName |
'onLost' |
listenerFunc |
(uuid: string, content?: string) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
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(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
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 |
Prop | Type | Description | Since |
---|---|---|---|
uuid |
UUID |
The UUID of the message. | 1.0.0 |
content |
string |
The raw bytes content of the message. | 1.0.0 |
Prop | Type | Description | Since |
---|---|---|---|
ttlSeconds |
TTLSeconds |
Sets the time to live in seconds for the publish operation. | 1.0.0 |
Prop | Type | Description | Since |
---|---|---|---|
ttlSeconds |
TTLSeconds |
Sets the time to live in seconds for the subscribe operation. | 1.0.0 |
Prop | Type |
---|---|
remove |
() => Promise<void> |
string
{ isPublishing: boolean; isSubscribing: boolean; uuids: UUID[]; }
Members | Value |
---|---|
LOW_POWER |
0 |
BALANCED |
1 |
LOW_LATENCY |
2 |
OPPORTUNISTIC |
-1 |
Members | Value |
---|---|
LOW_POWER |
0 |
BALANCED |
1 |
LOW_LATENCY |
2 |
Members | Value |
---|---|
ULTRA_LOW |
0 |
LOW |
1 |
MEDIUM |
2 |
HIGH |
3 |
Members | Value |
---|---|
TTL_SECONDS_DEFAULT |
300 |
TTL_SECONDS_MAX |
86400 |
TTL_SECONDS_INFINITE |
2147483647 |
Members | Value |
---|---|
UNKNOWN |
'unknown' |
RESETTING |
'resetting' |
UNSUPPORTED |
'unsupported' |
UNAUTHORIZED |
'unauthorized' |
POWERED_OFF |
'poweredOff' |
POWERED_ON |
'poweredOn' |