// this._processing refers to this module/hash const processor = async function (packet,socket) { return await process[this.getSocket(socket).type].bind(this)(packet,socket) } export { processor, commands, namespaces } const process = { s: async function (packet,socket) { // console.log('in default socket processor',packet.cmd) if (!packet.cmd) return {error: '[socket] no command in packet', packet: packet } let response = await this._callCmdFunc(packet,socket); if(response!=='failed') return response return {error: 'no socket processing function supplied for command', packet: packet } }, c: async function (packet,socket) { // console.log('in default consumer processor',packet.cmd) if (packet.error) return await this._defaultCmds.c.error(packet) if (packet.cmd) { let response = await this._callCmdFunc(packet,socket); if(response!=='failed') return response packet = {error:'no consumer processing function supplied for command',packet:packet} this._defaultCmds.c.error(packet) } else { packet = {error:'[consumer] no command in packet',packet:packet} return await this._defaultCmds.c.error(packet) } } } const namespaces = { s: ['s',null,'_defaultCmds.s'], c: ['c',null,'_defaultCmds.c'], cn: ['cn'], ct: ['ct'], sn: ['sn'], st: ['st'], cm: ['cm'], sm: ['sm'], } /* * * Default packet command processing functions * */ 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) { // TODO log and make this show only on env debug console.log('==============Packet ERROR [consumer]==========') console.log(packet.error ) console.dir(packet.packet) console.log('===========================') }, reply: function(packet) { // TODO log and make this show only on env debug console.log('==============Packet returned from socket - default reply==========') console.dir(packet) console.log('===========================') } } }