@@ -90,38 +90,42 @@ function IOURequestStepScan({
90
90
return ;
91
91
}
92
92
93
- navigator . mediaDevices . getUserMedia ( { video : { facingMode : { exact : 'environment' } , zoom : { ideal : 1 } } } ) . then ( ( stream ) => {
94
- _ . forEach ( stream . getTracks ( ) , ( track ) => track . stop ( ) ) ;
95
- // Only Safari 17+ supports zoom constraint
96
- if ( Browser . isMobileSafari ( ) && stream . getTracks ( ) . length > 0 ) {
97
- const deviceId = _ . chain ( stream . getTracks ( ) )
98
- . map ( ( track ) => track . getSettings ( ) )
99
- . find ( ( setting ) => setting . zoom === 1 )
100
- . get ( 'deviceId' )
101
- . value ( ) ;
102
- if ( deviceId ) {
103
- setVideoConstraints ( { deviceId} ) ;
104
- return ;
93
+ const defaultConstraints = { facingMode : { exact : 'environment' } } ;
94
+ navigator . mediaDevices
95
+ . getUserMedia ( { video : { facingMode : { exact : 'environment' } , zoom : { ideal : 1 } } } )
96
+ . then ( ( stream ) => {
97
+ _ . forEach ( stream . getTracks ( ) , ( track ) => track . stop ( ) ) ;
98
+ // Only Safari 17+ supports zoom constraint
99
+ if ( Browser . isMobileSafari ( ) && stream . getTracks ( ) . length > 0 ) {
100
+ const deviceId = _ . chain ( stream . getTracks ( ) )
101
+ . map ( ( track ) => track . getSettings ( ) )
102
+ . find ( ( setting ) => setting . zoom === 1 )
103
+ . get ( 'deviceId' )
104
+ . value ( ) ;
105
+ if ( deviceId ) {
106
+ setVideoConstraints ( { deviceId} ) ;
107
+ return ;
108
+ }
105
109
}
106
- }
107
- if ( ! navigator . mediaDevices . enumerateDevices ) {
108
- setVideoConstraints ( { facingMode : { exact : 'environment' } } ) ;
109
- return ;
110
- }
111
- navigator . mediaDevices . enumerateDevices ( ) . then ( ( devices ) => {
112
- const lastBackDeviceId = _ . chain ( devices )
113
- . filter ( ( item ) => item . kind === 'videoinput' )
114
- . last ( )
115
- . get ( 'deviceId' , '' )
116
- . value ( ) ;
117
-
118
- if ( ! lastBackDeviceId ) {
119
- setVideoConstraints ( { facingMode : { exact : 'environment' } } ) ;
110
+ if ( ! navigator . mediaDevices . enumerateDevices ) {
111
+ setVideoConstraints ( defaultConstraints ) ;
120
112
return ;
121
113
}
122
- setVideoConstraints ( { deviceId : lastBackDeviceId } ) ;
123
- } ) ;
124
- } ) ;
114
+ navigator . mediaDevices . enumerateDevices ( ) . then ( ( devices ) => {
115
+ const lastBackDeviceId = _ . chain ( devices )
116
+ . filter ( ( item ) => item . kind === 'videoinput' )
117
+ . last ( )
118
+ . get ( 'deviceId' , '' )
119
+ . value ( ) ;
120
+
121
+ if ( ! lastBackDeviceId ) {
122
+ setVideoConstraints ( defaultConstraints ) ;
123
+ return ;
124
+ }
125
+ setVideoConstraints ( { deviceId : lastBackDeviceId } ) ;
126
+ } ) ;
127
+ } )
128
+ . catch ( ( ) => setVideoConstraints ( defaultConstraints ) ) ;
125
129
// eslint-disable-next-line react-hooks/exhaustive-deps
126
130
} , [ isTabActive ] ) ;
127
131
0 commit comments