/* Copyright 2021 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React, { useCallback, useEffect, useRef, useState } from "react"; import { createPortal } from "react-dom"; import ColorHash from "color-hash"; import classNames from "classnames"; import styles from "./DevTools.module.css"; import { Resizable } from "re-resizable"; const colorHash = new ColorHash({ lightness: 0.8 }); function UserId({ userId, ...rest }) { const shortUserId = userId.split(":")[0]; const color = colorHash.hex(shortUserId); return ( {shortUserId} ); } function CallId({ callId, ...rest }) { const shortId = callId.substr(callId.length - 16); const color = colorHash.hex(shortId); return ( {shortId} ); } function sortEntries(a, b) { const aInactive = a[1].state === "inactive"; const bInactive = b[1].state === "inactive"; if (aInactive && !bInactive) { return 1; } else if (bInactive && !aInactive) { return -1; } else { return a[0] < b[0] ? -1 : 1; } } export function DevTools({ callDebugger }) { const [debugState, setDebugState] = useState(callDebugger.debugState); const [selectedEvent, setSelectedEvent] = useState(); const [activeTab, setActiveTab] = useState("users"); useEffect(() => { function onRoomDebug() { setDebugState({ ...callDebugger.debugState }); } callDebugger.on("debug", onRoomDebug); return () => { callDebugger.removeListener("debug", onRoomDebug); }; }, [callDebugger]); if (!callDebugger.groupCall.entered) { return
; } return (Event Type: {type}
Sender: {sender}
{call_id && (
Call Id:
Invitee:
Raw Event:
{JSON.stringify(json, undefined, 2)}