Skip to content

Commit bd93e61

Browse files
Assume camera faces requested facingMode and mirror accordingly; report mirroring and camera name in onLoad callback
1 parent 3e49a92 commit bd93e61

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class Test extends Component {
6161

6262
### Events
6363

64-
| Prop | Argument | Description |
65-
| ----------- | ---------------- | ----------------------------------------------------------------------------------------------- |
66-
| onScan | `result` | Scan event handler. Called every scan with the decoded value or `null` if no QR code was found. |
67-
| onError | `Error` | Called when an error occurs. |
68-
| onLoad | none | Called when the component is ready for use. |
69-
| onImageLoad | img onLoad event | Called when the image in legacyMode is loaded. |
64+
| Prop | Argument | Description |
65+
| ----------- | ---------------- | --------------------------------------------------------------------------------------------------------------- |
66+
| onScan | `result` | Scan event handler. Called every scan with the decoded value or `null` if no QR code was found. |
67+
| onError | `Error` | Called when an error occurs. |
68+
| onLoad | `object` | Called when the component is ready for use. Object properties are `mirrorVideo`: boolean, `streamLabel`: string |
69+
| onImageLoad | img onLoad event | Called when the image in legacyMode is loaded. |
7070

7171
### Options
7272

lib/index.js

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ module.exports = class Reader extends Component {
164164
}
165165
handleVideo(stream) {
166166
const { preview } = this.els
167+
const { facingMode } = this.props
167168

168169
// Preview element hasn't been rendered so wait for it.
169170
if (!preview) {
@@ -192,17 +193,16 @@ module.exports = class Reader extends Component {
192193

193194
preview.addEventListener('loadstart', this.handleLoadStart)
194195

195-
const facingUserPattern = getFacingModePattern('user')
196-
const isUserFacing = facingUserPattern.test(streamTrack.label)
197-
this.setState({ mirrorVideo: isUserFacing })
196+
this.setState({ mirrorVideo: facingMode == 'user', streamLabel: streamTrack.label })
198197
}
199198
handleLoadStart() {
200199
const { delay, onLoad } = this.props
200+
const { mirrorVideo, streamLabel } = this.state
201201
const preview = this.els.preview
202202
preview.play()
203203

204204
if(typeof onLoad == 'function') {
205-
onLoad()
205+
onLoad({ mirrorVideo, streamLabel })
206206
}
207207

208208
if (typeof delay == 'number') {

0 commit comments

Comments
 (0)