feat(ws): add stick-input WebSocket message handler and client support

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
itsrubberduck
2026-02-20 18:30:26 +01:00
parent 4e74b74255
commit c4c841a2c1
2 changed files with 19 additions and 0 deletions

View File

@@ -174,6 +174,14 @@ export default defineWebSocketHandler({
userSessionMap.set(data.userId, session.code)
break
}
case 'stick-input': {
// Broadcast stick/throttle input to all peers in session (for PFD display)
const session = findSessionByPeer(peerId)
if (!session) return
broadcastToSession(session, { type: 'stick-input', data: data.data }, peerId)
break
}
}
},

View File

@@ -16,6 +16,7 @@ export function useFlightLabSync() {
onPeerLeft: [] as Array<(peerRole: FlightLabRole) => void>,
onTelemetry: [] as Array<(data: any) => void>,
onError: [] as Array<(msg: string) => void>,
onStickInput: [] as Array<(data: { pitch: number; roll: number; throttle: number }) => void>,
}
function connect(): Promise<void> {
@@ -77,6 +78,9 @@ export function useFlightLabSync() {
case 'error':
callbacks.onError.forEach(cb => cb(data.message))
break
case 'stick-input':
callbacks.onStickInput.forEach(cb => cb(data.data))
break
}
}
@@ -128,6 +132,11 @@ export function useFlightLabSync() {
function onPeerLeft(cb: (role: FlightLabRole) => void) { callbacks.onPeerLeft.push(cb) }
function onTelemetry(cb: (data: any) => void) { callbacks.onTelemetry.push(cb) }
function onError(cb: (msg: string) => void) { callbacks.onError.push(cb) }
function onStickInput(cb: (data: { pitch: number; roll: number; throttle: number }) => void) { callbacks.onStickInput.push(cb) }
function sendStickInput(data: { pitch: number; roll: number; throttle: number }) {
send({ type: 'stick-input', data })
}
return {
isConnected,
@@ -147,5 +156,7 @@ export function useFlightLabSync() {
onPeerLeft,
onTelemetry,
onError,
onStickInput,
sendStickInput,
}
}