Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ const usePreviewPublisher = (): PreviewPublisherContextType => {
if (publisherRef.current) {
return;
}
// We reset user preferences as we want to start with both devices enabled
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, 'true');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, 'true');
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, isAudioEnabled);

setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, 'true');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, 'true');
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, isVideoEnabled);


// Set videoFilter based on user's selected background
let videoFilter: VideoFilter | undefined;
Expand Down Expand Up @@ -283,6 +286,7 @@ const usePreviewPublisher = (): PreviewPublisherContextType => {
return;
}
publisherRef.current.publishVideo(!isVideoEnabled);
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, isVideoEnabled ? 'true' : 'false');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, isVideoEnabled ? 'true' : 'false');
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, isVideoEnabled);

No need to add conversion, automatically done by setStorageItem.

setIsVideoEnabled(!isVideoEnabled);
if (setUser) {
setUser((prevUser: UserType) => ({
Expand All @@ -307,6 +311,7 @@ const usePreviewPublisher = (): PreviewPublisherContextType => {
}
publisherRef.current.publishAudio(!isAudioEnabled);
setIsAudioEnabled(!isAudioEnabled);
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, isAudioEnabled ? 'true' : 'false');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, isAudioEnabled ? 'true' : 'false');
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, isAudioEnabled);

No need to add conversion, automatically done by setStorageItem.

if (setUser) {
setUser((prevUser: UserType) => ({
...prevUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import usePublisherQuality, { NetworkQuality } from '../usePublisherQuality/useP
import usePublisherOptions from '../usePublisherOptions';
import useSessionContext from '../../../hooks/useSessionContext';
import applyBackgroundFilter from '../../../utils/backgroundFilter/applyBackgroundFilter/applyBackgroundFilter';
import { setStorageItem, STORAGE_KEYS } from '../../../utils/storage';

type PublisherStreamCreatedEvent = Event<'streamCreated', Publisher> & {
stream: Stream;
Expand Down Expand Up @@ -291,6 +292,7 @@ const usePublisher = (): PublisherContextType => {
}
publisherRef.current.publishVideo(!isVideoEnabled);
setIsVideoEnabled(!isVideoEnabled);
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, isVideoEnabled ? 'true' : 'false');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, isVideoEnabled ? 'true' : 'false');
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, isVideoEnabled);

No need to add conversion, automatically done by setStorageItem.

};

/**
Expand All @@ -305,6 +307,7 @@ const usePublisher = (): PublisherContextType => {
}
publisherRef.current.publishAudio(!isAudioEnabled);
setIsAudioEnabled(!isAudioEnabled);
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, isAudioEnabled ? 'true' : 'false');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, isAudioEnabled ? 'true' : 'false');
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, isAudioEnabled);

setIsForceMuted(false);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,18 @@ describe('usePublisherOptions', () => {
});
});
});

it('should disable audio and video from storage options', async () => {
vi.spyOn(OT, 'hasMediaProcessorSupport').mockReturnValue(true);
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, 'false');
setStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED, 'true');

await deviceStore.init();
mockUseUserContext.mockImplementation(() => mockUserContextWithCustomSettings);
const { result } = renderHook(() => usePublisherOptions());
await waitFor(() => {
expect(result.current?.publishAudio).toBe(false);
expect(result.current?.publishVideo).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useUserContext from '../../../hooks/useUserContext';
import getInitials from '../../../utils/getInitials';
import DeviceStore from '../../../utils/DeviceStore';
import useConfigContext from '../../../hooks/useConfigContext';
import { getStorageItem, STORAGE_KEYS } from '../../../utils/storage';

/**
* React hook to get PublisherProperties combining default options and options set in UserContext
Expand Down Expand Up @@ -51,14 +52,17 @@ const usePublisherOptions = (): PublisherProperties | null => {
const videoFilter: VideoFilter | undefined =
backgroundFilter && hasMediaProcessorSupport() ? backgroundFilter : undefined;

const isAudioDisabled = getStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED) === 'false';
const isVideoDisabled = getStorageItem(STORAGE_KEYS.VIDEO_SOURCE_ENABLED) === 'false';

setPublisherOptions({
audioFallback: { publisher: true },
audioSource,
initials,
insertDefaultUI: false,
name,
publishAudio: allowAudioOnJoin && publishAudio,
publishVideo: allowVideoOnJoin && publishVideo,
publishAudio: allowAudioOnJoin && publishAudio && !isAudioDisabled,
publishVideo: allowVideoOnJoin && publishVideo && !isVideoDisabled,
resolution: defaultResolution,
audioFilter,
videoFilter,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const STORAGE_KEYS = {
AUDIO_SOURCE: 'audioSource',
AUDIO_SOURCE_ENABLED: 'audioSourceEnabled',
VIDEO_SOURCE: 'videoSource',
VIDEO_SOURCE_ENABLED: 'videoSourceEnabled',
NOISE_SUPPRESSION: 'noiseSuppression',
BACKGROUND_REPLACEMENT: 'backgroundReplacement',
USERNAME: 'username',
Expand Down