Experimental version of LiveKit with EC that works!

This commit is contained in:
Daniel Abramov 2023-06-02 19:12:28 +02:00
parent ee1819a0b6
commit 991129e470
2 changed files with 10 additions and 18 deletions

View file

@ -138,6 +138,8 @@ export function InCallView({
token, token,
serverUrl: "ws://localhost:7880", serverUrl: "ws://localhost:7880",
room: livekitRoom, room: livekitRoom,
audio: true,
video: true,
onConnected: () => { onConnected: () => {
console.log("connected to LiveKit room"); console.log("connected to LiveKit room");
}, },

View file

@ -19,7 +19,7 @@ import { animated } from "@react-spring/web";
import classNames from "classnames"; import classNames from "classnames";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { LocalParticipant, RemoteParticipant, Track } from "livekit-client"; import { LocalParticipant, RemoteParticipant, Track } from "livekit-client";
import { useMediaTrack } from "@livekit/components-react"; import { VideoTrack, useMediaTrack } from "@livekit/components-react";
import styles from "./VideoTile.module.css"; import styles from "./VideoTile.module.css";
import { ReactComponent as MicMutedIcon } from "../icons/MicMuted.svg"; import { ReactComponent as MicMutedIcon } from "../icons/MicMuted.svg";
@ -28,24 +28,14 @@ import { ReactComponent as VideoMutedIcon } from "../icons/VideoMuted.svg";
interface Props { interface Props {
name: string; name: string;
avatar?: JSX.Element; avatar?: JSX.Element;
maximised?: boolean;
className?: string; className?: string;
sfuParticipant: LocalParticipant | RemoteParticipant; sfuParticipant: LocalParticipant | RemoteParticipant;
} }
export const VideoTile = forwardRef<HTMLDivElement, Props>( export const VideoTile = forwardRef<HTMLDivElement, Props>(
({ name, avatar, maximised, className, sfuParticipant, ...rest }, ref) => { ({ name, avatar, className, sfuParticipant, ...rest }, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();
const videoEl = React.useRef<HTMLVideoElement>(null);
const { isMuted: cameraMuted } = useMediaTrack(
Track.Source.Camera,
sfuParticipant,
{
element: videoEl,
}
);
const audioEl = React.useRef<HTMLAudioElement>(null); const audioEl = React.useRef<HTMLAudioElement>(null);
const { isMuted: microphoneMuted } = useMediaTrack( const { isMuted: microphoneMuted } = useMediaTrack(
Track.Source.Microphone, Track.Source.Microphone,
@ -62,18 +52,18 @@ export const VideoTile = forwardRef<HTMLDivElement, Props>(
[styles.speaking]: sfuParticipant.isSpeaking, [styles.speaking]: sfuParticipant.isSpeaking,
[styles.muted]: microphoneMuted, [styles.muted]: microphoneMuted,
[styles.screenshare]: false, [styles.screenshare]: false,
[styles.maximised]: maximised, [styles.maximised]: false,
})} })}
ref={ref} ref={ref}
{...rest} {...rest}
> >
{cameraMuted && ( {!sfuParticipant.isCameraEnabled && (
<> <>
<div className={styles.videoMutedOverlay} /> <div className={styles.videoMutedOverlay} />
{avatar} {avatar}
</> </>
)} )}
{!maximised && {!false &&
(sfuParticipant.isScreenShareEnabled ? ( (sfuParticipant.isScreenShareEnabled ? (
<div className={styles.presenterLabel}> <div className={styles.presenterLabel}>
<span>{t("{{name}} is presenting", { name })}</span> <span>{t("{{name}} is presenting", { name })}</span>
@ -86,13 +76,13 @@ export const VideoTile = forwardRef<HTMLDivElement, Props>(
aren't quite real-time, so this is an important kludge to make aren't quite real-time, so this is an important kludge to make
sure no one appears muted when they've clearly begun talking. */ sure no one appears muted when they've clearly begun talking. */
microphoneMuted && microphoneMuted &&
!cameraMuted && sfuParticipant.isCameraEnabled &&
!sfuParticipant.isSpeaking && <MicMutedIcon /> !sfuParticipant.isSpeaking && <MicMutedIcon />
} }
{cameraMuted && <VideoMutedIcon />} {!sfuParticipant.isCameraEnabled && <VideoMutedIcon />}
</div> </div>
))} ))}
<video ref={videoEl} /> <VideoTrack participant={sfuParticipant} source={Track.Source.Camera} />
<audio ref={audioEl} /> <audio ref={audioEl} />
</animated.div> </animated.div>
); );