|
@@ -16,7 +16,7 @@ function getMediaDevices () {
|
|
return navigator.mediaDevices
|
|
return navigator.mediaDevices
|
|
}
|
|
}
|
|
|
|
|
|
- let getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia
|
|
|
|
|
|
+ const getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia
|
|
if (!getUserMedia) {
|
|
if (!getUserMedia) {
|
|
return null
|
|
return null
|
|
}
|
|
}
|
|
@@ -94,25 +94,34 @@ module.exports = class Webcam extends Plugin {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- start () {
|
|
|
|
- if (!this.mediaDevices) {
|
|
|
|
- return Promise.reject(new Error('Webcam access not supported'))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.webcamActive = true
|
|
|
|
|
|
+ isSupported () {
|
|
|
|
+ return !!this.mediaDevices
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ getConstraints () {
|
|
const acceptsAudio = this.opts.modes.indexOf('video-audio') !== -1 ||
|
|
const acceptsAudio = this.opts.modes.indexOf('video-audio') !== -1 ||
|
|
this.opts.modes.indexOf('audio-only') !== -1
|
|
this.opts.modes.indexOf('audio-only') !== -1
|
|
const acceptsVideo = this.opts.modes.indexOf('video-audio') !== -1 ||
|
|
const acceptsVideo = this.opts.modes.indexOf('video-audio') !== -1 ||
|
|
this.opts.modes.indexOf('video-only') !== -1 ||
|
|
this.opts.modes.indexOf('video-only') !== -1 ||
|
|
this.opts.modes.indexOf('picture') !== -1
|
|
this.opts.modes.indexOf('picture') !== -1
|
|
|
|
|
|
|
|
+ return {
|
|
|
|
+ audio: acceptsAudio,
|
|
|
|
+ video: acceptsVideo
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ start () {
|
|
|
|
+ if (!this.isSupported()) {
|
|
|
|
+ return Promise.reject(new Error('Webcam access not supported'))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.webcamActive = true
|
|
|
|
+
|
|
|
|
+ const constraints = this.getConstraints()
|
|
|
|
+
|
|
// ask user for access to their camera
|
|
// ask user for access to their camera
|
|
- return this.mediaDevices
|
|
|
|
- .getUserMedia({
|
|
|
|
- audio: acceptsAudio,
|
|
|
|
- video: acceptsVideo
|
|
|
|
- })
|
|
|
|
|
|
+ return this.mediaDevices.getUserMedia(constraints)
|
|
.then((stream) => {
|
|
.then((stream) => {
|
|
this.stream = stream
|
|
this.stream = stream
|
|
this.streamSrc = URL.createObjectURL(this.stream)
|
|
this.streamSrc = URL.createObjectURL(this.stream)
|