Spaces:
Running
Running
Download src/components/clients/PushStreamRow.tsx from evalstate/mcp-webcam: direct link, hf CLI and curl.
- Browser
- Download file 4.6 kB
-
https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/clients/PushStreamRow.tsx
- Command line
-
hf download hf://spaces/evalstate/mcp-webcam/src/components/clients/PushStreamRow.tsx
-
curl -L -o PushStreamRow.tsx https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/clients/PushStreamRow.tsx
4.6 kB
| import { Copy, Heart, PlugZap, ShieldBan } from 'lucide-react'; | |
| import { toast } from 'sonner'; | |
| import type { PushStreamView } from '../../../shared/api-types'; | |
| import { Badge } from '@/components/ui/badge'; | |
| import { Button } from '@/components/ui/button'; | |
| import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; | |
| import { formatMs, formatUptime, prettyCursor } from '@/lib/format'; | |
| import { ClientBadge } from './ClientBadge'; | |
| import { EraBadge } from './EraBadge'; | |
| export function PushStreamRow({ | |
| stream, | |
| nowMs, | |
| heartbeatSeq, | |
| onDrop, | |
| onRevoke, | |
| }: { | |
| stream: PushStreamView; | |
| nowMs: number; | |
| heartbeatSeq: number; | |
| onDrop: (streamId: string) => Promise<void>; | |
| onRevoke: (streamId: string) => Promise<void>; | |
| }) { | |
| const copyCursor = async () => { | |
| if (!stream.cursor) return; | |
| try { | |
| await navigator.clipboard.writeText(stream.cursor); | |
| toast.success('Copied stream cursor'); | |
| } catch { | |
| toast.error('Clipboard copy failed'); | |
| } | |
| }; | |
| return ( | |
| <div className="rounded-lg border border-push/25 bg-panel-2/45 p-2.5 space-y-2"> | |
| <div className="flex items-start justify-between gap-2"> | |
| <div className="min-w-0 space-y-1"> | |
| <div className="flex flex-wrap items-center gap-1.5"> | |
| <span className="h-2 w-2 rounded-full bg-push shrink-0" /> | |
| <ClientBadge client={stream.client} /> | |
| <EraBadge era={stream.client.era} protocolVersion={stream.client.protocolVersion} /> | |
| </div> | |
| <div className="flex flex-wrap items-center gap-1.5"> | |
| <Badge variant="event" className="font-mono text-[10px]"> | |
| {stream.eventName} | |
| </Badge> | |
| <button | |
| type="button" | |
| onClick={() => void copyCursor()} | |
| className="inline-flex items-center gap-1 font-mono text-[10.5px] text-muted hover:text-fg cursor-pointer" | |
| title={stream.cursor ? `Copy cursor ${stream.cursor}` : 'No cursor'} | |
| > | |
| <span>cur:{prettyCursor(stream.cursor)}</span> | |
| {stream.cursor && <Copy className="h-2.5 w-2.5 opacity-60" />} | |
| </button> | |
| </div> | |
| </div> | |
| <div className="flex items-center gap-1 shrink-0"> | |
| <Tooltip> | |
| <TooltipTrigger asChild> | |
| <Button | |
| variant="outline" | |
| size="sm" | |
| className="h-6.5 px-2 text-[11px]" | |
| onClick={() => | |
| void onDrop(stream.streamId) | |
| .then(() => toast.info('Dropped push stream (graceful close)')) | |
| .catch((e) => toast.error(e instanceof Error ? e.message : 'Drop failed')) | |
| } | |
| > | |
| <PlugZap className="h-3 w-3" /> | |
| Drop | |
| </Button> | |
| </TooltipTrigger> | |
| <TooltipContent>Close gracefully; client reconnects from its cursor</TooltipContent> | |
| </Tooltip> | |
| <Tooltip> | |
| <TooltipTrigger asChild> | |
| <Button | |
| variant="danger" | |
| size="sm" | |
| className="h-6.5 px-2 text-[11px]" | |
| onClick={() => | |
| void onRevoke(stream.streamId) | |
| .then(() => toast.warning('Revoked push stream (-32024 Forbidden)')) | |
| .catch((e) => toast.error(e instanceof Error ? e.message : 'Revoke failed')) | |
| } | |
| > | |
| <ShieldBan className="h-3 w-3" /> | |
| Revoke | |
| </Button> | |
| </TooltipTrigger> | |
| <TooltipContent>Send terminated / -32024 Forbidden so client removes subscription</TooltipContent> | |
| </Tooltip> | |
| </div> | |
| </div> | |
| <div className="flex flex-wrap items-center gap-3 text-[11px] text-muted tabular-nums"> | |
| <span className="relative inline-flex items-center gap-1 text-push"> | |
| <span className="relative flex h-3.5 w-3.5 items-center justify-center"> | |
| {heartbeatSeq > 0 && ( | |
| <span | |
| key={heartbeatSeq} | |
| className="animate-heartbeat-ring absolute inset-0 rounded-full border border-push" | |
| /> | |
| )} | |
| <Heart className="h-3 w-3 fill-current" /> | |
| </span> | |
| <span>{formatMs(stream.heartbeatMs)}</span> | |
| </span> | |
| <span>up {formatUptime(stream.openedAt, nowMs)}</span> | |
| <span> | |
| delivered <strong className="font-medium text-fg">{stream.delivered}</strong> | |
| </span> | |
| </div> | |
| </div> | |
| ); | |
| } | |