finished actions => handlers refacto, small bux fix in maestro => Test maestro1 OK

This commit is contained in:
STEINNI
2026-06-20 20:10:14 +00:00
parent 44a84c64ec
commit 3066a54a4c
32 changed files with 386 additions and 33 deletions
+17
View File
@@ -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] : [],
})
},
})
+9
View File
@@ -0,0 +1,9 @@
export const eventHandlers = {
'arena:gods:ready': {
readyToStart(msg, chan) {
if(!this.maestroSrv) return
this.maestroSrv.handlePrepareAck(msg, chan)
},
},
}
+17
View File
@@ -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),
})
},
})
+63
View File
@@ -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 },
})
},
}
+20
View File
@@ -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(),
})
},
}