2026-10-23 11:43:49 -05:00
|
|
|
'use client';
|
|
|
|
|
|
2026-11-17 00:24:33 +06:00
|
|
|
import { PageShell } from '@/components/layout/PageShell';
|
2026-10-23 11:43:49 -05:00
|
|
|
import { Button } from '@/components/ui/Button';
|
2026-11-16 21:58:18 +06:00
|
|
|
import { CodeBlock } from '@/components/ui/CodeBlock';
|
2026-10-23 11:43:49 -05:00
|
|
|
import { Select, Textarea } from '@/components/ui/Input';
|
2026-11-16 21:58:18 +06:00
|
|
|
import { Panel } from '@/components/ui/Panel';
|
2026-11-18 05:18:55 +06:00
|
|
|
import { Pill } from '@/components/ui/Pill';
|
2026-11-17 00:24:33 +06:00
|
|
|
import { StatStrip } from '@/components/ui/StatStrip';
|
2026-10-23 11:43:49 -05:00
|
|
|
import { useToast } from '@/components/ui/Toast';
|
2026-11-16 23:10:44 +06:00
|
|
|
import { getCached, setCached } from '@/lib/vconCache';
|
2026-11-19 20:22:01 +06:00
|
|
|
import {
|
|
|
|
|
resolvePublicEndpoints,
|
|
|
|
|
summarizeHttpBatchResult,
|
|
|
|
|
} from '@/lib/vconUiHelpers';
|
2026-11-18 05:18:55 +06:00
|
|
|
import Link from 'next/link';
|
2026-10-23 19:56:38 -07:00
|
|
|
import { useEffect, useState } from 'react';
|
2026-11-18 05:18:55 +06:00
|
|
|
import { io } from 'socket.io-client';
|
|
|
|
|
|
|
|
|
|
interface SimulatorClient {
|
|
|
|
|
clientId: string;
|
|
|
|
|
name: string;
|
|
|
|
|
status: 'active' | 'revoked';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TransportMode = 'http' | 'websocket';
|
|
|
|
|
type DispatchStatus = 'Ready' | 'Accepted' | 'Rejected' | 'Error';
|
|
|
|
|
|
2026-11-19 20:22:01 +06:00
|
|
|
function getSocketOrigin(serverPort: number): string {
|
|
|
|
|
return resolvePublicEndpoints(window.location, serverPort).serverUrl;
|
2026-11-18 05:18:55 +06:00
|
|
|
}
|
2026-10-23 11:43:49 -05:00
|
|
|
|
|
|
|
|
export default function SimulatorPage() {
|
2026-11-18 05:18:55 +06:00
|
|
|
const { success, warning, error } = useToast();
|
|
|
|
|
const [clients, setClients] = useState<SimulatorClient[]>(() =>
|
|
|
|
|
getCached<SimulatorClient[]>('vcon:clients', [])
|
2026-11-17 00:24:33 +06:00
|
|
|
);
|
2026-11-16 23:10:44 +06:00
|
|
|
const [selectedClient, setSelectedClient] = useState<string>(() => {
|
2026-11-18 05:18:55 +06:00
|
|
|
const cached = getCached<SimulatorClient[]>('vcon:clients', []);
|
|
|
|
|
return cached.find((c) => c.status === 'active')?.clientId ?? cached[0]?.clientId ?? '';
|
2026-11-16 23:10:44 +06:00
|
|
|
});
|
2026-11-18 05:18:55 +06:00
|
|
|
const [transport, setTransport] = useState<TransportMode>('http');
|
2026-10-23 11:43:49 -05:00
|
|
|
const [payloadText, setPayloadText] = useState<string>(
|
|
|
|
|
JSON.stringify(
|
|
|
|
|
{
|
|
|
|
|
event_name: 'sensor_telemetry',
|
|
|
|
|
temperature: 24.8,
|
|
|
|
|
humidity: 58.2,
|
|
|
|
|
voltage: 3.31,
|
|
|
|
|
status: 'NOMINAL',
|
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
)
|
|
|
|
|
);
|
2026-11-19 20:22:01 +06:00
|
|
|
const [serverPort, setServerPort] = useState<number>(() =>
|
|
|
|
|
getCached<number>('vcon:server-port', 4000)
|
|
|
|
|
);
|
2026-10-23 11:43:49 -05:00
|
|
|
const [sending, setSending] = useState(false);
|
2026-11-18 05:18:55 +06:00
|
|
|
const [dispatchStatus, setDispatchStatus] = useState<DispatchStatus>('Ready');
|
|
|
|
|
const [lastResponse, setLastResponse] = useState<Record<string, unknown> | null>(null);
|
2026-10-23 11:43:49 -05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-11-19 20:22:01 +06:00
|
|
|
async function loadSimulatorContext() {
|
2026-10-23 11:43:49 -05:00
|
|
|
try {
|
2026-11-19 20:22:01 +06:00
|
|
|
const [clientsRes, metricsRes] = await Promise.all([
|
|
|
|
|
fetch('/api/clients', { cache: 'no-store' }),
|
|
|
|
|
fetch('/api/metrics', { cache: 'no-store' }).catch(() => null),
|
|
|
|
|
]);
|
|
|
|
|
if (clientsRes.status === 401 || metricsRes?.status === 401) {
|
2026-11-18 05:18:55 +06:00
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-11-19 20:22:01 +06:00
|
|
|
if (clientsRes.ok) {
|
|
|
|
|
const data = await clientsRes.json();
|
2026-11-18 05:18:55 +06:00
|
|
|
const list = setCached<SimulatorClient[]>('vcon:clients', data.clients || []);
|
2026-10-23 11:43:49 -05:00
|
|
|
setClients(list);
|
2026-11-18 05:18:55 +06:00
|
|
|
setSelectedClient((prev) => {
|
|
|
|
|
if (prev && list.some((c) => c.clientId === prev)) return prev;
|
|
|
|
|
return list.find((c) => c.status === 'active')?.clientId ?? list[0]?.clientId ?? '';
|
|
|
|
|
});
|
2026-10-23 11:43:49 -05:00
|
|
|
}
|
2026-11-19 20:22:01 +06:00
|
|
|
if (metricsRes && metricsRes.ok) {
|
|
|
|
|
const metricsData = await metricsRes.json().catch(() => null);
|
|
|
|
|
const runtimePort = Number(metricsData?.runtime?.serverPort);
|
|
|
|
|
if (Number.isFinite(runtimePort) && runtimePort > 0) {
|
|
|
|
|
setServerPort(setCached('vcon:server-port', runtimePort));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-23 11:43:49 -05:00
|
|
|
} catch {
|
2026-11-18 05:18:55 +06:00
|
|
|
// Ignore transient failure and retain cached list
|
2026-10-23 11:43:49 -05:00
|
|
|
}
|
|
|
|
|
}
|
2026-11-19 20:22:01 +06:00
|
|
|
void loadSimulatorContext();
|
2026-10-23 11:43:49 -05:00
|
|
|
}, []);
|
|
|
|
|
|
2026-11-18 05:18:55 +06:00
|
|
|
const fetchClientJwt = async (clientId: string): Promise<string> => {
|
|
|
|
|
const res = await fetch(`/api/clients/${encodeURIComponent(clientId)}?includeToken=true`, {
|
|
|
|
|
cache: 'no-store',
|
|
|
|
|
});
|
|
|
|
|
if (res.status === 401) {
|
|
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
throw new Error('Authentication required');
|
|
|
|
|
}
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
if (!res.ok || !data?.client?.token) {
|
|
|
|
|
throw new Error(data?.error || 'Unable to retrieve client JWT token');
|
|
|
|
|
}
|
|
|
|
|
return String(data.client.token);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const emitSocketEvents = async (
|
|
|
|
|
clientId: string,
|
|
|
|
|
items: Array<Record<string, unknown>>
|
|
|
|
|
): Promise<{ accepted: number; rejected: number; responses: Record<string, unknown>[] }> => {
|
|
|
|
|
const token = await fetchClientJwt(clientId);
|
2026-11-19 20:22:01 +06:00
|
|
|
const socketUrl = getSocketOrigin(serverPort);
|
2026-11-18 05:18:55 +06:00
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const socket = io(socketUrl, {
|
|
|
|
|
auth: { token },
|
|
|
|
|
transports: ['websocket', 'polling'],
|
|
|
|
|
reconnection: false,
|
|
|
|
|
timeout: 4000,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const timer = window.setTimeout(() => {
|
|
|
|
|
socket.disconnect();
|
2026-11-19 20:22:01 +06:00
|
|
|
reject(new Error(`WebSocket timeout (is Port ${serverPort} ingestion server running?)`));
|
2026-11-19 00:42:38 +06:00
|
|
|
}, 5000);
|
2026-11-18 05:18:55 +06:00
|
|
|
|
|
|
|
|
socket.on('connect_error', (connectErr) => {
|
|
|
|
|
window.clearTimeout(timer);
|
|
|
|
|
socket.disconnect();
|
|
|
|
|
reject(new Error(connectErr.message || 'WebSocket authentication failed'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.on('connect', () => {
|
2026-11-19 00:42:38 +06:00
|
|
|
if (items.length === 1) {
|
|
|
|
|
const eventId = `sim_ws_${Date.now()}_0`;
|
|
|
|
|
socket.emit(
|
|
|
|
|
'sync_data',
|
|
|
|
|
{
|
|
|
|
|
clientId,
|
|
|
|
|
eventId,
|
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
|
data: items[0],
|
|
|
|
|
},
|
|
|
|
|
(response: Record<string, unknown>) => {
|
|
|
|
|
window.clearTimeout(timer);
|
|
|
|
|
socket.disconnect();
|
|
|
|
|
const ok = Boolean(response?.success);
|
|
|
|
|
resolve({
|
|
|
|
|
accepted: ok ? 1 : 0,
|
|
|
|
|
rejected: ok ? 0 : 1,
|
|
|
|
|
responses: [response || { success: false, error: 'Empty response' }],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
const batchPayload = items.map((data, idx) => ({
|
|
|
|
|
eventId: `sim_ws_${Date.now()}_${idx}`,
|
2026-11-18 05:18:55 +06:00
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
|
data,
|
2026-11-19 00:42:38 +06:00
|
|
|
}));
|
|
|
|
|
socket.emit('batch_sync', batchPayload, (response: Record<string, unknown>) => {
|
|
|
|
|
window.clearTimeout(timer);
|
|
|
|
|
socket.disconnect();
|
|
|
|
|
const processed = Number(response?.processed) || 0;
|
|
|
|
|
const rejected = Number(response?.rejected) || 0;
|
|
|
|
|
const ok = Boolean(response?.success);
|
|
|
|
|
resolve({
|
|
|
|
|
accepted: processed,
|
|
|
|
|
rejected: ok && rejected === 0 ? 0 : (rejected || (ok ? 0 : items.length)),
|
|
|
|
|
responses: [response || { success: false, error: 'Empty response' }],
|
|
|
|
|
});
|
2026-11-18 05:18:55 +06:00
|
|
|
});
|
2026-11-19 00:42:38 +06:00
|
|
|
}
|
2026-11-18 05:18:55 +06:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-23 11:43:49 -05:00
|
|
|
const handleSendSingle = async () => {
|
2026-11-18 05:18:55 +06:00
|
|
|
if (!selectedClient) {
|
|
|
|
|
error('No target client', 'Register a client in /vcon/clients first.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let parsedData: Record<string, unknown>;
|
2026-10-23 11:43:49 -05:00
|
|
|
try {
|
2026-11-18 05:18:55 +06:00
|
|
|
const raw = JSON.parse(payloadText);
|
|
|
|
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
|
|
|
error('Invalid payload', 'Payload must be a JSON object.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
parsedData = raw as Record<string, unknown>;
|
2026-10-23 11:43:49 -05:00
|
|
|
} catch {
|
2026-11-16 21:58:18 +06:00
|
|
|
error('Invalid JSON', 'Fix payload syntax');
|
2026-10-23 11:43:49 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSending(true);
|
|
|
|
|
try {
|
2026-11-18 05:18:55 +06:00
|
|
|
if (transport === 'websocket') {
|
|
|
|
|
const result = await emitSocketEvents(selectedClient, [parsedData]);
|
|
|
|
|
const first = result.responses[0] || {};
|
|
|
|
|
setLastResponse({ transport: 'websocket', ...first });
|
|
|
|
|
if (result.accepted > 0) {
|
|
|
|
|
setDispatchStatus('Accepted');
|
|
|
|
|
success('WebSocket Event Accepted', `${String(first.eventId || selectedClient)} acknowledged`);
|
|
|
|
|
} else {
|
|
|
|
|
setDispatchStatus('Rejected');
|
|
|
|
|
error('WebSocket Event Rejected', String(first.message || first.error || 'Rejected by Port 4000'));
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-23 11:43:49 -05:00
|
|
|
const res = await fetch('/api/events', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({
|
2026-11-18 05:18:55 +06:00
|
|
|
clientId: selectedClient,
|
2026-10-23 11:43:49 -05:00
|
|
|
data: parsedData,
|
|
|
|
|
}),
|
|
|
|
|
});
|
2026-11-18 05:18:55 +06:00
|
|
|
if (res.status === 401) {
|
|
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-10-23 11:43:49 -05:00
|
|
|
|
|
|
|
|
const data = await res.json();
|
2026-11-18 05:18:55 +06:00
|
|
|
setLastResponse({ transport: 'http', status: res.status, ...data });
|
2026-10-23 11:43:49 -05:00
|
|
|
|
|
|
|
|
if (res.ok) {
|
2026-11-18 05:18:55 +06:00
|
|
|
setDispatchStatus('Accepted');
|
|
|
|
|
success('Event Accepted', `${data.event?.eventId || selectedClient} buffered`);
|
2026-10-23 11:43:49 -05:00
|
|
|
} else {
|
2026-11-18 05:18:55 +06:00
|
|
|
setDispatchStatus('Rejected');
|
2026-10-23 11:43:49 -05:00
|
|
|
error('Event Rejected', data.error || 'Server rejected');
|
|
|
|
|
}
|
2026-11-18 05:18:55 +06:00
|
|
|
} catch (err: unknown) {
|
|
|
|
|
const message = err instanceof Error ? err.message : 'Dispatch error';
|
|
|
|
|
setDispatchStatus('Error');
|
|
|
|
|
setLastResponse({ transport, error: message });
|
|
|
|
|
error('Dispatch failed', message);
|
2026-10-23 11:43:49 -05:00
|
|
|
} finally {
|
|
|
|
|
setSending(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSendBatch = async (count = 10) => {
|
2026-11-18 05:18:55 +06:00
|
|
|
if (!selectedClient) {
|
|
|
|
|
error('No target client', 'Register a client in /vcon/clients first.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const items = Array.from({ length: count }, (_, i) => ({
|
|
|
|
|
batch_index: i + 1,
|
|
|
|
|
sensor: `sensor_${(i % 3) + 1}`,
|
|
|
|
|
reading: +(Math.random() * 100).toFixed(2),
|
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
|
}));
|
|
|
|
|
|
2026-10-23 11:43:49 -05:00
|
|
|
setSending(true);
|
|
|
|
|
try {
|
2026-11-18 05:18:55 +06:00
|
|
|
if (transport === 'websocket') {
|
|
|
|
|
const result = await emitSocketEvents(selectedClient, items);
|
|
|
|
|
setLastResponse({
|
|
|
|
|
transport: 'websocket',
|
|
|
|
|
batchSent: count,
|
|
|
|
|
accepted: result.accepted,
|
|
|
|
|
rejected: result.rejected,
|
|
|
|
|
sample: result.responses.slice(0, 3),
|
|
|
|
|
});
|
|
|
|
|
if (result.accepted === 0) {
|
|
|
|
|
setDispatchStatus('Rejected');
|
|
|
|
|
error('WebSocket Batch Rejected', `0/${count} events ingested`);
|
|
|
|
|
} else if (result.accepted < count) {
|
|
|
|
|
setDispatchStatus('Rejected');
|
|
|
|
|
warning('WebSocket Batch Partial', `${result.accepted}/${count} ingested (${result.rejected} rejected)`);
|
|
|
|
|
} else {
|
|
|
|
|
setDispatchStatus('Accepted');
|
|
|
|
|
success('WebSocket Batch Streamed', `${result.accepted}/${count} ingested`);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-19 20:22:01 +06:00
|
|
|
const batchPayload = items.map((item, idx) => ({
|
|
|
|
|
eventId: `sim_http_${Date.now()}_${idx}`,
|
|
|
|
|
timestamp: item.timestamp,
|
|
|
|
|
data: item,
|
|
|
|
|
}));
|
|
|
|
|
const res = await fetch('/api/events', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
clientId: selectedClient,
|
|
|
|
|
batch: batchPayload,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
if (res.status === 401) {
|
|
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
return;
|
2026-10-23 11:43:49 -05:00
|
|
|
}
|
2026-11-18 05:18:55 +06:00
|
|
|
|
2026-11-19 20:22:01 +06:00
|
|
|
const data = await res.json().catch(() => ({}));
|
|
|
|
|
const summary = summarizeHttpBatchResult(
|
|
|
|
|
res.ok,
|
|
|
|
|
data && typeof data === 'object' ? (data as Record<string, unknown>) : null,
|
|
|
|
|
count,
|
|
|
|
|
);
|
2026-11-18 05:18:55 +06:00
|
|
|
setLastResponse({
|
|
|
|
|
transport: 'http',
|
2026-11-19 20:22:01 +06:00
|
|
|
status: res.status,
|
2026-11-18 05:18:55 +06:00
|
|
|
batchSent: count,
|
2026-11-19 20:22:01 +06:00
|
|
|
accepted: summary.accepted,
|
|
|
|
|
rejected: summary.rejected,
|
|
|
|
|
duplicates: summary.duplicates,
|
|
|
|
|
...(data && typeof data === 'object' ? data : {}),
|
2026-11-18 05:18:55 +06:00
|
|
|
});
|
|
|
|
|
|
2026-11-19 20:22:01 +06:00
|
|
|
setDispatchStatus(summary.status);
|
|
|
|
|
if (summary.level === 'error') {
|
|
|
|
|
error(summary.title, summary.message);
|
|
|
|
|
} else if (summary.level === 'warning') {
|
|
|
|
|
warning(summary.title, summary.message);
|
2026-11-18 05:18:55 +06:00
|
|
|
} else {
|
2026-11-19 20:22:01 +06:00
|
|
|
success(summary.title, summary.message);
|
2026-11-18 05:18:55 +06:00
|
|
|
}
|
|
|
|
|
} catch (err: unknown) {
|
|
|
|
|
const message = err instanceof Error ? err.message : 'Batch dispatch error';
|
|
|
|
|
setDispatchStatus('Error');
|
|
|
|
|
setLastResponse({ transport, error: message });
|
|
|
|
|
error('Batch Error', message);
|
2026-10-23 11:43:49 -05:00
|
|
|
} finally {
|
|
|
|
|
setSending(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-11-17 00:24:33 +06:00
|
|
|
<PageShell
|
|
|
|
|
title="Simulator"
|
|
|
|
|
actions={
|
|
|
|
|
<>
|
|
|
|
|
<Button
|
|
|
|
|
size="xs"
|
|
|
|
|
variant="secondary"
|
|
|
|
|
loading={sending}
|
2026-11-18 05:18:55 +06:00
|
|
|
disabled={sending || !selectedClient}
|
|
|
|
|
onClick={() => void handleSendBatch(10)}
|
2026-11-17 00:24:33 +06:00
|
|
|
>
|
|
|
|
|
Burst 10
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
size="xs"
|
|
|
|
|
variant="primary"
|
|
|
|
|
icon="Send"
|
|
|
|
|
loading={sending}
|
2026-11-18 05:18:55 +06:00
|
|
|
disabled={sending || !selectedClient}
|
|
|
|
|
onClick={() => void handleSendSingle()}
|
2026-11-17 00:24:33 +06:00
|
|
|
>
|
|
|
|
|
Send Event
|
|
|
|
|
</Button>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
>
|
2026-11-18 05:18:55 +06:00
|
|
|
{clients.length === 0 && (
|
|
|
|
|
<div
|
|
|
|
|
role="alert"
|
|
|
|
|
className="mb-3 flex flex-wrap items-center justify-between gap-2 border border-[var(--warning)] bg-[var(--warning-soft)] px-3 py-2 text-[11.5px] text-[var(--text)]"
|
|
|
|
|
>
|
|
|
|
|
<span>No registered SDK clients found. Register a client before dispatching events.</span>
|
|
|
|
|
<Link href="/vcon/clients" className="font-medium text-[var(--accent)] underline">
|
|
|
|
|
Go to Clients →
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-11-17 00:24:33 +06:00
|
|
|
<StatStrip
|
|
|
|
|
items={[
|
|
|
|
|
{
|
|
|
|
|
label: 'Target client',
|
2026-11-18 05:18:55 +06:00
|
|
|
value: selectedClient || 'None selected',
|
|
|
|
|
dot: selectedClient ? 'ok' : 'off',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Ingest transport',
|
2026-11-19 20:22:01 +06:00
|
|
|
value: transport === 'http' ? 'POST /api/events' : `WS Port ${serverPort}`,
|
2026-11-17 00:24:33 +06:00
|
|
|
},
|
|
|
|
|
{ label: 'Payload format', value: 'JSON' },
|
|
|
|
|
{
|
|
|
|
|
label: 'Last dispatch',
|
2026-11-18 05:18:55 +06:00
|
|
|
value: dispatchStatus,
|
|
|
|
|
dot:
|
|
|
|
|
dispatchStatus === 'Accepted'
|
|
|
|
|
? 'ok'
|
|
|
|
|
: dispatchStatus === 'Ready'
|
|
|
|
|
? undefined
|
|
|
|
|
: 'off',
|
2026-11-17 00:24:33 +06:00
|
|
|
},
|
|
|
|
|
]}
|
2026-11-16 21:58:18 +06:00
|
|
|
/>
|
2026-10-23 11:43:49 -05:00
|
|
|
|
2026-11-17 00:24:33 +06:00
|
|
|
<div className="grid grid-cols-1 gap-3 lg:grid-cols-2">
|
2026-11-16 21:58:18 +06:00
|
|
|
<Panel title="Payload" bodyClassName="flex flex-col gap-2.5 p-3">
|
2026-11-18 05:18:55 +06:00
|
|
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
|
|
|
<span className="text-[10px] uppercase tracking-wider text-[var(--text-faint)]">
|
|
|
|
|
Transport
|
|
|
|
|
</span>
|
|
|
|
|
<div className="flex gap-1" role="group" aria-label="Ingest transport">
|
|
|
|
|
<Pill
|
|
|
|
|
active={transport === 'http'}
|
|
|
|
|
onClick={() => setTransport('http')}
|
|
|
|
|
>
|
|
|
|
|
HTTP /api/events
|
|
|
|
|
</Pill>
|
|
|
|
|
<Pill
|
|
|
|
|
active={transport === 'websocket'}
|
|
|
|
|
onClick={() => setTransport('websocket')}
|
|
|
|
|
>
|
2026-11-19 20:22:01 +06:00
|
|
|
WebSocket Port {serverPort}
|
2026-11-18 05:18:55 +06:00
|
|
|
</Pill>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-16 21:58:18 +06:00
|
|
|
<Select
|
|
|
|
|
compact
|
2026-11-18 05:18:55 +06:00
|
|
|
label="Target client"
|
2026-11-16 21:58:18 +06:00
|
|
|
value={selectedClient}
|
2026-11-18 05:18:55 +06:00
|
|
|
disabled={clients.length === 0}
|
2026-11-16 21:58:18 +06:00
|
|
|
onChange={(e) => setSelectedClient(e.target.value)}
|
|
|
|
|
>
|
2026-11-18 05:18:55 +06:00
|
|
|
{clients.length === 0 ? (
|
|
|
|
|
<option value="">No registered clients</option>
|
|
|
|
|
) : (
|
|
|
|
|
clients.map((c) => (
|
|
|
|
|
<option key={c.clientId} value={c.clientId}>
|
|
|
|
|
{c.clientId} ({c.status})
|
|
|
|
|
</option>
|
|
|
|
|
))
|
|
|
|
|
)}
|
2026-11-16 21:58:18 +06:00
|
|
|
</Select>
|
2026-10-23 11:43:49 -05:00
|
|
|
|
2026-11-16 21:58:18 +06:00
|
|
|
<Textarea
|
2026-11-18 05:18:55 +06:00
|
|
|
label="Event JSON"
|
2026-11-16 21:58:18 +06:00
|
|
|
rows={7}
|
|
|
|
|
value={payloadText}
|
|
|
|
|
onChange={(e) => setPayloadText(e.target.value)}
|
|
|
|
|
className="font-mono text-[11.5px]"
|
|
|
|
|
/>
|
|
|
|
|
</Panel>
|
|
|
|
|
|
|
|
|
|
<Panel title="Response" bodyClassName="p-3 font-mono text-[11.5px]">
|
|
|
|
|
{lastResponse ? (
|
|
|
|
|
<CodeBlock className="max-h-[280px] border border-[var(--border)] text-[11px]">
|
|
|
|
|
{JSON.stringify(lastResponse, null, 2)}
|
|
|
|
|
</CodeBlock>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="border border-dashed border-[var(--border-strong)] p-5 text-center text-[11px] text-[var(--text-dim)]">
|
|
|
|
|
No response
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Panel>
|
2026-10-23 11:43:49 -05:00
|
|
|
</div>
|
2026-11-17 00:24:33 +06:00
|
|
|
</PageShell>
|
2026-10-23 11:43:49 -05:00
|
|
|
);
|
|
|
|
|
}
|