28 lines
779 B
JavaScript
28 lines
779 B
JavaScript
import Socket from '../src'
|
|
|
|
async function packetProcess(packet) {
|
|
return new Promise(resolve => {
|
|
let res = {}
|
|
console.log('processing')
|
|
if (packet.cmd !== 'doit') {
|
|
res.response = `command ${packet.cmd} was unknown at server echo payload back`
|
|
res.payload = packet.payload
|
|
console.log(JSON.stringify(res))
|
|
} else {
|
|
res.cmd = 'doit'
|
|
res.response = 'take some action in browser like color a button green'
|
|
res.payload = {button:'on'}
|
|
}
|
|
resolve(res)
|
|
})
|
|
}
|
|
|
|
// let test = new Test()
|
|
let test = new Socket({ port: 8090, clientTracking: true })
|
|
test.registerPacketProcessor(packetProcess)
|
|
;(async () => {
|
|
console.log(await test.create())
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n', err)
|
|
})
|