uci-socket/examples/server.mjs

38 lines
837 B
JavaScript

import { Socket } from '../src'
const USOCKET = __dirname + '/sample.sock'
;
(async () => {
class Test extends Socket {
constructor(path,opts) {
super(path,opts)
}
async _process(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'})
test.packet = test
await test.create()
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})