feat: 收敛玩法运行时配置并加入故障恢复

This commit is contained in:
2026-04-01 13:04:26 +08:00
parent 1635a11780
commit 3ef841ecc7
73 changed files with 8820 additions and 2122 deletions

View File

@@ -17,6 +17,12 @@ type RawMockGpsMessage = {
accuracyMeters?: number
speedMps?: number
headingDeg?: number
channelId?: string
}
function normalizeMockChannelId(rawChannelId: string | null | undefined): string {
const trimmed = String(rawChannelId || '').trim()
return trimmed || 'default'
}
function safeParseMessage(data: string): RawMockGpsMessage | null {
@@ -27,7 +33,7 @@ function safeParseMessage(data: string): RawMockGpsMessage | null {
}
}
function toLocationSample(message: RawMockGpsMessage): LocationSample | null {
function toLocationSample(message: RawMockGpsMessage, expectedChannelId: string): LocationSample | null {
if (message.type !== 'mock_gps') {
return null
}
@@ -36,6 +42,10 @@ function toLocationSample(message: RawMockGpsMessage): LocationSample | null {
return null
}
if (normalizeMockChannelId(message.channelId) !== expectedChannelId) {
return null
}
return {
latitude: Number(message.lat),
longitude: Number(message.lon),
@@ -53,6 +63,7 @@ export class MockLocationBridge {
connected: boolean
connecting: boolean
url: string
channelId: string
constructor(callbacks: MockLocationBridgeCallbacks) {
this.callbacks = callbacks
@@ -60,6 +71,11 @@ export class MockLocationBridge {
this.connected = false
this.connecting = false
this.url = DEFAULT_MOCK_LOCATION_BRIDGE_URL
this.channelId = 'default'
}
setChannelId(channelId: string): void {
this.channelId = normalizeMockChannelId(channelId)
}
connect(url = DEFAULT_MOCK_LOCATION_BRIDGE_URL): void {
@@ -109,7 +125,7 @@ export class MockLocationBridge {
return
}
const sample = toLocationSample(parsed)
const sample = toLocationSample(parsed, this.channelId)
if (!sample) {
return
}