2018-02-05 22:05:38 -08:00
|
|
|
|
|
|
|
|
|
|
|
// this._processing refers to this module/hash
|
|
|
|
|
|
|
|
const processor = async function (packet,socket) {
|
2018-02-06 18:30:00 -08:00
|
|
|
return await process[this.getSocket(socket).type].bind(this)(packet,socket)
|
2018-02-05 22:05:38 -08:00
|
|
|
}
|
|
|
|
|
2018-02-06 18:30:00 -08:00
|
|
|
export { processor, commands, namespaces }
|
2018-02-05 22:05:38 -08:00
|
|
|
|
|
|
|
const process = {
|
2018-02-06 18:30:00 -08:00
|
|
|
s: async function (packet,socket) {
|
2018-02-05 22:05:38 -08:00
|
|
|
// console.log('in default socket processor',packet.cmd)
|
2018-02-06 18:30:00 -08:00
|
|
|
if (!packet.cmd) return {error: '[socket] no command in packet', packet: packet }
|
|
|
|
let response = await this._callCmdFunc(packet,socket); if(response!=='failed') return response
|
2018-02-05 22:05:38 -08:00
|
|
|
return {error: 'no socket processing function supplied for command', packet: packet }
|
|
|
|
},
|
|
|
|
|
2018-02-06 18:30:00 -08:00
|
|
|
c: async function (packet,socket) {
|
|
|
|
|
2018-02-05 22:05:38 -08:00
|
|
|
// console.log('in default consumer processor',packet.cmd)
|
2018-02-06 18:30:00 -08:00
|
|
|
if (packet.error) return await this._defaultCmds.c.error(packet)
|
2018-02-05 22:05:38 -08:00
|
|
|
if (packet.cmd) {
|
2018-02-06 18:30:00 -08:00
|
|
|
let response = await this._callCmdFunc(packet,socket); if(response!=='failed') return response
|
2018-02-05 22:05:38 -08:00
|
|
|
packet = {error:'no consumer processing function supplied for command',packet:packet}
|
|
|
|
this._defaultCmds.c.error(packet)
|
|
|
|
} else {
|
2018-02-06 18:30:00 -08:00
|
|
|
packet = {error:'[consumer] no command in packet',packet:packet}
|
|
|
|
return await this._defaultCmds.c.error(packet)
|
2018-02-05 22:05:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 18:30:00 -08:00
|
|
|
const namespaces = {
|
2018-05-25 14:39:48 -07:00
|
|
|
s: ['s','_defaultCmds.s'],
|
|
|
|
c: ['c','_defaultCmds.c'],
|
2018-02-06 18:30:00 -08:00
|
|
|
cn: ['cn'],
|
|
|
|
ct: ['ct'],
|
|
|
|
sn: ['sn'],
|
|
|
|
st: ['st'],
|
2018-05-20 15:44:31 -07:00
|
|
|
cm: ['cm'],
|
|
|
|
sm: ['sm'],
|
2018-05-25 14:39:48 -07:00
|
|
|
sw: ['sw'],
|
2018-02-06 18:30:00 -08:00
|
|
|
}
|
|
|
|
|
2018-02-05 22:05:38 -08:00
|
|
|
/*
|
|
|
|
*
|
2018-02-06 18:30:00 -08:00
|
|
|
* Default packet command processing functions
|
2018-02-05 22:05:38 -08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
const commands ={
|
|
|
|
s:{
|
|
|
|
echo: async packet => {
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
packet.processed = true
|
|
|
|
packet.cmd = 'reply'
|
|
|
|
packet.info = 'default socket echo'
|
|
|
|
return resolve(packet)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
c:{
|
|
|
|
error: function (packet) {
|
2018-03-02 08:35:25 -08:00
|
|
|
// TODO log and make this show only on env debug
|
2018-02-17 18:23:38 -08:00
|
|
|
console.log('==============Packet ERROR [consumer]==========')
|
2018-02-05 22:05:38 -08:00
|
|
|
console.log(packet.error )
|
|
|
|
console.dir(packet.packet)
|
|
|
|
console.log('===========================')
|
|
|
|
},
|
|
|
|
reply: function(packet) {
|
2018-03-02 08:35:25 -08:00
|
|
|
// TODO log and make this show only on env debug
|
2018-02-06 18:30:00 -08:00
|
|
|
console.log('==============Packet returned from socket - default reply==========')
|
2018-02-05 22:05:38 -08:00
|
|
|
console.dir(packet)
|
|
|
|
console.log('===========================')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|