@@ -35,7 +35,6 @@ const Video = props => {
35
35
const [ devices , setDevices ] = useState ( [ ] )
36
36
const [ cameras , setCameras ] = useState ( [ ] )
37
37
const [ videoMode , setVideoMode ] = useState ( { } )
38
- const isMobile = window . innerWidth <= 768
39
38
40
39
const getDevices = useCallback ( async ( ) => {
41
40
if ( ! devices . length ) {
@@ -78,7 +77,17 @@ const Video = props => {
78
77
} , [ devices , setCapture , setError , stream ] )
79
78
80
79
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' ) {
82
91
const userStream = await navigator . mediaDevices . getUserMedia ( {
83
92
video : { facingMode : 'user' } ,
84
93
} )
@@ -137,7 +146,7 @@ const Video = props => {
137
146
138
147
return (
139
148
< >
140
- { cameras . length > 1 && isMobile && (
149
+ { ! ( devices . length <= 1 ) && (
141
150
< Button icon = "switch_camera" message = { m . switchCamera } onClick = { switchStream } />
142
151
) }
143
152
{ devices . length && stream ? (
0 commit comments