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'
|
|
|
|
|
2018-01-08 13:06:01 -08:00
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
2018-01-20 14:30:21 -08:00
|
|
|
class Test extends Socket {
|
|
|
|
constructor(path,opts) {
|
|
|
|
super(path,opts)
|
2018-01-08 13:06:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async processPacket(packet) {
|
|
|
|
console.log('packet being processed')
|
|
|
|
console.dir(packet)
|
2018-01-13 20:46:14 -08:00
|
|
|
if (packet.cmd) return await this[packet.cmd](packet.data,packet.name)
|
|
|
|
return {error: 'no command in packet', packet: packet }
|
2018-01-08 13:06:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-20 14:30:21 -08:00
|
|
|
let test = new Test(USOCKET,{path: USOCKET, name:'example-socket'})
|
|
|
|
await test.create()
|
2018-01-08 13:06:01 -08:00
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|