import React, { useCallback, useEffect, useRef, useState } from "react"; import ColorHash from "color-hash"; import styles from "./DevTools.module.css"; const colorHash = new ColorHash({ lightness: 0.8 }); function CallId({ callId, ...rest }) { const shortId = callId.substr(callId.length - 16); const color = colorHash.hex(shortId); return ( {shortId} ); } export function DevTools({ manager }) { const [debugState, setDebugState] = useState(manager.debugState); useEffect(() => { function onRoomDebug() { setDebugState(manager.debugState); } manager.on("debug", onRoomDebug); return () => { manager.removeListener("debug", onRoomDebug); }; }, [manager]); return (
{Array.from(debugState.entries()).map(([userId, props]) => ( ))}
); } function UserState({ userId, state, callId, events }) { const eventsRef = useRef(); const [autoScroll, setAutoScroll] = useState(true); useEffect(() => { if (autoScroll) { const el = eventsRef.current; el.scrollTop = el.scrollHeight - el.clientHeight; } }); const onScroll = useCallback((event) => { const el = eventsRef.current; if (el.scrollHeight - el.scrollTop === el.clientHeight) { setAutoScroll(true); } else { setAutoScroll(false); } }, []); return (
{userId} {callId && } {`(${state})`}
{events.map((event, idx) => (
{event.type} {event.callId && ( )} {event.newCallId && ( <> {"->"} )} {event.to && ( {event.to} )} {event.reason && ( {event.reason} )}
))}
); }