bionic-bt-serial
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

bionic-bt-serial

Send data between bluetooth devices using a serial like interface

Install

npm install bionic-bt-serial
npx cap sync

API

addListener(PluginEvents, ...)

addListener(eventName: PluginEvents, callback: EventCallback) => Promise<PluginListenerHandle>
Param Type
eventName PluginEvents
callback EventCallback

Returns: Promise<PluginListenerHandle>


addListener('discoveryState', ...)

addListener(eventName: 'discoveryState', callback: (result: { starting?: boolean; completed?: boolean; }) => void) => Promise<PluginListenerHandle>
Param Type
eventName 'discoveryState'
callback (result: { starting?: boolean; completed?: boolean; }) => void

Returns: Promise<PluginListenerHandle>


addListener('discovered', ...)

addListener(eventName: 'discovered', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param Type
eventName 'discovered'
callback (result: BTDevice) => void

Returns: Promise<PluginListenerHandle>


addListener('rawData', ...)

addListener(eventName: 'rawData', callback: (result: RawDataResult) => void) => Promise<PluginListenerHandle>
Param Type
eventName 'rawData'
callback (result: RawDataResult) => void

Returns: Promise<PluginListenerHandle>


addListener('connected', ...)

addListener(eventName: 'connected', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param Type
eventName 'connected'
callback (result: BTDevice) => void

Returns: Promise<PluginListenerHandle>


addListener('connectionFailed', ...)

addListener(eventName: 'connectionFailed', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param Type
eventName 'connectionFailed'
callback (result: BTDevice) => void

Returns: Promise<PluginListenerHandle>


addListener('connectionLost', ...)

addListener(eventName: 'connectionLost', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param Type
eventName 'connectionLost'
callback (result: BTDevice) => void

Returns: Promise<PluginListenerHandle>


getBondedDevices()

getBondedDevices() => Promise<{ result: BTDevice[]; }>

Gets a list of the bonded (paired) devices.

Returns: Promise<{ result: BTDevice[]; }>


startListening(...)

startListening(_options: {}, callback: ListenCallback) => Promise<void>

Start listening for incoming connections

Param Type
_options {}
callback ListenCallback

stopListening()

stopListening() => Promise<void>

Stops listening for incoming connections.


isListening()

isListening() => Promise<{ result: boolean; }>

True if listening for an accepting incoming connections. A device acting as a server should be listening.

Returns: Promise<{ result: boolean; }>


connect(...)

connect(options: { macAddress: string; }) => Promise<void>

Connect to another device acting as a server that is in listening mode. Should already be paired?

Param Type
options { macAddress: string; }

isConnected(...)

isConnected(options: { macAddress: string; }) => Promise<{ result: boolean; }>

True if there is an active connection to the provided macAddress false otherwise.

Param Type
options { macAddress: string; }

Returns: Promise<{ result: boolean; }>


getConnectedDevices()

getConnectedDevices() => Promise<{ result: BTDevice[]; }>

Gets a list of the connected devices.

Returns: Promise<{ result: BTDevice[]; }>


disconnect(...)

disconnect(options: { macAddress: string; }) => Promise<{ result: boolean; }>

Disconnects specified connection.

Param Type
options { macAddress: string; }

Returns: Promise<{ result: boolean; }>


disconnectAll()

disconnectAll() => Promise<void>

Disconnects all connections (incomming and outgoing).


write(...)

write(options: { macAddress: string; data: number[]; }) => Promise<{ result: boolean; }>

Write data to specified macAddress

Param Type
options { macAddress: string; data: number[]; }

Returns: Promise<{ result: boolean; }>


isEnabled()

isEnabled() => Promise<{ result: boolean; }>

True if device has bluetooth enabled, false otherwise

Returns: Promise<{ result: boolean; }>


enableAdapter()

enableAdapter() => Promise<void>

Prompt the user to enable bluetooth. Resolved if bluetooth is enabled, rejects otherwise.


disableAdapter()

disableAdapter() => Promise<void>

Prompt the user to enable bluetooth. Resolved if bluetooth is enabled, rejects otherwise.


showBluetoothSettings()

showBluetoothSettings() => Promise<void>

Open the bluetooth settings screen for the user.


startDiscovery(...)

startDiscovery(_options: {}, callback: DiscoveryCallback) => Promise<void>

Starts discovery process, sends info about found devices to the callback. Scans for about 12 seconds.

Param Type
_options {}
callback DiscoveryCallback

cancelDiscovery()

cancelDiscovery() => Promise<void>

Stops any running discovery process.


setName(...)

setName(options: { name: string; }) => Promise<void>

Sets the name of the bluetooth adapter. Name is what paired devices will see when they connect.

Param Type
options { name: string; }

getName()

getName() => Promise<{ result: string; }>

Gets the name of the bluetooth adapter.

Returns: Promise<{ result: string; }>


setDiscoverable(...)

setDiscoverable(options: { durationSec?: number; }) => Promise<void>

Ensure bluetooth is enabled and the device is discoverable to remote scanners. Default durationSec is 120 is not provided. Max is 300 seconds.

Param Type
options { durationSec?: number; }

Interfaces

PluginListenerHandle

Prop Type
remove () => Promise<void>

Type Aliases

EventCallback

(info: any, err?: any): void

BTDevice

{name:string, macAddress:string, class:number}

RawDataResult

{bytes:number[], from:BTDevice}

ListenCallback

(device: BTDevice, err?: any): void

DiscoveryCallback

(device: BTDevice, err?: any): void

Enums

PluginEvents

Members Value
discovered "discovered"
discoveryState "discoveryState"
rawData "rawData"
connected "connected"
connectionFailed "connectionFailed"
connectionLost "connectionLost"

Readme

Keywords

Package Sidebar

Install

npm i bionic-bt-serial

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

120 kB

Total Files

27

Last publish

Collaborators

  • techplex