capacitor-nearby
Uses Bluetooth LE to scan and advertise for nearby devices
Install
npm install capacitor-nearby
npx cap sync
API
initialize(...)
reset()
publish(...)
unpublish()
subscribe(...)
unsubscribe()
status()
addListener('onPermissionChanged', ...)
addListener('onBluetoothStateChanged', ...)
addListener('onFound', ...)
addListener('onLost', ...)
addListener('onPublishExpired', ...)
addListener('onSubscribeExpired', ...)
- Interfaces
- Type Aliases
- Enums
initialize(...)
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()
reset() => Promise<void>
Stops and resets advertising and scanning of nearby tokens.
Since: 1.0.0
publish(...)
publish(options: { message: Message; options?: PublishOptions; }) => Promise<void>
Start publishing nearby token.
Param | Type |
---|---|
options |
{ message: Message; options?: PublishOptions; } |
Since: 1.0.0
unpublish()
unpublish() => Promise<void>
Stop publishing nearby token.
Since: 1.0.0
subscribe(...)
subscribe(options: { options?: SubscribeOptions; }) => Promise<void>
Start listening to nearby tokens.
Param | Type |
---|---|
options |
{ options?: SubscribeOptions; } |
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: (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('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: (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('onLost', ...)
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('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 |
Message
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 |
PublishOptions
Prop | Type | Description | Since |
---|---|---|---|
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[]; }
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' |