From cb45f42912a08a2ab8c03b1e5109eb24d1d78180 Mon Sep 17 00:00:00 2001 From: lukasIO Date: Thu, 29 Aug 2024 14:40:20 +0200 Subject: [PATCH] Fix local storage of user choices (#949) --- .changeset/dry-cameras-invite.md | 6 ++++++ packages/core/etc/components-core.api.md | 2 +- packages/core/src/components/mediaToggle.ts | 14 +++++++++----- packages/react/etc/components-react.api.md | 2 +- packages/react/src/hooks/useTrackToggle.ts | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 .changeset/dry-cameras-invite.md diff --git a/.changeset/dry-cameras-invite.md b/.changeset/dry-cameras-invite.md new file mode 100644 index 000000000..a63fbc55b --- /dev/null +++ b/.changeset/dry-cameras-invite.md @@ -0,0 +1,6 @@ +--- +"@livekit/components-core": patch +"@livekit/components-react": patch +--- + +Fix local storage of user choices diff --git a/packages/core/etc/components-core.api.md b/packages/core/etc/components-core.api.md index 9d3a13605..dba0d43dc 100644 --- a/packages/core/etc/components-core.api.md +++ b/packages/core/etc/components-core.api.md @@ -282,7 +282,7 @@ export const log: loglevel.Logger; // @public (undocumented) export type MediaToggleType = { pendingObserver: Observable; - toggle: (forceState?: boolean, captureOptions?: CaptureOptionsBySource) => Promise; + toggle: (forceState?: boolean, captureOptions?: CaptureOptionsBySource) => Promise; className: string; enabledObserver: Observable; }; diff --git a/packages/core/src/components/mediaToggle.ts b/packages/core/src/components/mediaToggle.ts index 251b38cdd..67b27fd56 100644 --- a/packages/core/src/components/mediaToggle.ts +++ b/packages/core/src/components/mediaToggle.ts @@ -22,7 +22,10 @@ export type CaptureOptionsBySource = T extends Track.Sou export type MediaToggleType = { pendingObserver: Observable; - toggle: (forceState?: boolean, captureOptions?: CaptureOptionsBySource) => Promise; + toggle: ( + forceState?: boolean, + captureOptions?: CaptureOptionsBySource, + ) => Promise; className: string; enabledObserver: Observable; }; @@ -79,27 +82,28 @@ export function setupMediaToggle( captureOptions as VideoCaptureOptions, publishOptions, ); - break; + return localParticipant.isCameraEnabled; case Track.Source.Microphone: await localParticipant.setMicrophoneEnabled( forceState ?? !localParticipant.isMicrophoneEnabled, captureOptions as AudioCaptureOptions, publishOptions, ); - break; + return localParticipant.isMicrophoneEnabled; case Track.Source.ScreenShare: await localParticipant.setScreenShareEnabled( forceState ?? !localParticipant.isScreenShareEnabled, captureOptions as ScreenShareCaptureOptions, publishOptions, ); - break; + return localParticipant.isScreenShareEnabled; default: - break; + throw new TypeError('Tried to toggle unsupported source'); } } catch (e) { if (onError && e instanceof Error) { onError?.(e); + return undefined; } else { throw e; } diff --git a/packages/react/etc/components-react.api.md b/packages/react/etc/components-react.api.md index f1c296de1..bbd2c00cd 100644 --- a/packages/react/etc/components-react.api.md +++ b/packages/react/etc/components-react.api.md @@ -1159,7 +1159,7 @@ export type UseTracksOptions = { // @public export function useTrackToggle({ source, onChange, initialState, captureOptions, publishOptions, onDeviceError, ...rest }: UseTrackToggleProps): { - toggle: (forceState?: boolean | undefined, captureOptions?: CaptureOptionsBySource | undefined) => Promise; + toggle: ((forceState?: boolean | undefined) => Promise) | ((forceState?: boolean | undefined, captureOptions?: CaptureOptionsBySource | undefined) => Promise); enabled: boolean; pending: boolean; track: LocalTrackPublication | undefined; diff --git a/packages/react/src/hooks/useTrackToggle.ts b/packages/react/src/hooks/useTrackToggle.ts index 30ea9a91a..4e3a1410c 100644 --- a/packages/react/src/hooks/useTrackToggle.ts +++ b/packages/react/src/hooks/useTrackToggle.ts @@ -65,7 +65,7 @@ export function useTrackToggle({ const clickHandler: React.MouseEventHandler = React.useCallback( (evt) => { userInteractionRef.current = true; - toggle().finally(() => (userInteractionRef.current = false)); + toggle().catch(() => (userInteractionRef.current = false)); rest.onClick?.(evt); }, [rest, toggle],