Ver Fonte

if no countdown, show “smile” right away, fixes on @goto-bus-stop comments

Artur Paikin há 7 anos atrás
pai
commit
34ea05f97d
2 ficheiros alterados com 40 adições e 33 exclusões
  1. 1 1
      examples/bundled-example/main.js
  2. 39 32
      src/plugins/Webcam/index.js

+ 1 - 1
examples/bundled-example/main.js

@@ -72,7 +72,7 @@ const uppy = Uppy({
   // .use(ProgressBar, {target: 'body'})
   .use(Webcam, {
     target: Dashboard,
-    countdown: 5,
+    // countdown: 5,
     locale: {
       strings: { smile: 'Улыбочку!' }
     }

+ 39 - 32
src/plugins/Webcam/index.js

@@ -83,18 +83,32 @@ module.exports = class Webcam extends Plugin {
     this.startRecording = this.startRecording.bind(this)
     this.stopRecording = this.stopRecording.bind(this)
     this.oneTwoThreeSmile = this.oneTwoThreeSmile.bind(this)
-    this.justSmile = this.justSmile.bind(this)
+    // this.justSmile = this.justSmile.bind(this)
 
     this.webcam = new WebcamProvider(this.opts, this.params)
     this.webcamActive = false
 
-    if (typeof opts.onBeforeSnapshot === 'undefined' || !this.opts.onBeforeSnapshot) {
-      if (this.opts.countdown) {
-        this.opts.onBeforeSnapshot = this.oneTwoThreeSmile
-      } else {
-        this.opts.onBeforeSnapshot = this.justSmile
-      }
+    if (this.opts.countdown) {
+      this.opts.onBeforeSnapshot = this.oneTwoThreeSmile
     }
+
+    // if (typeof opts.onBeforeSnapshot === 'undefined' || !this.opts.onBeforeSnapshot) {
+    //   if (this.opts.countdown) {
+    //     this.opts.onBeforeSnapshot = this.oneTwoThreeSmile
+    //   } else {
+    //     this.opts.onBeforeSnapshot = this.justSmile
+    //   }
+    // }
+  }
+
+  /**
+   * Little shorthand to update the state with my new state
+   */
+  updateState (newState) {
+    const {state} = this.core
+    const webcam = Object.assign({}, state.webcam, newState)
+
+    this.core.setState({webcam})
   }
 
   start () {
@@ -186,7 +200,7 @@ module.exports = class Webcam extends Plugin {
         if (!this.webcamActive) {
           clearInterval(countDown)
           this.captureInProgress = false
-          return Promise.reject('Webcam is not active')
+          return reject('Webcam is not active')
         }
 
         if (count > 0) {
@@ -201,12 +215,12 @@ module.exports = class Webcam extends Plugin {
     })
   }
 
-  justSmile () {
-    return new Promise((resolve, reject) => {
-      setTimeout(() => this.core.emit('informer', this.i18n('smile'), 'success', 1000), 1500)
-      setTimeout(() => resolve(), 2000)
-    })
-  }
+  // justSmile () {
+  //   return new Promise((resolve, reject) => {
+  //     setTimeout(() => this.core.emit('informer', this.i18n('smile'), 'success', 1000), 1500)
+  //     setTimeout(() => resolve(), 2000)
+  //   })
+  // }
 
   takeSnapshot () {
     const opts = {
@@ -224,7 +238,10 @@ module.exports = class Webcam extends Plugin {
       return Promise.reject(`onBeforeSnapshot: ${err}`)
     }).then(() => {
       const video = this.target.querySelector('.UppyWebcam-video')
-      if (!video) return Promise.reject('No video element found, likely due to the Webcam tab being closed.')
+      if (!video) {
+        this.captureInProgress = false
+        return Promise.reject('No video element found, likely due to the Webcam tab being closed.')
+      }
 
       const image = this.webcam.getImage(video, opts)
 
@@ -240,6 +257,13 @@ module.exports = class Webcam extends Plugin {
     })
   }
 
+  focus () {
+    if (this.opts.countdown) return
+    setTimeout(() => {
+      this.core.emit('informer', this.i18n('smile'), 'success', 1500)
+    }, 1000)
+  }
+
   render (state) {
     if (!this.webcamActive) {
       this.start()
@@ -267,13 +291,6 @@ module.exports = class Webcam extends Plugin {
     }))
   }
 
-  focus () {
-    // if (this.opts.oneTwoThreeSmile) return
-    // setTimeout(() => {
-    //   this.core.emitter.emit('informer', 'Smile!', 'success', 2000)
-    // }, 1000)
-  }
-
   install () {
     this.webcam.init()
     this.core.setState({
@@ -291,14 +308,4 @@ module.exports = class Webcam extends Plugin {
     this.webcam.reset()
     this.unmount()
   }
-
-  /**
-   * Little shorthand to update the state with my new state
-   */
-  updateState (newState) {
-    const {state} = this.core
-    const webcam = Object.assign({}, state.webcam, newState)
-
-    this.core.setState({webcam})
-  }
 }