fix(server): reject stale voice mode enables
This commit is contained in:
@@ -19,13 +19,13 @@ export class VoiceModeManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setEnabled(instanceId: string, connection: ClientConnectionRef, enabled: boolean): void {
|
setEnabled(instanceId: string, connection: ClientConnectionRef, enabled: boolean): boolean {
|
||||||
if (enabled && !this.options.connections.isConnected(connection)) {
|
if (enabled && !this.options.connections.isConnected(connection)) {
|
||||||
this.options.logger.debug(
|
this.options.logger.debug(
|
||||||
{ instanceId, clientId: connection.clientId, connectionId: connection.connectionId },
|
{ instanceId, clientId: connection.clientId, connectionId: connection.connectionId },
|
||||||
"Ignoring voice mode enable for disconnected client connection",
|
"Ignoring voice mode enable for disconnected client connection",
|
||||||
)
|
)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = getConnectionKey(connection)
|
const key = getConnectionKey(connection)
|
||||||
@@ -44,6 +44,7 @@ export class VoiceModeManager {
|
|||||||
|
|
||||||
this.options.logger.debug({ instanceId, clientId: connection.clientId, connectionId: connection.connectionId, enabled }, "Voice mode updated for client connection")
|
this.options.logger.debug({ instanceId, clientId: connection.clientId, connectionId: connection.connectionId, enabled }, "Voice mode updated for client connection")
|
||||||
this.publishIfChanged(instanceId)
|
this.publishIfChanged(instanceId)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
syncInstance(instanceId: string): void {
|
syncInstance(instanceId: string): void {
|
||||||
|
|||||||
@@ -66,11 +66,17 @@ export function registerPluginRoutes(app: FastifyInstance, deps: RouteDeps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const payload = VoiceModeStateSchema.parse(request.body ?? {})
|
const payload = VoiceModeStateSchema.parse(request.body ?? {})
|
||||||
deps.voiceModeManager.setEnabled(
|
const applied = deps.voiceModeManager.setEnabled(
|
||||||
request.params.id,
|
request.params.id,
|
||||||
{ clientId: payload.clientId, connectionId: payload.connectionId },
|
{ clientId: payload.clientId, connectionId: payload.connectionId },
|
||||||
payload.enabled,
|
payload.enabled,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (payload.enabled && !applied) {
|
||||||
|
reply.code(409).send({ error: "Client connection not active for voice mode enable" })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return { enabled: payload.enabled }
|
return { enabled: payload.enabled }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user