File tree Expand file tree Collapse file tree 5 files changed +30
-2
lines changed
PreviewPublisherProvider/usePreviewPublisher Expand file tree Collapse file tree 5 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,9 @@ const usePreviewPublisher = (): PreviewPublisherContextType => {
228228 if ( publisherRef . current ) {
229229 return ;
230230 }
231+ // We reset user preferences as we want to start with both devices enabled
232+ setStorageItem ( STORAGE_KEYS . AUDIO_SOURCE_ENABLED , 'true' ) ;
233+ setStorageItem ( STORAGE_KEYS . VIDEO_SOURCE_ENABLED , 'true' ) ;
231234
232235 // Set videoFilter based on user's selected background
233236 let videoFilter : VideoFilter | undefined ;
@@ -282,6 +285,7 @@ const usePreviewPublisher = (): PreviewPublisherContextType => {
282285 return ;
283286 }
284287 publisherRef . current . publishVideo ( ! isVideoEnabled ) ;
288+ setStorageItem ( STORAGE_KEYS . VIDEO_SOURCE_ENABLED , ( ! isVideoEnabled ) . toString ( ) ) ;
285289 setIsVideoEnabled ( ! isVideoEnabled ) ;
286290 if ( setUser ) {
287291 setUser ( ( prevUser : UserType ) => ( {
@@ -306,6 +310,7 @@ const usePreviewPublisher = (): PreviewPublisherContextType => {
306310 }
307311 publisherRef . current . publishAudio ( ! isAudioEnabled ) ;
308312 setIsAudioEnabled ( ! isAudioEnabled ) ;
313+ setStorageItem ( STORAGE_KEYS . AUDIO_SOURCE_ENABLED , ( ! isAudioEnabled ) . toString ( ) ) ;
309314 if ( setUser ) {
310315 setUser ( ( prevUser : UserType ) => ( {
311316 ...prevUser ,
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import OT, {
88 PublisherProperties ,
99} from '@vonage/client-sdk-video' ;
1010import { useTranslation } from 'react-i18next' ;
11+ import { setStorageItem , STORAGE_KEYS } from '@utils/storage' ;
1112import usePublisherQuality , { NetworkQuality } from '../usePublisherQuality/usePublisherQuality' ;
1213import usePublisherOptions from '../usePublisherOptions' ;
1314import useSessionContext from '../../../hooks/useSessionContext' ;
@@ -291,6 +292,7 @@ const usePublisher = (): PublisherContextType => {
291292 }
292293 publisherRef . current . publishVideo ( ! isVideoEnabled ) ;
293294 setIsVideoEnabled ( ! isVideoEnabled ) ;
295+ setStorageItem ( STORAGE_KEYS . VIDEO_SOURCE_ENABLED , ( ! isVideoEnabled ) . toString ( ) ) ;
294296 } ;
295297
296298 /**
@@ -305,6 +307,7 @@ const usePublisher = (): PublisherContextType => {
305307 }
306308 publisherRef . current . publishAudio ( ! isAudioEnabled ) ;
307309 setIsAudioEnabled ( ! isAudioEnabled ) ;
310+ setStorageItem ( STORAGE_KEYS . AUDIO_SOURCE_ENABLED , ( ! isAudioEnabled ) . toString ( ) ) ;
308311 setIsForceMuted ( false ) ;
309312 } ;
310313
Original file line number Diff line number Diff line change @@ -191,6 +191,20 @@ describe('usePublisherOptions', () => {
191191 } ) ;
192192 } ) ;
193193 } ) ;
194+
195+ it ( 'should disable audio and video from storage options' , async ( ) => {
196+ vi . spyOn ( OT , 'hasMediaProcessorSupport' ) . mockReturnValue ( true ) ;
197+ setStorageItem ( STORAGE_KEYS . AUDIO_SOURCE_ENABLED , 'false' ) ;
198+ setStorageItem ( STORAGE_KEYS . VIDEO_SOURCE_ENABLED , 'true' ) ;
199+
200+ await deviceStore . init ( ) ;
201+ vi . mocked ( useUserContext ) . mockImplementation ( ( ) => mockUserContextWithCustomSettings ) ;
202+ const { result } = renderHook ( ( ) => usePublisherOptions ( ) ) ;
203+ await waitFor ( ( ) => {
204+ expect ( result . current ?. publishAudio ) . toBe ( false ) ;
205+ expect ( result . current ?. publishVideo ) . toBe ( true ) ;
206+ } ) ;
207+ } ) ;
194208} ) ;
195209
196210function renderHook < Result , Props > (
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import useAppConfig from '@Context/AppConfig/hooks/useAppConfig';
99import useUserContext from '@hooks/useUserContext' ;
1010import getInitials from '@utils/getInitials' ;
1111import DeviceStore from '@utils/DeviceStore' ;
12+ import { getStorageItem , STORAGE_KEYS } from '@utils/storage' ;
1213
1314/**
1415 * React hook to get PublisherProperties combining default options and options set in UserContext
@@ -53,14 +54,17 @@ const usePublisherOptions = (): PublisherProperties | null => {
5354 const videoFilter : VideoFilter | undefined =
5455 backgroundFilter && hasMediaProcessorSupport ( ) ? backgroundFilter : undefined ;
5556
57+ const isAudioDisabled = getStorageItem ( STORAGE_KEYS . AUDIO_SOURCE_ENABLED ) === 'false' ;
58+ const isVideoDisabled = getStorageItem ( STORAGE_KEYS . VIDEO_SOURCE_ENABLED ) === 'false' ;
59+
5660 setPublisherOptions ( {
5761 audioFallback : { publisher : true } ,
5862 audioSource,
5963 initials,
6064 insertDefaultUI : false ,
6165 name,
62- publishAudio : allowAudioOnJoin && publishAudio ,
63- publishVideo : allowVideoOnJoin && publishVideo ,
66+ publishAudio : allowAudioOnJoin && publishAudio && ! isAudioDisabled ,
67+ publishVideo : allowVideoOnJoin && publishVideo && ! isVideoDisabled ,
6468 resolution : defaultResolution ,
6569 audioFilter,
6670 videoFilter,
Original file line number Diff line number Diff line change 11export const STORAGE_KEYS = {
22 AUDIO_SOURCE : 'audioSource' ,
3+ AUDIO_SOURCE_ENABLED : 'audioSourceEnabled' ,
34 VIDEO_SOURCE : 'videoSource' ,
5+ VIDEO_SOURCE_ENABLED : 'videoSourceEnabled' ,
46 NOISE_SUPPRESSION : 'noiseSuppression' ,
57 BACKGROUND_REPLACEMENT : 'backgroundReplacement' ,
68 USERNAME : 'username' ,
You can’t perform that action at this time.
0 commit comments