feat: 收敛玩法运行时配置并加入故障恢复
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user