2023-01-19 19:56:00 +01:00
|
|
|
import * as React from 'react';
|
|
|
|
import { useRoomContext } from '@livekit/components-react';
|
2024-03-05 15:48:46 +01:00
|
|
|
import { setLogLevel, getLogger, LogLevel, RemoteTrackPublication } from 'livekit-client';
|
2023-08-04 12:09:39 +02:00
|
|
|
import { tinykeys } from 'tinykeys';
|
|
|
|
import styles from '../styles/Debug.module.css';
|
2023-01-19 19:56:00 +01:00
|
|
|
|
2023-01-20 15:41:00 +01:00
|
|
|
export const useDebugMode = ({ logLevel }: { logLevel?: LogLevel }) => {
|
2023-01-19 19:56:00 +01:00
|
|
|
const room = useRoomContext();
|
2023-08-04 12:09:39 +02:00
|
|
|
|
2023-01-19 19:56:00 +01:00
|
|
|
React.useEffect(() => {
|
2024-01-20 11:40:24 +01:00
|
|
|
setLogLevel(logLevel ?? 'debug');
|
2024-03-05 15:48:46 +01:00
|
|
|
// @ts-ignore
|
|
|
|
setLogLevel('debug', 'lk-e2ee');
|
|
|
|
|
2023-01-19 19:56:00 +01:00
|
|
|
// @ts-expect-error
|
|
|
|
window.__lk_room = room;
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
// @ts-expect-error
|
|
|
|
window.__lk_room = undefined;
|
|
|
|
};
|
2024-01-20 11:40:24 +01:00
|
|
|
}, [room, logLevel]);
|
2023-01-19 19:56:00 +01:00
|
|
|
};
|
|
|
|
|
2023-01-20 15:41:00 +01:00
|
|
|
export const DebugMode = ({ logLevel }: { logLevel?: LogLevel }) => {
|
2023-08-04 12:09:39 +02:00
|
|
|
const room = useRoomContext();
|
|
|
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
|
|
const [, setRender] = React.useState({});
|
2024-02-20 13:05:10 +01:00
|
|
|
const [roomSid, setRoomSid] = React.useState('');
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
room.getSid().then(setRoomSid);
|
|
|
|
}, [room]);
|
2023-08-04 12:09:39 +02:00
|
|
|
|
2023-01-20 15:41:00 +01:00
|
|
|
useDebugMode({ logLevel });
|
2023-08-04 12:09:39 +02:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (window) {
|
|
|
|
const unsubscribe = tinykeys(window, {
|
|
|
|
'Shift+D': () => {
|
|
|
|
console.log('setting open');
|
|
|
|
setIsOpen((open) => !open);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// timer to re-render
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
setRender({});
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
unsubscribe();
|
|
|
|
clearInterval(interval);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}, [isOpen]);
|
|
|
|
|
|
|
|
if (typeof window === 'undefined' || !isOpen) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleSimulate = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
|
|
const { value } = event.target;
|
|
|
|
if (value == '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.target.value = '';
|
|
|
|
let isReconnect = false;
|
|
|
|
switch (value) {
|
|
|
|
case 'signal-reconnect':
|
|
|
|
isReconnect = true;
|
|
|
|
|
|
|
|
// fall through
|
|
|
|
default:
|
|
|
|
// @ts-expect-error
|
|
|
|
room.simulateScenario(value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const lp = room.localParticipant;
|
|
|
|
|
|
|
|
if (!isOpen) {
|
|
|
|
return <></>;
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div className={styles.overlay}>
|
|
|
|
<section id="room-info">
|
|
|
|
<h3>
|
2024-02-20 13:05:10 +01:00
|
|
|
Room Info {room.name}: {roomSid}
|
2023-08-04 12:09:39 +02:00
|
|
|
</h3>
|
|
|
|
</section>
|
|
|
|
<details open>
|
|
|
|
<summary>
|
|
|
|
<b>Local Participant: {lp.identity}</b>
|
|
|
|
</summary>
|
|
|
|
<details open className={styles.detailsSection}>
|
|
|
|
<summary>
|
|
|
|
<b>Published tracks</b>
|
|
|
|
</summary>
|
|
|
|
<div>
|
2024-02-20 13:05:10 +01:00
|
|
|
{Array.from(lp.trackPublications.values()).map((t) => (
|
2023-08-04 12:09:39 +02:00
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<i>
|
|
|
|
{t.source.toString()}
|
|
|
|
<span>{t.trackSid}</span>
|
|
|
|
</i>
|
|
|
|
</div>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>Kind</td>
|
|
|
|
<td>
|
|
|
|
{t.kind}
|
|
|
|
{t.kind === 'video' && (
|
|
|
|
<span>
|
|
|
|
{t.track?.dimensions?.width}x{t.track?.dimensions?.height}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Bitrate</td>
|
|
|
|
<td>{Math.ceil(t.track!.currentBitrate / 1000)} kbps</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</details>
|
|
|
|
<details open className={styles.detailsSection}>
|
|
|
|
<summary>
|
|
|
|
<b>Permissions</b>
|
|
|
|
</summary>
|
|
|
|
<div>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
{lp.permissions &&
|
|
|
|
Object.entries(lp.permissions).map(([key, val]) => (
|
|
|
|
<>
|
|
|
|
<tr>
|
|
|
|
<td>{key}</td>
|
|
|
|
{key !== 'canPublishSources' ? (
|
|
|
|
<td>{val.toString()}</td>
|
|
|
|
) : (
|
|
|
|
<td> {val.join(', ')} </td>
|
|
|
|
)}
|
|
|
|
</tr>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</details>
|
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
<b>Remote Participants</b>
|
|
|
|
</summary>
|
2024-02-20 13:05:10 +01:00
|
|
|
{Array.from(room.remoteParticipants.values()).map((p) => (
|
2023-08-04 12:09:39 +02:00
|
|
|
<details key={p.sid} className={styles.detailsSection}>
|
|
|
|
<summary>
|
|
|
|
<b>
|
|
|
|
{p.identity}
|
|
|
|
<span></span>
|
|
|
|
</b>
|
|
|
|
</summary>
|
|
|
|
<div>
|
2024-02-20 13:05:10 +01:00
|
|
|
{Array.from(p.trackPublications.values()).map((t) => (
|
2023-08-04 12:09:39 +02:00
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<i>
|
|
|
|
{t.source.toString()}
|
|
|
|
<span>{t.trackSid}</span>
|
|
|
|
</i>
|
|
|
|
</div>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>Kind</td>
|
|
|
|
<td>
|
|
|
|
{t.kind}
|
|
|
|
{t.kind === 'video' && (
|
|
|
|
<span>
|
|
|
|
{t.dimensions?.width}x{t.dimensions?.height}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Status</td>
|
|
|
|
<td>{trackStatus(t)}</td>
|
|
|
|
</tr>
|
|
|
|
{t.track && (
|
|
|
|
<tr>
|
|
|
|
<td>Bitrate</td>
|
|
|
|
<td>{Math.ceil(t.track.currentBitrate / 1000)} kbps</td>
|
|
|
|
</tr>
|
|
|
|
)}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</details>
|
|
|
|
))}
|
|
|
|
</details>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-01-19 19:56:00 +01:00
|
|
|
};
|
2023-08-04 12:09:39 +02:00
|
|
|
|
|
|
|
function trackStatus(t: RemoteTrackPublication): string {
|
|
|
|
if (t.isSubscribed) {
|
|
|
|
return t.isEnabled ? 'enabled' : 'disabled';
|
|
|
|
} else {
|
|
|
|
return 'unsubscribed';
|
|
|
|
}
|
|
|
|
}
|