2.0 KiB
// this._processing refers to this module/hash
export default { s:{ // s is for socket/server _process: async function (packet,sname) { if (!packet.cmd) return {error: 'no command in packet', packet: packet } / TODO before hook here / TODO Add namespce if (this._default[sname]) if (this._default[sname][packet.cmd]) return await this._default[sname][packet.cmd](packet) if (this[packet.cmd]) return await this[packet.cmd](packet) // TODO add socket transport if (this._default.s[packet.cmd]) return await this._default.s[packet.cmd](packet) // TODO after hook here return {error: 'no socket processing function supplied for command', packet: packet } }, echo: packet => { packet.processed = true packet.cmd = 'reply' packet.info = 'default socket echo' return packet } },
c: { // c is for consumer/client
_process: async function (packet,sname) {
if (packet.error) this._default.c.error(packet)
if (packet.cmd) {
/ TODO before hook here.
/ TODO Add namespce
if (this._default[sname]) if (this._default[sname][packet.cmd]) return await this._default[sname][packet.cmd](packet)
if (this[packet.cmd]) return await this[packet.cmd](packet)
if (this._default.c[packet.cmd]) return await this._default.c[packet.cmd](packet)
// TODO after hook here
packet = {error:'no consumer processing function supplied for command',packet:packet}
this._default.c.error(packet)
} else {
packet = {error:'no command in packet',packet:packet}
this._default.c.error(packet)
}
},
error: function (packet) {
console.log('=============Packet ERROR=========
')
console.log(packet.error )
console.dir(packet.packet)
console.log('=========================
')
},
reply: packet > {
console.log('==============Packet returned from socket=========
')
console.dir(packet)
console.log('=========================
')
}
}
}