2018-04-05 15:05:59 -07:00
|
|
|
import { Socket } from '../src'
|
|
|
|
|
2018-05-24 12:23:49 -07:00
|
|
|
async function packetProcess (packet) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let res = {}
|
|
|
|
if (packet.cmd !== 'doit') {
|
|
|
|
res.response = `the payload sent was: ${packet.payload} with command ${packet.cmd}`
|
|
|
|
} else {
|
|
|
|
res.cmd = 'doit'
|
|
|
|
res.response = 'take some action in browser like color a button green' }
|
|
|
|
resolve (res)
|
|
|
|
})
|
|
|
|
}
|
2018-04-05 15:05:59 -07:00
|
|
|
|
2018-05-24 12:23:49 -07:00
|
|
|
// let test = new Test()
|
|
|
|
let test = new Socket({port:8090, clientTracking:true})
|
|
|
|
test.registerPacketProcessor(packetProcess)
|
2018-04-05 15:05:59 -07:00
|
|
|
|
2018-05-24 12:23:49 -07:00
|
|
|
;
|
|
|
|
(async () => {
|
2018-04-05 15:05:59 -07:00
|
|
|
|
|
|
|
console.log(await test.create())
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|