2018-01-08 13:06:01 -08:00
|
|
|
import { Socket } from '../src'
|
|
|
|
|
2018-01-10 15:03:32 -08:00
|
|
|
const USOCKET = __dirname + '/sample.sock'
|
|
|
|
|
|
|
|
console.log(USOCKET)
|
2018-01-08 13:06:01 -08:00
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
|
|
|
class Test {
|
2018-01-10 15:03:32 -08:00
|
|
|
constructor(opts={}) {
|
2018-01-08 13:06:01 -08:00
|
|
|
this.socket = new Socket(USOCKET)
|
2018-01-10 15:03:32 -08:00
|
|
|
this.uspp = opts.uspp || 'processPacket'
|
2018-01-08 13:06:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async processPacket(packet) {
|
|
|
|
console.log('packet being processed')
|
|
|
|
console.dir(packet)
|
|
|
|
return await this[packet.cmd](packet.data,packet.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
async doit(data,name) {
|
|
|
|
let res = {}
|
|
|
|
console.log('data:', data)
|
|
|
|
res.status ='success'
|
|
|
|
res.name = name
|
|
|
|
res.data = 'this would be response from device'
|
|
|
|
return(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
init() { this.socket.create(this)}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let test = new Test()
|
|
|
|
await test.init()
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|