0.0.3 • Published 4 years ago

bionic-bt-serial v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

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>
ParamType
eventNamePluginEvents
callbackEventCallback

Returns: Promise<PluginListenerHandle>


addListener('discoveryState', ...)

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

Returns: Promise<PluginListenerHandle>


addListener('discovered', ...)

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

Returns: Promise<PluginListenerHandle>


addListener('rawData', ...)

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

Returns: Promise<PluginListenerHandle>


addListener('connected', ...)

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

Returns: Promise<PluginListenerHandle>


addListener('connectionFailed', ...)

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

Returns: Promise<PluginListenerHandle>


addListener('connectionLost', ...)

addListener(eventName: 'connectionLost', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
ParamType
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

ParamType
_options{}
callbackListenCallback

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?

ParamType
options{ macAddress: string; }

isConnected(...)

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

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

ParamType
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.

ParamType
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

ParamType
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.

ParamType
_options{}
callbackDiscoveryCallback

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.

ParamType
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.

ParamType
options{ durationSec?: number; }

Interfaces

PluginListenerHandle

PropType
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

MembersValue
discovered"discovered"
discoveryState"discoveryState"
rawData"rawData"
connected"connected"
connectionFailed"connectionFailed"
connectionLost"connectionLost"
0.0.3

4 years ago

0.0.3-pre0

4 years ago

0.0.2

4 years ago

0.0.2-pre5

4 years ago

0.0.2-pre4

4 years ago

0.0.1

4 years ago