Don't poll webrtc call stats when inspector hidden

This commit is contained in:
Robert Long 2021-11-08 11:40:46 -08:00
parent ff4c5bb9fc
commit ccd328918a

View file

@ -117,6 +117,23 @@ export function GroupCallInspector({ client, groupCall, show }) {
client.on("hangup", onCallHangup); client.on("hangup", onCallHangup);
client.on("toDeviceEvent", onToDeviceEvent); client.on("toDeviceEvent", onToDeviceEvent);
onUpdateRoomState();
}, [client, groupCall]);
const toDeviceEventsByCall = useMemo(() => {
const result = {};
for (const event of toDeviceEvents) {
const callId = event.content.call_id;
const key = `${callId} (${event.sender})`;
result[key] = result[key] || [];
result[key].push(event);
}
return result;
}, [toDeviceEvents]);
useEffect(() => {
let timeout; let timeout;
async function updateCallStats() { async function updateCallStats() {
@ -151,27 +168,14 @@ export function GroupCallInspector({ client, groupCall, show }) {
timeout = setTimeout(updateCallStats, 1000); timeout = setTimeout(updateCallStats, 1000);
} }
updateCallStats(); if (show) {
updateCallStats();
onUpdateRoomState(); }
return () => { return () => {
clearTimeout(timeout); clearTimeout(timeout);
}; };
}, [client, groupCall]); }, [show]);
const toDeviceEventsByCall = useMemo(() => {
const result = {};
for (const event of toDeviceEvents) {
const callId = event.content.call_id;
const key = `${callId} (${event.sender})`;
result[key] = result[key] || [];
result[key].push(event);
}
return result;
}, [toDeviceEvents]);
if (!show) { if (!show) {
return null; return null;