Event-driven CommandService dispatches exact case-sensitive #command matches on COMMAND_CHANNEL (default 2) through a single-registration-point registry; first command #ping -> #pong!. Replies ride COMMAND_CHANNEL: directed DM back to the sender when present, else broadcast. Failing handler/send only logs a warn. DI: CommandModule's factory injects MeshService and attaches itself via MeshService.attachCommands() — a constructor-level cycle leaves one side null in NestJS 12's injector (verified), so no forwardRef is used. Tests 106 -> 121; docs synced (AGENTS.md, MESHTASTIC.md, README).
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MeshModule } from '../mesh/mesh.module.js';
|
||||
import { MeshService } from '../mesh/mesh.service.js';
|
||||
import { CommandService } from './command.service.js';
|
||||
|
||||
@Module({
|
||||
imports: [MeshModule], // one-way only — the reverse edge is wired in the factory below, not via DI
|
||||
providers: [
|
||||
{
|
||||
provide: CommandService,
|
||||
useFactory: (mesh: MeshService) => {
|
||||
const commands = new CommandService(mesh);
|
||||
// break the cycle: MeshService can't inject us (its own factory would deadlock on this edge), so attach ourselves once we exist — mesh is guaranteed created here because it's our injected dependency
|
||||
mesh.attachCommands(commands);
|
||||
return commands;
|
||||
},
|
||||
inject: [MeshService],
|
||||
},
|
||||
],
|
||||
exports: [CommandService],
|
||||
})
|
||||
export class CommandModule {}
|
||||
Reference in New Issue
Block a user