intval3/lib/blootstrap/index.js

32 lines
696 B
JavaScript
Raw Normal View History

'use strict'
const ipc = require('node-ipc')
function capitalize (s) {
return s[0].toUpperCase() + s.slice(1)
}
class Blootstrap {
constructor () {
this._onData = () => {}
ipc.connectTo('blootstrap_ble', () => {
ipc.of.blootstrap_ble.on('connect', () => {
ipc.log(`Connected to the blootstrap_ble service`)
})
ipc.of.blootstrap_ble.on('data', data => {
const str = data.toString()
ipc.log(str)
this._onData(str)
})
ipc.of.blootstrap_ble.on('disconnect', () => {
ipc.log(`Disconnected from the blootstrap_ble service`)
})
})
}
on (eventName, callback) {
this[`_on${capitalize(eventName)}`] = callback
}
}
module.exports = new Blootstrap()