Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Undefined MediaDevices error on HTTP (#26396)
- Loading branch information
1 parent
0d7a720
commit fec3a1a
Showing
12 changed files
with
149 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { DeviceContext, Device } from '../DeviceContext'; | ||
import { DeviceContext, Device, isDeviceContextEnabled } from '../DeviceContext'; | ||
|
||
type AvailableDevices = { | ||
audioInput?: Device[]; | ||
audioOutput?: Device[]; | ||
}; | ||
|
||
export const useAvailableDevices = (): AvailableDevices => ({ | ||
audioInput: useContext(DeviceContext).availableAudioInputDevices, | ||
audioOutput: useContext(DeviceContext).availableAudioOutputDevices, | ||
}); | ||
export const useAvailableDevices = (): AvailableDevices | null => { | ||
const context = useContext(DeviceContext); | ||
|
||
if (!isDeviceContextEnabled(context)) { | ||
console.warn( | ||
'Device Management is disabled on unsecure contexts, see https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts/features_restricted_to_secure_contexts', | ||
); | ||
return null; | ||
} | ||
|
||
return { | ||
audioInput: context.availableAudioInputDevices, | ||
audioOutput: context.availableAudioOutputDevices, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { DeviceContext } from '../DeviceContext'; | ||
import { DeviceContext, isDeviceContextEnabled } from '../DeviceContext'; | ||
|
||
export const useDeviceConstraints = (): MediaStreamConstraints => { | ||
const selectedAudioInputDeviceId = useContext(DeviceContext).selectedAudioInputDevice?.id; | ||
export const useDeviceConstraints = (): MediaStreamConstraints | null => { | ||
const context = useContext(DeviceContext); | ||
|
||
if (!isDeviceContextEnabled(context)) { | ||
console.warn( | ||
'Device Management is disabled on unsecure contexts, see https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts/features_restricted_to_secure_contexts', | ||
); | ||
return null; | ||
} | ||
|
||
const selectedAudioInputDeviceId = context.selectedAudioInputDevice?.id; | ||
return { audio: selectedAudioInputDeviceId === 'default' ? true : { deviceId: { exact: selectedAudioInputDeviceId } } }; | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/ui-contexts/src/hooks/useIsDeviceManagementEnabled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { DeviceContext } from '../DeviceContext'; | ||
|
||
export const useIsDeviceManagementEnabled = (): boolean => useContext(DeviceContext).enabled; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { DeviceContext, Device } from '../DeviceContext'; | ||
import { DeviceContext, Device, isDeviceContextEnabled } from '../DeviceContext'; | ||
|
||
type SelectedDevices = { | ||
audioInput?: Device; | ||
audioOutput?: Device; | ||
}; | ||
|
||
export const useSelectedDevices = (): SelectedDevices => ({ | ||
audioInput: useContext(DeviceContext).selectedAudioInputDevice, | ||
audioOutput: useContext(DeviceContext).selectedAudioOutputDevice, | ||
}); | ||
export const useSelectedDevices = (): SelectedDevices | null => { | ||
const context = useContext(DeviceContext); | ||
|
||
if (!isDeviceContextEnabled(context)) { | ||
console.warn( | ||
'Device Management is disabled on unsecure contexts, see https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts/features_restricted_to_secure_contexts', | ||
); | ||
return null; | ||
} | ||
|
||
return { | ||
audioInput: context.selectedAudioInputDevice, | ||
audioOutput: context.selectedAudioOutputDevice, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { DeviceContext, Device } from '../DeviceContext'; | ||
import { DeviceContext, Device, isDeviceContextEnabled } from '../DeviceContext'; | ||
|
||
type setInputMediaDevice = (inputDevice: Device) => void; | ||
|
||
export const useSetInputMediaDevice = (): setInputMediaDevice => { | ||
return useContext(DeviceContext).setAudioInputDevice; | ||
const context = useContext(DeviceContext); | ||
|
||
if (!isDeviceContextEnabled(context)) { | ||
console.warn( | ||
'Device Management is disabled on unsecure contexts, see https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts/features_restricted_to_secure_contexts', | ||
); | ||
return () => undefined; | ||
} | ||
return context.setAudioInputDevice; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters