完善后端联调链路与模拟器多通道支持
This commit is contained in:
@@ -106,6 +106,11 @@ function isDebugLogPayload(payload) {
|
||||
&& typeof payload.message === 'string'
|
||||
}
|
||||
|
||||
function normalizeChannelId(value) {
|
||||
const trimmed = String(value || '').trim()
|
||||
return trimmed || 'default'
|
||||
}
|
||||
|
||||
async function handleProxyRequest(request, response) {
|
||||
const requestUrl = new URL(request.url || '/', `http://127.0.0.1:${PORT}`)
|
||||
const targetUrl = requestUrl.searchParams.get('url')
|
||||
@@ -533,6 +538,7 @@ gpsWss.on('connection', (socket) => {
|
||||
const outgoing = JSON.stringify({
|
||||
type: 'mock_gps',
|
||||
timestamp: Number.isFinite(parsed.timestamp) ? parsed.timestamp : Date.now(),
|
||||
channelId: normalizeChannelId(parsed.channelId),
|
||||
lat: Number(parsed.lat),
|
||||
lon: Number(parsed.lon),
|
||||
accuracyMeters: Number.isFinite(parsed.accuracyMeters) ? Number(parsed.accuracyMeters) : 6,
|
||||
@@ -566,6 +572,7 @@ heartRateWss.on('connection', (socket) => {
|
||||
const outgoing = JSON.stringify({
|
||||
type: 'mock_heart_rate',
|
||||
timestamp: Number.isFinite(parsed.timestamp) ? parsed.timestamp : Date.now(),
|
||||
channelId: normalizeChannelId(parsed.channelId),
|
||||
bpm: Math.max(1, Math.round(Number(parsed.bpm))),
|
||||
})
|
||||
gatewayBridge.publish(JSON.parse(outgoing))
|
||||
@@ -595,6 +602,7 @@ debugLogWss.on('connection', (socket) => {
|
||||
const outgoing = JSON.stringify({
|
||||
type: 'debug-log',
|
||||
timestamp: Number.isFinite(parsed.timestamp) ? parsed.timestamp : Date.now(),
|
||||
channelId: normalizeChannelId(parsed.channelId),
|
||||
scope: String(parsed.scope || 'app').slice(0, 64),
|
||||
level: parsed.level === 'warn' || parsed.level === 'error' ? parsed.level : 'info',
|
||||
message: String(parsed.message || '').slice(0, 400),
|
||||
|
||||
Reference in New Issue
Block a user