javascript - Websocket progress pauses when switching tabs on browser (client) -


i face quite extraordinary side effect never faced before. let me describe thoroughly:

client (browser) has input tag, files being chosen. on clicking specific button, action emits, files being transmitted server websockets (by library socket.io).

// starts upload after clicking on upload button. async upload() {     if (this.state.filelist.length === 0) { return; }      // dispatch start uploading action.     this.props.startup();      // map original files state's file list.     let originfiles = _.map(this.state.filelist, (file: any) => {         return file.originfileobj;     });      // send files on socket streams server.     await apiservice.upload(originfiles, () => {         // update state whenever file has been uploaded.         this.setstate({ ...this.state, finishedfiles: this.state.finishedfiles + 1 })     });      this.clearitemlist();     // dispatch end uploading action.     this.props.endup(); } 

this function called whenever button clicked. can see, there api service, gets called on filelist, , streams files server. files streamed through sockets.

import * io 'socket.io-client'; import * ios 'socket.io-stream';  export function upload(data: any[], onupload?: () => void): promise<any> {     return new promise((res, rej) => {         const = io.connect("ws://localhost:8000/");         // right after connect.         up.on('connect', () => {             // connect upload socket point.             up.emit('upload', {});             // whenever receive 'ok' status, send files on wire.             up.on('ok', async () => {                 // if sent files, notify server end.                 if (data.length === 0) {                     up.emit('end', {});                     up.disconnect();                     // resolve promise.                     res();                 // otherwise, emit 'data' action, sends files.                 } else {                     let blob = data.pop();                     let stream = ios.createstream();                     ios(up).emit('data', stream, { size: blob.size });                     ios.createblobreadstream(blob, { highwatermark: 500000 }).pipe(stream);                     // callback onupload event.                     onupload();                 }             });             up.on('error', () => {                 rej();             });         });     }); } 

everything works well, until switch tabs on client (browser) , progress gets paused. after switch client tab, progress automatically resumes.

my colleague presumed, might problem browser itself, stops files piped whenever lose focus of tab.

any ideas on how solve problem and/or tweak code bit appreciated.

thank you.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -