37 lines
821 B
JavaScript
37 lines
821 B
JavaScript
import { Socket } from '../src'
|
|
|
|
const USOCKET = __dirname + '/sample.sock'
|
|
|
|
;
|
|
(async () => {
|
|
|
|
class Test extends Socket {
|
|
constructor(path,opts) {
|
|
super(path,opts)
|
|
}
|
|
|
|
async processPacket(packet) {
|
|
console.log('packet being processed')
|
|
console.dir(packet)
|
|
if (packet.cmd) return await this[packet.cmd](packet.data,packet.name)
|
|
return {error: 'no command in packet', packet: packet }
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
}
|
|
|
|
let test = new Test(USOCKET,{path: USOCKET, name:'example-socket'})
|
|
await test.create()
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
})
|