| 226 | } |
| 227 | |
| 228 | class ReceiveDialog extends Dialog { |
| 229 | |
| 230 | constructor() { |
| 231 | super('receiveDialog'); |
| 232 | Events.on('file-received', e => { |
| 233 | this._nextFile(e.detail); |
| 234 | window.blop.play(); |
| 235 | }); |
| 236 | this._filesQueue = []; |
| 237 | } |
| 238 | |
| 239 | _nextFile(nextFile) { |
| 240 | if (nextFile) this._filesQueue.push(nextFile); |
| 241 | if (this._busy) return; |
| 242 | this._busy = true; |
| 243 | const file = this._filesQueue.shift(); |
| 244 | this._displayFile(file); |
| 245 | } |
| 246 | |
| 247 | _dequeueFile() { |
| 248 | if (!this._filesQueue.length) { // nothing to do |
| 249 | this._busy = false; |
| 250 | return; |
| 251 | } |
| 252 | // dequeue next file |
| 253 | setTimeout(_ => { |
| 254 | this._busy = false; |
| 255 | this._nextFile(); |
| 256 | }, 300); |
| 257 | } |
| 258 | |
| 259 | _displayFile(file) { |
| 260 | const $a = this.$el.querySelector('#download'); |
| 261 | const url = URL.createObjectURL(file.blob); |
| 262 | $a.href = url; |
| 263 | $a.download = file.name; |
| 264 | |
| 265 | if(this._autoDownload()){ |
| 266 | $a.click() |
| 267 | return |
| 268 | } |
| 269 | if(file.mime.split('/')[0] === 'image'){ |
| 270 | console.log('the file is image'); |
| 271 | this.$el.querySelector('.preview').style.visibility = 'inherit'; |
| 272 | this.$el.querySelector("#img-preview").src = url; |
| 273 | } |
| 274 | |
| 275 | this.$el.querySelector('#fileName').textContent = file.name; |
| 276 | this.$el.querySelector('#fileSize').textContent = this._formatFileSize(file.size); |
| 277 | this.show(); |
| 278 | |
| 279 | if (window.isDownloadSupported) return; |
| 280 | // fallback for iOS |
| 281 | $a.target = '_blank'; |
| 282 | const reader = new FileReader(); |
| 283 | reader.onload = e => $a.href = reader.result; |
| 284 | reader.readAsDataURL(file.blob); |
| 285 | } |
nothing calls this directly
no outgoing calls
no test coverage detected