General Actions to handlers Refacto
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { assembleHandlers, createDispatchMessage } from '../../../bus/assembleMesh.js'
|
||||
import * as prepare from './prepare.js'
|
||||
|
||||
const { actionHandlers, eventHandlers, afterLogin } = assembleHandlers([prepare])
|
||||
|
||||
export { actionHandlers, afterLogin }
|
||||
|
||||
export const dispatchMessage = createDispatchMessage({
|
||||
eventHandlers,
|
||||
actionRules(redisCnx) {
|
||||
const maestro = redisCnx.config.maestro ?? {}
|
||||
const arenaChannel = maestro.bus?.arena?.actionsChannel
|
||||
return({
|
||||
channels: arenaChannel ? [arenaChannel] : [],
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
export const eventHandlers = {
|
||||
'arena:gods:ready': {
|
||||
readyToStart(msg, chan) {
|
||||
if(!this.maestroSrv) return
|
||||
this.maestroSrv.handlePrepareAck(msg, chan)
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { assembleHandlers, createDispatchMessage } from '../../../bus/assembleMesh.js'
|
||||
import * as simulation from './simulation.js'
|
||||
import * as utilities from './utilities.js'
|
||||
|
||||
const { actionHandlers, eventHandlers, afterLogin } = assembleHandlers([simulation, utilities])
|
||||
|
||||
export { actionHandlers, afterLogin }
|
||||
|
||||
export const dispatchMessage = createDispatchMessage({
|
||||
eventHandlers,
|
||||
actionRules(redisCnx) {
|
||||
const maestro = redisCnx.config.maestro ?? {}
|
||||
return({
|
||||
channels: [maestro.maestroActionsChannel].filter(Boolean),
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { replyToAction } from '../../../bus/publishActionReply.js'
|
||||
import { isValidUuid } from '../../simRepository.js'
|
||||
|
||||
export const actions = {
|
||||
|
||||
async action_STARTSIMULATION(action, payload, reqid, sender, roles) {
|
||||
if(!isValidUuid(sender)) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
return
|
||||
}
|
||||
|
||||
if(!payload?.simulationUuid) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing simulationUuid' })
|
||||
return
|
||||
}
|
||||
|
||||
const result = await this.maestroSrv.startSimulation(sender, payload)
|
||||
if(!result.ok) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
|
||||
return
|
||||
}
|
||||
|
||||
replyToAction(this, {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
success: true,
|
||||
payload: {
|
||||
simulationId: result.simulationId,
|
||||
keyframeId: result.keyframeId,
|
||||
infraId: result.infraId,
|
||||
agentIds: result.agentIds,
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
async action_STOPSIMULATION(action, payload, reqid, sender, roles) {
|
||||
if(!isValidUuid(sender)) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
return
|
||||
}
|
||||
|
||||
if(!payload?.simulationUuid) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing simulationUuid' })
|
||||
return
|
||||
}
|
||||
|
||||
const result = await this.maestroSrv.stopSimulation(sender, payload)
|
||||
if(!result.ok) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
|
||||
return
|
||||
}
|
||||
|
||||
replyToAction(this, {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
success: true,
|
||||
payload: { simulationId: result.simulationId },
|
||||
})
|
||||
},
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { replyToAction } from '../../../bus/publishActionReply.js'
|
||||
|
||||
export const actions = {
|
||||
|
||||
async action_RELOADCONFIG(action, payload, reqid, sender, roles) {
|
||||
this.reloadAccessRights()
|
||||
replyToAction(this, { action, reqid, sender, success: true })
|
||||
},
|
||||
|
||||
async action_GETCONFIG(action, payload, reqid, sender, roles) {
|
||||
replyToAction(this, {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
success: true,
|
||||
payload: this.getAccessRights(),
|
||||
})
|
||||
},
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user