Add event viewer
This commit is contained in:
		
					parent
					
						
							
								49353cd2fe
							
						
					
				
			
			
				commit
				
					
						fe5e840630
					
				
			
		
					 3 changed files with 91 additions and 8 deletions
				
			
		| 
						 | 
					@ -188,7 +188,7 @@ export class ConferenceCallManager extends EventEmitter {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (type.startsWith("m.call.") || type.startsWith("me.robertlong.conf")) {
 | 
					    if (type.startsWith("m.call.") || type.startsWith("me.robertlong.conf")) {
 | 
				
			||||||
      const content = event.getContent();
 | 
					      const content = event.getContent();
 | 
				
			||||||
      const details = {};
 | 
					      const details = { content };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      switch (type) {
 | 
					      switch (type) {
 | 
				
			||||||
        case "m.call.invite":
 | 
					        case "m.call.invite":
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,16 @@ import styles from "./DevTools.module.css";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const colorHash = new ColorHash({ lightness: 0.8 });
 | 
					const colorHash = new ColorHash({ lightness: 0.8 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function UserId({ userId, ...rest }) {
 | 
				
			||||||
 | 
					  const shortUserId = userId.split(":")[0];
 | 
				
			||||||
 | 
					  const color = colorHash.hex(shortUserId);
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    <span style={{ color }} {...rest}>
 | 
				
			||||||
 | 
					      {shortUserId}
 | 
				
			||||||
 | 
					    </span>
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function CallId({ callId, ...rest }) {
 | 
					function CallId({ callId, ...rest }) {
 | 
				
			||||||
  const shortId = callId.substr(callId.length - 16);
 | 
					  const shortId = callId.substr(callId.length - 16);
 | 
				
			||||||
  const color = colorHash.hex(shortId);
 | 
					  const color = colorHash.hex(shortId);
 | 
				
			||||||
| 
						 | 
					@ -17,6 +27,7 @@ function CallId({ callId, ...rest }) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function DevTools({ manager }) {
 | 
					export function DevTools({ manager }) {
 | 
				
			||||||
  const [debugState, setDebugState] = useState(manager.debugState);
 | 
					  const [debugState, setDebugState] = useState(manager.debugState);
 | 
				
			||||||
 | 
					  const [selectedEvent, setSelectedEvent] = useState();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  useEffect(() => {
 | 
					  useEffect(() => {
 | 
				
			||||||
    function onRoomDebug() {
 | 
					    function onRoomDebug() {
 | 
				
			||||||
| 
						 | 
					@ -33,13 +44,24 @@ export function DevTools({ manager }) {
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className={styles.devTools}>
 | 
					    <div className={styles.devTools}>
 | 
				
			||||||
      {Array.from(debugState.entries()).map(([userId, props]) => (
 | 
					      {Array.from(debugState.entries()).map(([userId, props]) => (
 | 
				
			||||||
        <UserState key={userId} userId={userId} {...props} />
 | 
					        <UserState
 | 
				
			||||||
 | 
					          key={userId}
 | 
				
			||||||
 | 
					          onSelectEvent={setSelectedEvent}
 | 
				
			||||||
 | 
					          userId={userId}
 | 
				
			||||||
 | 
					          {...props}
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
      ))}
 | 
					      ))}
 | 
				
			||||||
 | 
					      {selectedEvent && (
 | 
				
			||||||
 | 
					        <EventViewer
 | 
				
			||||||
 | 
					          event={selectedEvent}
 | 
				
			||||||
 | 
					          onClose={() => setSelectedEvent(null)}
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function UserState({ userId, state, callId, events }) {
 | 
					function UserState({ userId, state, callId, events, onSelectEvent }) {
 | 
				
			||||||
  const eventsRef = useRef();
 | 
					  const eventsRef = useRef();
 | 
				
			||||||
  const [autoScroll, setAutoScroll] = useState(true);
 | 
					  const [autoScroll, setAutoScroll] = useState(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,7 +72,7 @@ function UserState({ userId, state, callId, events }) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const onScroll = useCallback((event) => {
 | 
					  const onScroll = useCallback(() => {
 | 
				
			||||||
    const el = eventsRef.current;
 | 
					    const el = eventsRef.current;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (el.scrollHeight - el.scrollTop === el.clientHeight) {
 | 
					    if (el.scrollHeight - el.scrollTop === el.clientHeight) {
 | 
				
			||||||
| 
						 | 
					@ -63,13 +85,17 @@ function UserState({ userId, state, callId, events }) {
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className={styles.user}>
 | 
					    <div className={styles.user}>
 | 
				
			||||||
      <div className={styles.userId}>
 | 
					      <div className={styles.userId}>
 | 
				
			||||||
        <span>{userId}</span>
 | 
					        <UserId userId={userId} />
 | 
				
			||||||
        {callId && <CallId callId={callId} />}
 | 
					 | 
				
			||||||
        <span>{`(${state})`}</span>
 | 
					        <span>{`(${state})`}</span>
 | 
				
			||||||
 | 
					        {callId && <CallId callId={callId} />}
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      <div ref={eventsRef} className={styles.events} onScroll={onScroll}>
 | 
					      <div ref={eventsRef} className={styles.events} onScroll={onScroll}>
 | 
				
			||||||
        {events.map((event, idx) => (
 | 
					        {events.map((event, idx) => (
 | 
				
			||||||
          <div className={styles.event} key={idx}>
 | 
					          <div
 | 
				
			||||||
 | 
					            className={styles.event}
 | 
				
			||||||
 | 
					            key={idx}
 | 
				
			||||||
 | 
					            onClick={() => onSelectEvent(event)}
 | 
				
			||||||
 | 
					          >
 | 
				
			||||||
            <span className={styles.eventType}>{event.type}</span>
 | 
					            <span className={styles.eventType}>{event.type}</span>
 | 
				
			||||||
            {event.callId && (
 | 
					            {event.callId && (
 | 
				
			||||||
              <CallId className={styles.eventDetails} callId={event.callId} />
 | 
					              <CallId className={styles.eventDetails} callId={event.callId} />
 | 
				
			||||||
| 
						 | 
					@ -84,7 +110,7 @@ function UserState({ userId, state, callId, events }) {
 | 
				
			||||||
              </>
 | 
					              </>
 | 
				
			||||||
            )}
 | 
					            )}
 | 
				
			||||||
            {event.to && (
 | 
					            {event.to && (
 | 
				
			||||||
              <span className={styles.eventDetails}>{event.to}</span>
 | 
					              <UserId className={styles.eventDetails} userId={event.to} />
 | 
				
			||||||
            )}
 | 
					            )}
 | 
				
			||||||
            {event.reason && (
 | 
					            {event.reason && (
 | 
				
			||||||
              <span className={styles.eventDetails}>{event.reason}</span>
 | 
					              <span className={styles.eventDetails}>{event.reason}</span>
 | 
				
			||||||
| 
						 | 
					@ -95,3 +121,41 @@ function UserState({ userId, state, callId, events }) {
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function EventViewer({ event, onClose }) {
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    <div className={styles.eventViewer}>
 | 
				
			||||||
 | 
					      <p>Event Type: {event.type}</p>
 | 
				
			||||||
 | 
					      {event.callId && (
 | 
				
			||||||
 | 
					        <p>
 | 
				
			||||||
 | 
					          Call Id: <CallId callId={event.callId} />
 | 
				
			||||||
 | 
					        </p>
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
 | 
					      {event.newCallId && (
 | 
				
			||||||
 | 
					        <p>
 | 
				
			||||||
 | 
					          New Call Id:
 | 
				
			||||||
 | 
					          <CallId callId={event.newCallId} />
 | 
				
			||||||
 | 
					        </p>
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
 | 
					      {event.to && (
 | 
				
			||||||
 | 
					        <p>
 | 
				
			||||||
 | 
					          To: <UserId userId={event.to} />
 | 
				
			||||||
 | 
					        </p>
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
 | 
					      {event.reason && (
 | 
				
			||||||
 | 
					        <p>
 | 
				
			||||||
 | 
					          Reason: <span>{event.reason}</span>
 | 
				
			||||||
 | 
					        </p>
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
 | 
					      {event.content && (
 | 
				
			||||||
 | 
					        <>
 | 
				
			||||||
 | 
					          <p>Content:</p>
 | 
				
			||||||
 | 
					          <pre className={styles.content}>
 | 
				
			||||||
 | 
					            {JSON.stringify(event.content, undefined, 2)}
 | 
				
			||||||
 | 
					          </pre>
 | 
				
			||||||
 | 
					        </>
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
 | 
					      <button onClick={onClose}>Close</button>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,3 +68,22 @@
 | 
				
			||||||
  font-weight: 200;
 | 
					  font-weight: 200;
 | 
				
			||||||
  word-break: break-all;
 | 
					  word-break: break-all;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.eventViewer {
 | 
				
			||||||
 | 
					  position: absolute;
 | 
				
			||||||
 | 
					  top: 50%;
 | 
				
			||||||
 | 
					  left: 50%;
 | 
				
			||||||
 | 
					  transform: translate(-50%, -50%);
 | 
				
			||||||
 | 
					  min-width: 320px;
 | 
				
			||||||
 | 
					  max-width: 80%;
 | 
				
			||||||
 | 
					  border-radius: 8px;
 | 
				
			||||||
 | 
					  border: 1px solid black;
 | 
				
			||||||
 | 
					  background-color: #222;
 | 
				
			||||||
 | 
					  padding: 20px;
 | 
				
			||||||
 | 
					  margin: 20px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.eventViewer .content {
 | 
				
			||||||
 | 
					  max-height: 200px;
 | 
				
			||||||
 | 
					  overflow: auto;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue