export function busReplyRoute(daemonBlock, meshName) { if(!daemonBlock?.senderId) return(null) const onArena = meshName === 'arena' const systemReply = daemonBlock.maestroActionsReply ?? daemonBlock.gpsActionsReply ?? daemonBlock.observerActionsReply const actionsReply = onArena ? (daemonBlock.bus?.arena?.actionsReply ?? systemReply) : systemReply if(!actionsReply) return(null) return({ senderId: daemonBlock.senderId, actionsReply, }) } export function publishActionReply(redisCnx, options) { const { action, reqid, sender, reply, replyChannel, senderId, } = options reply.action = action reply.sender = senderId if(reqid) reply.reqid = reqid const chan = replyChannel.replace(/\[UID\]/g, sender) redisCnx.redisPublish(chan, reply) } export function replyToAction(redisCnx, options) { const { action, reqid, sender, success, payload, err, replyChannel, senderId, } = options const routeReplyChannel = replyChannel ?? redisCnx.actionsReply const routeSenderId = senderId ?? redisCnx.senderId if(!routeReplyChannel || !routeSenderId) { console.error(`[${redisCnx.redisId}] Cannot resolve action reply route`) return } const reply = { success } if(err != null) reply.err = err if(payload !== undefined) reply.payload = payload publishActionReply(redisCnx, { action, reqid, sender, replyChannel: routeReplyChannel, senderId: routeSenderId, reply, }) }