Try catch the connection

This commit is contained in:
mmcw-dev 2017-10-20 21:45:17 -04:00
parent df106e6e90
commit 58f8d09775
1 changed files with 23 additions and 17 deletions

View File

@ -11,25 +11,31 @@ function capitalize (s) {
class Blootstrap { class Blootstrap {
constructor () { constructor () {
this._onData = () => {} this._onData = () => {}
ipc.connectTo('blootstrap_ble', () => { try {
ipc.of.blootstrap_ble.on('connect', () => { ipc.connectTo('blootstrap_ble', () => {
log.info('connect', `Connected to the blootstrap_ble service`) ipc.of.blootstrap_ble.on('connect', () => {
log.info('connect', `Connected to the blootstrap_ble service`)
})
ipc.of.blootstrap_ble.on('data', data => {
const str = data.toString()
log.info('data', str)
this._onData(str)
})
ipc.of.blootstrap_ble.on('disconnect', () => {
log.info('disconnect', `Disconnected from the blootstrap_ble service`)
})
ipc.of.blootstrap_ble.on('error', (err) => {
if (err.code === 'EACCES') {
log.warn('ble', `Cannot access ipc`)
} else {
log.error('ble', { error : err })
}
})
}) })
ipc.of.blootstrap_ble.on('data', data => { } catch (e) {
const str = data.toString() log.error('connectTo', { error : e })
log.info('data', str) }
this._onData(str)
})
ipc.of.blootstrap_ble.on('disconnect', () => {
log.info('disconnect', `Disconnected from the blootstrap_ble service`)
})
ipc.of.blootstrap_ble.on('error', (err) => {
if (err.code === 'EACCES') {
log.warn('error', `Cannot access ipc`)
}
})
})
} }
/** /**
* Binds functions to events that are triggered by BLE messages * Binds functions to events that are triggered by BLE messages