39 lines
839 B
JavaScript
39 lines
839 B
JavaScript
import { Socket } from '../src'
|
|
|
|
;
|
|
(async () => {
|
|
|
|
class Test extends Socket {
|
|
constructor(opts) {
|
|
super(opts)
|
|
}
|
|
|
|
async _packetProcess(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) {
|
|
return new Promise(resolve => {
|
|
let res = {}
|
|
console.log('data:', data)
|
|
res.status ='success'
|
|
res.name = name
|
|
res.cmd = 'reply'
|
|
res.data = 'this would be response data from socket doit function'
|
|
resolve(res)
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let test = new Test({np:true})
|
|
await test.create()
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
})
|