export function dispatchMessage(redisCnx, msg, chan) { const observer = redisCnx.config.observer if(!observer?.observerActionsChannel) return const actionsChan = redisCnx.fullChan(observer.observerActionsChannel) if(chan != actionsChan) return const action = msg.action if(!action || typeof(action) !== 'string') { console.warn(`[${redisCnx.redisId}] Ignoring message without action on ${chan}`) return } const handler = redisCnx['action_'+action] if(typeof(handler) != 'function') { if(redisCnx.debug) console.warn(`[${redisCnx.redisId}] Unknown action ${action} on ${chan}`) return } const payload = ('payload' in msg) ? msg.payload : null const reqid = ('reqid' in msg) ? msg.reqid.substr(0, 50) : null const sender = msg.sender || null const roles = Array.isArray(msg.roles) ? msg.roles : ['*'] if(redisCnx.debug) console.log(`[${redisCnx.redisId}] Dispatching action ${action} from ${sender}`) handler.call(redisCnx, action, payload, reqid, sender, roles) }