Merge pull request #1910 from vector-im/dbkr/fix_no_media_perms

Fix joining calls with no media permission
This commit is contained in:
David Baker
2023-11-21 09:18:00 +00:00
committed by GitHub
3 changed files with 39 additions and 21 deletions

View File

@@ -72,35 +72,37 @@ async function doConnect(
} }
logger.info("Pre-creating microphone track"); logger.info("Pre-creating microphone track");
let preCreatedAudioTrack: LocalTrack | undefined;
try {
const audioTracks = await livekitRoom!.localParticipant.createTracks({ const audioTracks = await livekitRoom!.localParticipant.createTracks({
audio: audioOptions, audio: audioOptions,
}); });
if (audioTracks.length < 1) { if (audioTracks.length < 1) {
logger.info("Tried to pre-create local audio track but got no tracks"); logger.info("Tried to pre-create local audio track but got no tracks");
return; } else {
preCreatedAudioTrack = audioTracks[0];
} }
if (!audioEnabled) await audioTracks[0].mute();
logger.info("Pre-created microphone track"); logger.info("Pre-created microphone track");
} catch (e) {
logger.error("Failed to pre-create microphone track", e);
}
if (!audioEnabled) await preCreatedAudioTrack?.mute();
// check again having awaited for the track to create // check again having awaited for the track to create
if (livekitRoom!.localParticipant.getTrack(Track.Source.Microphone)) { if (livekitRoom!.localParticipant.getTrack(Track.Source.Microphone)) {
logger.warn( logger.warn(
"Publishing pre-created audio track but participant already appears to have an microphone track: this shouldn't happen!", "Pre-created audio track but participant already appears to have an microphone track: this shouldn't happen!",
); );
for (const t of audioTracks) { preCreatedAudioTrack?.stop();
t.stop();
}
return; return;
} }
logger.info("Connecting & publishing"); logger.info("Connecting & publishing");
try { try {
await connectAndPublish(livekitRoom, sfuConfig, audioTracks[0], []); await connectAndPublish(livekitRoom, sfuConfig, preCreatedAudioTrack, []);
} catch (e) { } catch (e) {
for (const t of audioTracks) { preCreatedAudioTrack?.stop();
t.stop();
}
} }
} }

View File

@@ -245,6 +245,19 @@ export function useLiveKit(
); );
} }
} catch (e) { } catch (e) {
if ((e as DOMException).name === "NotAllowedError") {
logger.error(
"Fatal errror while syncing mute state: resetting",
e,
);
if (type === MuteDevice.Microphone) {
audioMuteUpdating.current = false;
muteStates.audio.setEnabled?.(false);
} else {
videoMuteUpdating.current = false;
muteStates.video.setEnabled?.(false);
}
} else {
logger.error( logger.error(
"Failed to sync audio mute state with LiveKit (will retry to sync in 1s):", "Failed to sync audio mute state with LiveKit (will retry to sync in 1s):",
e, e,
@@ -252,6 +265,7 @@ export function useLiveKit(
setTimeout(() => syncMuteState(iterCount + 1, type), 1000); setTimeout(() => syncMuteState(iterCount + 1, type), 1000);
} }
} }
}
}; };
syncMuteState(0, MuteDevice.Microphone); syncMuteState(0, MuteDevice.Microphone);

View File

@@ -82,6 +82,8 @@ export const VideoPreview: FC<Props> = ({
}, },
(error) => { (error) => {
logger.error("Error while creating preview Tracks:", error); logger.error("Error while creating preview Tracks:", error);
muteStates.audio.setEnabled?.(false);
muteStates.video.setEnabled?.(false);
}, },
); );
const videoTrack = useMemo( const videoTrack = useMemo(