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 lifecycle from './lifecycle.js'
const { actionHandlers, eventHandlers, afterLogin } = assembleHandlers([lifecycle])
export { actionHandlers, afterLogin }
export const dispatchMessage = createDispatchMessage({
eventHandlers,
actionRules(redisCnx) {
const observer = redisCnx.config.observer ?? {}
const arenaChannel = observer.bus?.arena?.actionsChannel
return({
channels: arenaChannel ? [arenaChannel] : [],
})
},
})
+11
View File
@@ -0,0 +1,11 @@
export const eventHandlers = {
'arena:lifecycle': {
onYourMarks(msg, chan) {
this.observerSrv?.onYourMarks()
},
bigBang(msg, chan) {
this.observerSrv?.onBigBang()
},
},
}
+17
View File
@@ -0,0 +1,17 @@
import { assembleHandlers, createDispatchMessage } from '../../../bus/assembleMesh.js'
import * as positions from './positions.js'
import * as utilities from './utilities.js'
const { actionHandlers, eventHandlers, afterLogin } = assembleHandlers([positions, utilities])
export { actionHandlers, afterLogin }
export const dispatchMessage = createDispatchMessage({
eventHandlers,
actionRules(redisCnx) {
const observer = redisCnx.config.observer ?? {}
return({
channels: [observer.observerActionsChannel].filter(Boolean),
})
},
})
+116
View File
@@ -0,0 +1,116 @@
import { replyToAction } from '../../../bus/publishActionReply.js'
import { parseSimTime } from '../../actionsHelper.js'
import { Frustum } from '../../frustum.js'
export const actions = {
async action_GETAGENTPOSITION(action, payload, reqid, sender, roles) {
const reader = this.observerSrv.gpsStorageReader
if(!reader) {
replyToAction(this, { action, reqid, sender, success: false, err: 'GPS storage reader not ready' })
return
}
if(!this.observerSrv.isLive()) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Simulation not live' })
return
}
const agentId = payload?.agentId
if(!agentId || typeof(agentId) !== 'string') {
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid agentId' })
return
}
const at = parseSimTime(payload, () => this.observerSrv.now())
if(at === null) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Invalid simulation time' })
return
}
const agent = await reader.getAgentPosition(agentId, at)
if(!agent) {
replyToAction(this, { action, reqid, sender, success: false, err: `Unknown agent: ${agentId}` })
return
}
replyToAction(this, { action, reqid, sender, success: true, payload: { agent } })
},
async action_GETAGENTSINFRUSTUM(action, payload, reqid, sender, roles) {
const registry = this.observerSrv.requestorRegistry
if(!registry) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Requestor registry not ready' })
return
}
if(!this.observerSrv.isLive()) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Simulation not live' })
return
}
const frustum = Frustum.fromPlanes(payload?.planes)
if(!frustum) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid frustum planes (expected 6)' })
return
}
const at = parseSimTime(payload, () => this.observerSrv.now())
if(at === null) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Invalid simulation time' })
return
}
const result = await registry.evaluateOnce({ frustum, t: at })
if(!result.ok) {
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
return
}
replyToAction(this, {
action,
reqid,
sender,
success: true,
payload: {
agents: result.agents,
t: result.t,
},
})
},
async action_SUBSCRIBEFRUSTUM(action, payload, reqid, sender, roles) {
const registry = this.observerSrv.requestorRegistry
if(!registry) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Requestor registry not ready' })
return
}
if(!this.observerSrv.isLive()) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Simulation not live' })
return
}
const result = await registry.subscribeFrustum(sender, {
planes: payload?.planes,
frequency: payload?.frequency,
})
if(!result.ok) {
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
return
}
replyToAction(this, {
action,
reqid,
sender,
success: true,
payload: {
frequency: result.frequency,
agents: result.agents,
t: result.t,
},
})
},
}
+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(),
})
},
}