@yoda/bluetooth~ BluetoothHfp

Use bluetooth.getAdapter(PROFILE.HFP) instead of this constructor.

Constructor

new BluetoothHfp(deviceName)

Parameters:
Name Type Description
deviceName string

The device name.

Extends

Methods

open() → {boolean}

Turn on the bluetooth. It will starts hands-free profile.

You can listen following changed states:

  • protocol.RADIO_STATE.ON when bluetooth is opened successfully.
  • protocol.RADIO_STATE.ON_FAILED when bluetooth cannot be opened.
Fires:
  • module:@yoda/bluetooth/BluetoothHfp#event:radio_state_changed
Returns:
Type:
boolean

true if send command success else false.

Example
var bluetooth = require('@yoda/bluetooth')
var protocol = bluetooth.protocol
var hfp = bluetooth.getAdapter(protocol.PROFILE.HFP)
hfp.on('radio_state_changed', function (state) {
  console.log(`bluetooth state: ${state}`)
})
hfp.open()

close() → {boolean}

Turn off the bluetooth.

You can listen following changed state events:

  • protocol.RADIO_STATE.OFF when bluetooth is closed.
Fires:
  • module:@yoda/bluetooth/BluetoothHfp#event:radio_state_changed
Returns:
Type:
boolean

true if send command success else false.

answer() → {boolean}

Answer incoming call.

Fires:
  • module:@yoda/bluetooth/BluetoothHfp#event:call_state_changed
Returns:
Type:
boolean

true if send command success else false.

hangup() → {boolean}

Hang up call.

Fires:
  • module:@yoda/bluetooth/BluetoothHfp#event:call_state_changed
Returns:
Type:
boolean

true if send command success else false.

dial(number) → {boolean}

Outgoing a call.

Parameters:
Name Type Description
number string

Specify the destination phone number.

Fires:
  • module:@yoda/bluetooth/BluetoothHfp#event:call_state_changed
Returns:
Type:
boolean

true if send command success else false.

getRadioState() → {RADIO_STATE}

Get hfp radio state.

Returns:
Type:
RADIO_STATE
  • The current radio state.

getConnectionState() → {CONNECTION_STATE}

Get hfp connection state.

Returns:
Type:
CONNECTION_STATE
  • The current connection state.

getCallState() → {CALL_STATE}

Get hfp call state.

Returns:
Type:
CALL_STATE
  • The current call state.

getDiscoveryState() → {DISCOVERY_STATE}

Get hfp discovery state.

Returns:
Type:
DISCOVERY_STATE
  • The currenct discovery state.

isOpened() → {boolean}

Get if bluetooth is opened.

Returns:
Type:
boolean
  • true if bluetooth is opened else false.

isConnected() → {boolean}

Get if this device is connected with remote device.

Returns:
Type:
boolean
  • true if blueooth is connected with remote device else false.

getConnectedDevice() → {BluetoothDevice|null}

Get connected bluetooth device.

Returns:
Type:
BluetoothDevice | Null
  • Current connected bluetooth device object or null if no connected device.

isCalling() → {boolean}

Get if is calling.

Returns:
Type:
boolean
  • true if is calling else false.

isIncoming() → {boolean}

Get if is incoming a call.

Returns:
Type:
boolean
  • true if is incoming a call else false.

isOutgoing() → {boolean}

Get if is outgoing a call.

Returns:
Type:
boolean
  • true if is outgoing a call else false.

destroy()

Destroy bluetooth profile adapter.

Events

radio_state_changed

When bluetooth's radio state is changed, such as on/off.

connection_state_changed

When bluetooth's connection state is changed, such as connected/disconnected.

call_state_changed

When bluetooth's call state is changed, such as idle/incoming.