Skip to content

Commit e286a44

Browse files
committed
console: Fix camera switch for safari
1 parent 73ffae9 commit e286a44

File tree

1 file changed

+12
-3
lines changed
  • pkg/webui/components/qr/input/video

1 file changed

+12
-3
lines changed

pkg/webui/components/qr/input/video/index.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const Video = props => {
3535
const [devices, setDevices] = useState([])
3636
const [cameras, setCameras] = useState([])
3737
const [videoMode, setVideoMode] = useState({})
38-
const isMobile = window.innerWidth <= 768
3938

4039
const getDevices = useCallback(async () => {
4140
if (!devices.length) {
@@ -78,7 +77,17 @@ const Video = props => {
7877
}, [devices, setCapture, setError, stream])
7978

8079
const switchStream = useCallback(async () => {
81-
if (videoMode.facingMode === 'environment') {
80+
const ua = navigator.userAgent.toLowerCase()
81+
if (ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1) {
82+
const userStream = await navigator.mediaDevices.getUserMedia({
83+
video: {
84+
facingMode: {
85+
exact: videoMode.facingMode.exact === 'environment' ? 'user' : 'environment',
86+
},
87+
},
88+
})
89+
setStream(userStream)
90+
} else if (videoMode.facingMode === 'environment') {
8291
const userStream = await navigator.mediaDevices.getUserMedia({
8392
video: { facingMode: 'user' },
8493
})
@@ -137,7 +146,7 @@ const Video = props => {
137146

138147
return (
139148
<>
140-
{cameras.length > 1 && isMobile && (
149+
{!(devices.length <= 1) && (
141150
<Button icon="switch_camera" message={m.switchCamera} onClick={switchStream} />
142151
)}
143152
{devices.length && stream ? (

0 commit comments

Comments
 (0)