Browse Source

merge oliverpool-online-autoretry

Artur Paikin 8 years ago
parent
commit
6fb263b2bc
2 changed files with 21 additions and 2 deletions
  1. 2 1
      src/core/Core.js
  2. 19 1
      src/plugins/Tus10.js

+ 2 - 1
src/core/Core.js

@@ -393,7 +393,8 @@ class Uppy {
     } else {
       this.emit('is-online')
       if (this.wasOffline) {
-        this.emit('informer', 'Connected', 'success', 3000)
+        this.emit('back-online')
+        this.emit('informer', 'Connected!', 'success', 3000)
         this.wasOffline = false
       }
     }

+ 19 - 1
src/plugins/Tus10.js

@@ -36,7 +36,8 @@ module.exports = class Tus10 extends Plugin {
     // set default options
     const defaultOptions = {
       resume: true,
-      allowPause: true
+      allowPause: true,
+      autoRetry: true
     }
 
     // merge default options with the ones set by user
@@ -169,6 +170,17 @@ module.exports = class Tus10 extends Plugin {
         upload.start()
       })
 
+      this.core.on('core:retry-started', () => {
+        const files = this.core.getState().files
+        if (files[file.id].progress.uploadComplete ||
+          !files[file.id].progress.uploadStarted ||
+          files[file.id].isPaused
+            ) {
+          return
+        }
+        upload.start()
+      })
+
       upload.start()
       this.core.emitter.emit('core:upload-started', file.id, upload)
     })
@@ -341,6 +353,12 @@ module.exports = class Tus10 extends Plugin {
   actions () {
     this.core.emitter.on('core:pause-all', this.handlePauseAll)
     this.core.emitter.on('core:resume-all', this.handleResumeAll)
+
+    if (this.opts.autoRetry) {
+      this.core.emitter.on('back-online', () => {
+        this.core.emitter.emit('core:retry-started')
+      })
+    }
   }
 
   addResumableUploadsCapabilityFlag () {