a lot of refactos

This commit is contained in:
STEINNI
2026-06-21 21:08:46 +00:00
parent 3066a54a4c
commit 4c9e989bda
16 changed files with 472 additions and 60 deletions
+43 -11
View File
@@ -1,7 +1,6 @@
import { AccesRights } from '../accesRights.js'
import { GpsStorageReader } from './gpsStorageReader.js'
import { RequestorRegistry } from './requestorRegistry.js'
import { replyToAction } from '../bus/publishActionReply.js'
import { SimState } from '../GPS/simulationState.js'
export class observerServer {
@@ -26,6 +25,8 @@ export class observerServer {
return({
senderId: observer.senderId ?? 'observer',
scanIntervalMs: observer.scanIntervalMs ?? 300,
frustumEventsChannel: observer.observerFrustumEventsChannel
?? 'system:observer:subscribed[UID]:agents',
lifecycle: {
arenaChannel: observer.lifecycle?.arenaChannel ?? 'arena:lifecycle',
godsReadyChannel: observer.lifecycle?.godsReadyChannel ?? 'arena:gods:ready',
@@ -53,20 +54,44 @@ export class observerServer {
this.gpsStorageReader,
() => this.now(),
scanIntervalMs,
(sender, payload) => this.publishFrustumUpdate(sender, payload),
(subscriberId, payload) => this.publishFrustumAgentEvents(
subscriberId,
payload.agents,
payload.t
),
this.debug
)
}
publishFrustumUpdate(sender, payload) {
if(!this.systemCnx || !sender) return
const observer = this.observerConfig.observer ?? {}
replyToAction(this.systemCnx, {
action: 'GETAGENTSINFRUSTUM',
sender,
success: true,
payload,
})
async publishFrustumAgentEvents(subscriberId, agents, t) {
if(!this.systemCnx || !subscriberId) return
if(!Array.isArray(agents) || !agents.length) return
const { frustumEventsChannel } = this.getObserverSettings()
const chan = frustumEventsChannel.replace(/\[UID\]/g, subscriberId)
const senderId = this.getObserverSettings().senderId
for(const agent of agents) {
if(!agent?.id || !agent?.position) continue
await this.systemCnx.redisPublish(chan, {
eventType: 'move',
sender: senderId,
payload: {
aid: agent.id,
coords: {
x: agent.position.x,
y: agent.position.y,
z: agent.position.z,
},
t,
},
})
}
if(this.debug) {
console.log(`[Observer] Frustum events: ${agents.length} agent(s) on ${chan} at t=${t}`)
}
}
isLive() {
@@ -94,6 +119,13 @@ export class observerServer {
this.state = SimState.LIVE
}
onSimulationStopped(payload = {}) {
this.requestorRegistry?.clear()
this.state = SimState.IDLE
this.bigBangEpoch = null
if(this.debug) console.log(`[Observer] simulationStopped at t=${payload.t}`)
}
wireSystemConnexion(cnx) {
cnx.observerSrv = this
cnx.accessRights = this.accessRights