@@ -76,7 +76,30 @@ const tests = [
76
76
ratio : '4:3' ,
77
77
} ] ;
78
78
79
- const { getUserMedia } = navigator . mediaDevices || navigator . mozGetUserMedia ;
79
+ function getUserMedia ( constraints ) {
80
+ if ( navigator . mediaDevices && navigator . mediaDevices . getUserMedia ) {
81
+ return navigator . mediaDevices . getUserMedia ( constraints ) ;
82
+ }
83
+
84
+ // Some browsers partially implement mediaDevices. We can't just assign an object
85
+ // with getUserMedia as it would overwrite existing properties.
86
+ // Here, we will just add the getUserMedia property if it's missing.
87
+
88
+ // First get hold of the legacy getUserMedia, if present
89
+ const get = navigator . getUserMedia
90
+ || navigator . webkitGetUserMedia
91
+ || navigator . mozGetUserMedia
92
+ || ( ( ) => {
93
+ const error = new Error ( 'Permission unimplemented' ) ;
94
+ error . code = 0 ;
95
+ error . name = 'NotAllowedError' ;
96
+ throw error ;
97
+ } ) ;
98
+
99
+ return new Promise ( ( resolve , reject ) => {
100
+ get . call ( navigator , constraints , resolve , reject ) ;
101
+ } ) ;
102
+ }
80
103
81
104
const Camera = ( { children, containerStyle, onCameraReady, title } , ref ) => {
82
105
const windowDimensions = useWindowDimensions ( ) ;
@@ -85,7 +108,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
85
108
const [ candidate , setCandidate ] = useState ( ) ;
86
109
const [ loading , setLoading ] = useState ( false ) ;
87
110
88
- const { width : videoWith , height : videoHeight } = useMemo ( ( ) => {
111
+ const { width : videoWidth , height : videoHeight } = useMemo ( ( ) => {
89
112
if ( ! candidate ) { return { width : 0 , height : 0 } ; }
90
113
return getSize ( candidate . test . ratio , windowDimensions , 'number' ) ;
91
114
} , [ candidate , windowDimensions ] ) ;
@@ -163,7 +186,9 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
163
186
. drawImage ( videoEl . current , 0 , 0 , canvasEl . current . width , canvasEl . current . height ) ;
164
187
165
188
const imageType = utils . getOS ( ) === 'ios' ? 'image/png' : 'image/webp' ;
166
- return { uri : canvasEl . current . toDataURL ( imageType ) } ;
189
+ const uri = canvasEl . current . toDataURL ( imageType ) ;
190
+
191
+ return { uri } ;
167
192
} ,
168
193
async resumePreview ( ) {
169
194
if ( videoEl . current ) {
@@ -194,15 +219,16 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
194
219
195
220
if ( 'srcObject' in video ) {
196
221
video . srcObject = bestCandidate . stream ;
222
+ video . play ( ) ;
197
223
} else {
198
224
video . src = window . URL . createObjectURL ( bestCandidate . stream ) ;
199
225
}
200
226
201
- video . onloadedmetadata = ( ) => { video . play ( ) ; } ;
202
-
203
227
canvas . width = bestCandidate . test . width ;
204
228
canvas . height = bestCandidate . test . height ;
205
229
230
+ video . onloadedmetadata = ( ) => { video . play ( ) ; } ;
231
+
206
232
setLoading ( false ) ;
207
233
onCameraReady ( ) ;
208
234
}
@@ -211,6 +237,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
211
237
212
238
return (
213
239
< View
240
+ pointerEvents = "box-none"
214
241
accessibilityLabel = "Camera container"
215
242
style = { [ styles . container , containerStyle ] }
216
243
>
@@ -219,7 +246,7 @@ const Camera = ({ children, containerStyle, onCameraReady, title }, ref) => {
219
246
autoPlay
220
247
playsInline
221
248
ref = { videoEl }
222
- width = { videoWith }
249
+ width = { videoWidth }
223
250
height = { videoHeight }
224
251
/>
225
252
< canvas ref = { canvasEl } />
0 commit comments