瀏覽代碼

Fix multiple bugs on iOS

- receive multiple files
- display videos correctly
RobinLinus 6 年之前
父節點
當前提交
73c7430883
共有 2 個文件被更改,包括 9 次插入5 次删除
  1. 2 3
      client/scripts/network.js
  2. 7 2
      client/scripts/ui.js

+ 2 - 3
client/scripts/network.js

@@ -480,13 +480,12 @@ class FileDigester {
         this.progress = this._bytesReceived / this._size;
         if (this._bytesReceived < this._size) return;
         // we are done
-        let received = new Blob(this._buffer, { type: this._mime });
-        let url = URL.createObjectURL(received);
+        let blob = new Blob(this._buffer, { type: this._mime });
         this._callback({
             name: this._name,
             mime: this._mime,
             size: this._size,
-            url: url
+            blob: blob
         });
     }
 

+ 7 - 2
client/scripts/ui.js

@@ -230,7 +230,8 @@ class ReceiveDialog extends Dialog {
 
     _displayFile(file) {
         const $a = this.$el.querySelector('#download');
-        $a.href = file.url;
+        const url = URL.createObjectURL(file.blob);
+        $a.href = url;
         $a.download = file.name;
 
         this.$el.querySelector('#fileName').textContent = file.name;
@@ -238,7 +239,11 @@ class ReceiveDialog extends Dialog {
         this.show();
 
         if (window.isDownloadSupported) return;
-        // $a.target = "_blank"; // fallback
+        // fallback for iOS
+        $a.target = '_blank';
+        const reader = new FileReader();
+        reader.onload = e => $a.href = reader.result;
+        reader.readAsDataURL(file.blob);
     }
 
     _formatFileSize(bytes) {