Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo K
2023-10-17 15:20:26 +02:00
parent 8a240fd313
commit 94594a6354

View File

@@ -52,7 +52,7 @@ interface UseLivekitResult {
export function useLiveKit( export function useLiveKit(
muteStates: MuteStates, muteStates: MuteStates,
sfuConfig?: SFUConfig, sfuConfig?: SFUConfig,
e2eeConfig?: E2EEConfig e2eeConfig?: E2EEConfig,
): UseLivekitResult { ): UseLivekitResult {
const e2eeOptions = useMemo(() => { const e2eeOptions = useMemo(() => {
if (!e2eeConfig?.sharedKey) return undefined; if (!e2eeConfig?.sharedKey) return undefined;
@@ -67,7 +67,7 @@ export function useLiveKit(
if (!e2eeConfig?.sharedKey || !e2eeOptions) return; if (!e2eeConfig?.sharedKey || !e2eeOptions) return;
(e2eeOptions.keyProvider as ExternalE2EEKeyProvider).setKey( (e2eeOptions.keyProvider as ExternalE2EEKeyProvider).setKey(
e2eeConfig?.sharedKey e2eeConfig?.sharedKey,
); );
}, [e2eeOptions, e2eeConfig?.sharedKey]); }, [e2eeOptions, e2eeConfig?.sharedKey]);
@@ -93,7 +93,7 @@ export function useLiveKit(
}, },
e2ee: e2eeOptions, e2ee: e2eeOptions,
}), }),
[e2eeOptions] [e2eeOptions],
); );
// useECConnectionState creates and publishes an audio track by hand. To keep // useECConnectionState creates and publishes an audio track by hand. To keep
@@ -131,7 +131,7 @@ export function useLiveKit(
}, },
initialMuteStates.current.audio.enabled, initialMuteStates.current.audio.enabled,
room, room,
sfuConfig sfuConfig,
); );
// Unblock audio once the connection is finished // Unblock audio once the connection is finished
@@ -175,7 +175,7 @@ export function useLiveKit(
if (iterCount > 10) { if (iterCount > 10) {
logger.error( logger.error(
"Stop trying to sync the input device with current mute state after 10 failed tries" "Stop trying to sync the input device with current mute state after 10 failed tries",
); );
return; return;
} }
@@ -201,14 +201,14 @@ export function useLiveKit(
case MuteDevice.Microphone: case MuteDevice.Microphone:
audioMuteUpdating.current = true; audioMuteUpdating.current = true;
trackPublication = await participant.setMicrophoneEnabled( trackPublication = await participant.setMicrophoneEnabled(
buttonEnabled.current.audio buttonEnabled.current.audio,
); );
audioMuteUpdating.current = false; audioMuteUpdating.current = false;
break; break;
case MuteDevice.Camera: case MuteDevice.Camera:
videoMuteUpdating.current = true; videoMuteUpdating.current = true;
trackPublication = await participant.setCameraEnabled( trackPublication = await participant.setCameraEnabled(
buttonEnabled.current.video buttonEnabled.current.video,
); );
videoMuteUpdating.current = false; videoMuteUpdating.current = false;
break; break;
@@ -231,13 +231,13 @@ export function useLiveKit(
syncMuteState(iterCount + 1, type); syncMuteState(iterCount + 1, type);
} else { } else {
throw new Error( throw new Error(
"track with new mute state could not be published" "track with new mute state could not be published",
); );
} }
} catch (e) { } catch (e) {
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,
); );
setTimeout(() => syncMuteState(iterCount + 1, type), 1000); setTimeout(() => syncMuteState(iterCount + 1, type), 1000);
} }
@@ -269,11 +269,11 @@ export function useLiveKit(
room.options.audioCaptureDefaults?.deviceId === "default" room.options.audioCaptureDefaults?.deviceId === "default"
) { ) {
const activeMicTrack = Array.from( const activeMicTrack = Array.from(
room.localParticipant.audioTracks.values() room.localParticipant.audioTracks.values(),
).find((d) => d.source === Track.Source.Microphone)?.track; ).find((d) => d.source === Track.Source.Microphone)?.track;
const defaultDevice = device.available.find( const defaultDevice = device.available.find(
(d) => d.deviceId === "default" (d) => d.deviceId === "default",
); );
if ( if (
defaultDevice && defaultDevice &&
@@ -299,7 +299,7 @@ export function useLiveKit(
room room
.switchActiveDevice(kind, id) .switchActiveDevice(kind, id)
.catch((e) => .catch((e) =>
logger.error(`Failed to sync ${kind} device with LiveKit`, e) logger.error(`Failed to sync ${kind} device with LiveKit`, e),
); );
} }
} }