Persist audio and video mute state in video rooms (#8376)

…so that video lobbies remember whether you've disabled your camera.
This commit is contained in:
Robin 2022-04-21 11:00:32 -04:00 committed by GitHub
parent 6f5900557b
commit c70816d763
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 5 deletions

View file

@ -21,7 +21,6 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { _t } from "../../../languageHandler";
import { useAsyncMemo } from "../../../hooks/useAsyncMemo";
import { useStateToggle } from "../../../hooks/useStateToggle";
import { useConnectedMembers } from "../../../utils/VideoChannelUtils";
import VideoChannelStore from "../../../stores/VideoChannelStore";
import IconizedContextMenu, {
@ -108,6 +107,7 @@ const DeviceButton: FC<IDeviceButtonProps> = ({
const MAX_FACES = 8;
const VideoLobby: FC<{ room: Room }> = ({ room }) => {
const store = VideoChannelStore.instance;
const [connecting, setConnecting] = useState(false);
const me = useMemo(() => room.getMember(room.myUserId), [room]);
const connectedMembers = useConnectedMembers(room, false);
@ -130,8 +130,16 @@ const VideoLobby: FC<{ room: Room }> = ({ room }) => {
const audioDevice = selectedAudioDevice ?? audioDevices[0];
const videoDevice = selectedVideoDevice ?? videoDevices[0];
const [audioActive, toggleAudio] = useStateToggle(true);
const [videoActive, toggleVideo] = useStateToggle(true);
const [audioActive, setAudioActive] = useState(!store.audioMuted);
const [videoActive, setVideoActive] = useState(!store.videoMuted);
const toggleAudio = () => {
store.audioMuted = audioActive;
setAudioActive(!audioActive);
};
const toggleVideo = () => {
store.videoMuted = videoActive;
setVideoActive(!videoActive);
};
const videoStream = useAsyncMemo(async () => {
if (videoDevice && videoActive) {
@ -162,7 +170,7 @@ const VideoLobby: FC<{ room: Room }> = ({ room }) => {
const connect = async () => {
setConnecting(true);
try {
await VideoChannelStore.instance.connect(
await store.connect(
room.roomId, audioActive ? audioDevice : null, videoActive ? videoDevice : null,
);
} catch (e) {