mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-01 22:26:04 +08:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user