39 lines
867 B
JavaScript
39 lines
867 B
JavaScript
import { Socket } from '../src'
|
|
|
|
;
|
|
(async () => {
|
|
|
|
class Test extends Socket {
|
|
constructor(opts) {
|
|
super(opts)
|
|
}
|
|
|
|
async _packetProcess(packet) {
|
|
console.log('packet being processed at socket')
|
|
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 sent to doit = ', 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()
|
|
let test = new Test({path:true})
|
|
await test.create()
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
})
|