@yoda/bluetooth. BluetoothMessageStream

This class is used to send/receive messages from Bluetooth device.

Constructor

new BluetoothMessageStream()

Use bluetooth.getMessageStream() instead of this constructor.

Example
var messageStream = bluetooth.getMessageStream()
messageStream.start()
messageStream.on('data', (data) => {
  console.log(data)
})
messageStream.on('connected', (data) => {
  console.log(data)
})
messageStream.write('something')
messageStream.write({ foobar: true })

Extends

Methods

start(name, subsequent, onerror) → {Null}

start the message stream.

Parameters:
Name Type Description
name string

the bluetooth name.

subsequent boolean

if true, always start until success.

onerror function
Returns:
Type:
Null

end()

end the message stream.

disconnect()

Disconnect the event socket, this is deprecated please use .destroyConnection() instead.

destroyConnection()

Destroy the connection to bluetooth service, this firstly sends the OFF command and destroy the connection.

write(data)

write data to the message stream.

Parameters:
Name Type Description
data Any

the data to write to peer device.

Events

opened

when channel is opened

Type:

closed

when channel is closed

Type:

connected

when device is connected

Type:

handshake

data is handshaking

Type:

data

when some data is sent.

Type:

error

when something is wrong.

Type: