@vidispine/vdt-api 23.1.0 → 23.2.0-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +11 -8
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
package/dist/index.es.js
CHANGED
|
@@ -5,11 +5,12 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
5
5
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
6
|
import { Buffer } from 'buffer';
|
|
7
7
|
import axios from 'axios';
|
|
8
|
+
import axiosRetry from 'axios-retry';
|
|
8
9
|
import _typeof from '@babel/runtime/helpers/typeof';
|
|
9
10
|
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
10
11
|
import _createClass from '@babel/runtime/helpers/createClass';
|
|
11
12
|
|
|
12
|
-
var _excluded$Y=["username","password","token","contentType","accept"],_excluded2$S=["path","method","body","headers","queryParams","matrixParams","costEstimate"];function ownKeys$10(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread$10(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys$10(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys$10(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}var defaultClient=axios.create();var CancelToken=axios.CancelToken;function login(_ref){var baseURL=_ref.baseURL,token=_ref.token,username=_ref.username,password=_ref.password,bearerToken=_ref.bearerToken;if(baseURL){defaultClient.defaults.baseURL=baseURL;}if(token){defaultClient.defaults.headers.Authorization="token ".concat(token);}if(bearerToken){defaultClient.defaults.headers.Authorization="Bearer ".concat(bearerToken);}if(username||password)defaultClient.defaults.auth={username:username,password:password};}function logout(){delete defaultClient.defaults.headers.Authorization;delete defaultClient.defaults.auth;}function btoa(str){var buffer=str instanceof Buffer?str:Buffer.from(str.toString(),'binary');return buffer.toString('base64');}function debounce(func,wait,immediate){var _this=this;var timeout;return function(args){var context=_this;var later=function later(){timeout=null;if(!immediate)func.apply(context,args);};var callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)func.apply(context,args);};}function uuidv4(){return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,function(c){return(// eslint-disable-next-line
|
|
13
|
+
var _excluded$Y=["username","password","token","contentType","accept"],_excluded2$S=["path","method","body","headers","queryParams","matrixParams","costEstimate"];function ownKeys$10(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread$10(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys$10(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys$10(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}var defaultClient=axios.create();axiosRetry(defaultClient,{retries:24,retryDelay:function retryDelay(retryCount){return retryCount*5000;},retryCondition:function retryCondition(){return navigator.onLine===false;}});var CancelToken=axios.CancelToken;function login(_ref){var baseURL=_ref.baseURL,token=_ref.token,username=_ref.username,password=_ref.password,bearerToken=_ref.bearerToken;if(baseURL){defaultClient.defaults.baseURL=baseURL;}if(token){defaultClient.defaults.headers.Authorization="token ".concat(token);}if(bearerToken){defaultClient.defaults.headers.Authorization="Bearer ".concat(bearerToken);}if(username||password)defaultClient.defaults.auth={username:username,password:password};}function logout(){delete defaultClient.defaults.headers.Authorization;delete defaultClient.defaults.auth;}function btoa(str){var buffer=str instanceof Buffer?str:Buffer.from(str.toString(),'binary');return buffer.toString('base64');}function debounce(func,wait,immediate){var _this=this;var timeout;return function(args){var context=_this;var later=function later(){timeout=null;if(!immediate)func.apply(context,args);};var callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)func.apply(context,args);};}function uuidv4(){return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,function(c){return(// eslint-disable-next-line
|
|
13
14
|
(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16));});}function setDefaultHeaders(){var _ref2=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},_ref2$username=_ref2.username,username=_ref2$username===void 0?false:_ref2$username,_ref2$password=_ref2.password,password=_ref2$password===void 0?false:_ref2$password,token=_ref2.token,_ref2$contentType=_ref2.contentType,contentType=_ref2$contentType===void 0?'application/json':_ref2$contentType,_ref2$accept=_ref2.accept,accept=_ref2$accept===void 0?'application/json':_ref2$accept,props=_objectWithoutProperties(_ref2,_excluded$Y);var headers={'content-type':contentType,Accept:accept};if(username){var encodedAuth=btoa("".concat(username,":").concat(password));headers.Authorization="Basic ".concat(encodedAuth);}else if(token){headers.Authorization="token ".concat(token);}return _objectSpread$10(_objectSpread$10({},props),headers);}var KV_PARAMS=['jobmetadata','jobMetadata','notificationdata','notificationData','methodMetadata'];function setQueryParams(queryParams){var paramKeys=Object.keys(queryParams);if(paramKeys.length===0)return '';var reducer=function reducer(accumulator,currentKey,currentIndex){if(typeof queryParams[currentKey]==='undefined'){return accumulator;}var currentValue=queryParams[currentKey];var separator=currentIndex>0?'&':'';if(KV_PARAMS.includes(currentKey)){var kvReducer=function kvReducer(a,c,i){return "".concat(a).concat(i>0?'&':'').concat(currentKey,"=").concat(c.key,"%3D").concat(c.value);};var kvString=currentValue.reduce(kvReducer,'');return "".concat(accumulator).concat(separator).concat(kvString);}if(Array.isArray(currentValue)){return "".concat(accumulator).concat(separator).concat(currentKey,"=").concat(currentValue.join(','));}return "".concat(accumulator).concat(separator).concat(currentKey,"=").concat(currentValue);};var paramStr=paramKeys.reduce(reducer,'?');return paramStr;}function setMatrix(matrix){var matrixList=matrix;if(!Array.isArray(matrix)){matrixList=Object.entries(matrix);}if(matrixList.length===0)return '';var reducer=function reducer(a,c){var matrixKey;var matrixValue;if(Array.isArray(c)){var _c=_slicedToArray(c,2);matrixKey=_c[0];matrixValue=_c[1];}else {var _Object$keys=Object.keys(c);var _Object$keys2=_slicedToArray(_Object$keys,1);matrixKey=_Object$keys2[0];var _Object$values=Object.values(c);var _Object$values2=_slicedToArray(_Object$values,1);matrixValue=_Object$values2[0];}if(matrixValue===''||matrixValue===undefined){return a;}return "".concat(a,";").concat(matrixKey,"=").concat(encodeURIComponent(matrixValue));};var matrixStr=matrixList.reduce(reducer,'');return matrixStr;}function isRequired(){throw new Error('Missing property');}function vFetch(){var _ref3=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},path=_ref3.path,_ref3$method=_ref3.method,method=_ref3$method===void 0?'GET':_ref3$method,data=_ref3.body,_ref3$headers=_ref3.headers,extraHeaders=_ref3$headers===void 0?{}:_ref3$headers,_ref3$queryParams=_ref3.queryParams,queryParams=_ref3$queryParams===void 0?{}:_ref3$queryParams,_ref3$matrixParams=_ref3.matrixParams,matrixParams=_ref3$matrixParams===void 0?[]:_ref3$matrixParams,_ref3$costEstimate=_ref3.costEstimate,costEstimate=_ref3$costEstimate===void 0?false:_ref3$costEstimate,props=_objectWithoutProperties(_ref3,_excluded2$S);var params=setQueryParams(queryParams);var matrix=setMatrix(matrixParams);var headers=setDefaultHeaders(extraHeaders);var url="".concat(path).concat(matrix).concat(params);if(costEstimate){url=url.replace('/API/','/API/cost/');}var request=_objectSpread$10({method:method,url:url,headers:headers,data:data},props);return new Promise(function(resolve,reject){defaultClient(request).then(function(response){response.ok=response.status>=100&&response.status<=399;response.json=function(){return response.data;};response.text=function(){return response.data;};resolve(response);})["catch"](function(error){return reject(error);});});}
|
|
14
15
|
|
|
15
16
|
var utils = /*#__PURE__*/Object.freeze({
|
|
@@ -548,7 +549,7 @@ var _excluded$T=["itemId"],_excluded2$O=["itemId","shapeId"],_excluded3$G=["item
|
|
|
548
549
|
* @returns {Promise<Object>}
|
|
549
550
|
*/function removeComponentBulkyMetadata(_ref18){var _ref18$itemId=_ref18.itemId,itemId=_ref18$itemId===void 0?isRequired():_ref18$itemId,_ref18$shapeId=_ref18.shapeId,shapeId=_ref18$shapeId===void 0?isRequired():_ref18$shapeId,_ref18$componentId=_ref18.componentId,componentId=_ref18$componentId===void 0?isRequired():_ref18$componentId,_ref18$key=_ref18.key,key=_ref18$key===void 0?isRequired():_ref18$key,props=_objectWithoutProperties(_ref18,_excluded18$6);var path="/API/item/".concat(itemId,"/shape/").concat(shapeId,"/component/").concat(componentId,"/metadata/bulky/").concat(key);return vFetch(_objectSpread$W({path:path,method:'DELETE'},props));}var bulkymetadata = {listItemBulkyMetadata:listItemBulkyMetadata,listShapeBulkyMetadata:listShapeBulkyMetadata,listComponentBulkyMetadata:listComponentBulkyMetadata,updateAllItemBulkyMetadata:updateAllItemBulkyMetadata,updateAllShapeBulkyMetadata:updateAllShapeBulkyMetadata,updateAllComponentBulkyMetadata:updateAllComponentBulkyMetadata,removeAllItemBulkyMetadata:removeAllItemBulkyMetadata,removeAllShapeBulkyMetadata:removeAllShapeBulkyMetadata,removeAllComponentBulkyMetadata:removeAllComponentBulkyMetadata,getItemBulkyMetadata:getItemBulkyMetadata,getShapeBulkyMetadata:getShapeBulkyMetadata,getComponentBulkyMetadata:getComponentBulkyMetadata,updateItemBulkyMetadata:updateItemBulkyMetadata,updateShapeBulkyMetadata:updateShapeBulkyMetadata,updateComponentBulkyMetadata:updateComponentBulkyMetadata,removeItemBulkyMetadata:removeItemBulkyMetadata,removeShapeBulkyMetadata:removeShapeBulkyMetadata,removeComponentBulkyMetadata:removeComponentBulkyMetadata};
|
|
550
551
|
|
|
551
|
-
function ownKeys$V(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread$V(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys$V(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys$V(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}function toPercent(numerator,denominator){if(numerator===0||denominator===0){return 0;}return Math.floor(numerator/denominator*100);}var constants=Object.freeze({statuses:{transfering:1,paused:2,complete:3,failed:4,unstarted:5,canceled:6},events:{progress:'progress',update:'update',complete:'complete',error:'error',added:'upload-added',removed:'upload-removed',retry:'retry',pausing:'pausing',paused:'paused',resuming:'resuming',offline:'offline',// <-- don't change this one, www spec match
|
|
552
|
+
function ownKeys$V(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread$V(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys$V(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys$V(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}function toPercent(numerator,denominator){if(numerator===0||denominator===0){return 0;}return Math.floor(numerator/denominator*100);}var constants=Object.freeze({statuses:{transfering:1,paused:2,complete:3,failed:4,unstarted:5,canceled:6,offline:7},events:{progress:'progress',update:'update',complete:'complete',error:'error',added:'upload-added',removed:'upload-removed',retry:'retry',pausing:'pausing',paused:'paused',resuming:'resuming',offline:'offline',// <-- don't change this one, www spec match
|
|
552
553
|
online:'online'// <-- don't change this one, www spec match
|
|
553
554
|
},defaults:{targetRate:4000000,// 4mb sec,
|
|
554
555
|
chunkSize:10000000,// 10mb chunks
|
|
@@ -563,10 +564,9 @@ var handlers=this.events[event];if(!handlers||handlers.length<1)return;handlers.
|
|
|
563
564
|
};Object.assign(this,defaultProps,props);this.state={retries:0,status:constants.statuses.unstarted,startTime:null,completeTime:null,response:null,bytesTransfered:null};this.events=new CUEvents();}// try to transfer
|
|
564
565
|
_createClass(Chunk,[{key:"try",value:function _try(){var _this=this;this.state.status=constants.statuses.transfering;this.state.startTime=performance.now();return new Promise(function(resolve,reject){var tryTransfer=function tryTransfer(){_this.transfer().then(function(response){_this.state.response=response;_this.onComplete();resolve();})["catch"](function(){if(_this.state.retries>3){_this.state.status=constants.statuses.failed;reject(new Error("Chunk ".concat(_this.start,"-").concat(_this.end," failed")));}else if(_this.state.status!==constants.statuses.paused){_this.state.retries+=1;// wait a sec and call again
|
|
565
566
|
_this.tryTimeout=setTimeout(function(){tryTransfer();// retry
|
|
566
|
-
},1000);}else {clearTimeout(_this.tryTimeout);}});};tryTransfer()
|
|
567
|
-
});}},{key:"transfer",value:function transfer(){var _this2=this;var options={file:this.blobSlice,onUploadProgress:function onUploadProgress(progressEvent){if(_this2.state.status!==constants.statuses.complete){_this2.state.bytesTransfered=progressEvent.loaded;_this2.events.trigger(constants.events.progress,_this2.state);}}};if(this.end-this.start!==this.fileSize){// only add headers if chunk !== whole file
|
|
567
|
+
},1000);}else {clearTimeout(_this.tryTimeout);}});};tryTransfer();window.addEventListener(constants.events.online,function(){_this.resume();});window.addEventListener(constants.events.offline,function(){_this.pause();});});}},{key:"transfer",value:function transfer(){var _this2=this;var options={file:this.blobSlice,onUploadProgress:function onUploadProgress(progressEvent){if(_this2.state.status!==constants.statuses.complete||_this2.state.status!==constants.statuses.offline){_this2.state.bytesTransfered=progressEvent.loaded;_this2.events.trigger(constants.events.progress,_this2.state);}}};if(this.end-this.start!==this.fileSize){// only add headers if chunk !== whole file
|
|
568
568
|
options.headers={index:this.start,size:this.fileSize};}options=_objectSpread$V(_objectSpread$V({},options),this.api.props);this.transferPromise=this.api.method(options);// TODO implement axios onUploadProgress
|
|
569
|
-
this.state.status=constants.statuses.transfering;return this.transferPromise;}},{key:"onComplete",value:function onComplete(){this.state.status=constants.statuses.complete;this.state.bytesTransfered=this.end-this.start;this.state.completeTime=performance.now();this.events.trigger(constants.events.complete);}},{key:"pause",value:function pause(){if(this.state.status!==constants.statuses.complete){this.state.status=constants.statuses.paused;}}},{key:"cancel",value:function cancel(){if(this.state.status!==constants.statuses.complete){this.state.status=constants.statuses.canceled;// reject promise
|
|
569
|
+
this.state.status=constants.statuses.transfering;return this.transferPromise;}},{key:"onComplete",value:function onComplete(){this.state.status=constants.statuses.complete;this.state.bytesTransfered=this.end-this.start;this.state.completeTime=performance.now();this.events.trigger(constants.events.complete);}},{key:"pause",value:function pause(){if(this.state.status!==constants.statuses.complete){this.state.status=constants.statuses.paused;}}},{key:"resume",value:function resume(){if(this.state.status!==constants.statuses.complete){this.state.status=constants.statuses.transfering;}}},{key:"cancel",value:function cancel(){if(this.state.status!==constants.statuses.complete){this.state.status=constants.statuses.canceled;// reject promise
|
|
570
570
|
// this.transferPromise && this.transferPromise.reject(new Error(`Chunk ${this.start}-${this.end} canceled.`))
|
|
571
571
|
}}},{key:"transferRate",get:function get(){if(this.state.bytesTransfered){var secondsTaken=(this.state.completeTime-this.state.startTime)/1000;var bytesPerSecond=this.state.bytesTransfered/secondsTaken;return bytesPerSecond;}return 0;}}]);return Chunk;}();var ChunkedUpload=/*#__PURE__*/function(){function ChunkedUpload(param,options){_classCallCheck(this,ChunkedUpload);this.events=new CUEvents();// can be blob or transfer if for download (?)
|
|
572
572
|
if(!options.api.method)throw new Error('No api method specified');this.defaultOptions=_objectSpread$V(_objectSpread$V({},constants.defaults),{},{targetRate:4000000,// bytes / second
|
|
@@ -583,7 +583,9 @@ this.state.chunks.forEach(function(chunk){var isChunkAvailable=chunk.state.statu
|
|
|
583
583
|
_this3.state.transferPromises.push(chunk["try"]());}// TODO - forEach looks pretty but is not the fastest, consider if perf is optimal
|
|
584
584
|
});// reinvoke this method for next chunk batch
|
|
585
585
|
if(this.state.transferPromises.length>0){// there is more work to do
|
|
586
|
-
Promise.all(this.state.transferPromises).then(function(){_this3.upload();})["catch"](function(error){console.log('Failed on this upload() cycle, check connectivity and try to resume :(');_this3.state.status=constants.statuses.failed;_this3.events.trigger(constants.events.failed,{error:error,transfer:_this3})
|
|
586
|
+
Promise.all(this.state.transferPromises).then(function(){_this3.upload();})["catch"](function(error){console.log('Failed on this upload() cycle, check connectivity and try to resume :(',error);if(_this3.state.status!==constants.statuses.offline){_this3.state.status=constants.statuses.failed;_this3.events.trigger(constants.events.failed,{error:error,transfer:_this3});// if (this.options.onFail) this.options.onFail(error);
|
|
587
|
+
}else {setTimeout(function(){return _this3.retry();},5000);}});}}}else {// Operation unavailable, try .resume() instead.
|
|
588
|
+
this.retry();}}// get all byte ranges for splitting in chunks
|
|
587
589
|
},{key:"getByteRangesForChunks",value:function getByteRangesForChunks(blob){var chunkSize=arguments.length>1&&arguments[1]!==undefined?arguments[1]:this.options.chunkSize;var byteRanges=[];// output
|
|
588
590
|
var minChunkSize=this.options.minChunkSize;var targetChunkSize=chunkSize>=minChunkSize?chunkSize:minChunkSize;var finalChunkSize=targetChunkSize;// determine the number of chunks
|
|
589
591
|
var times=Math.floor(blob.size/finalChunkSize);// if last chunk happens to bee too small, reduce the denominator
|
|
@@ -592,7 +594,7 @@ times-=1;finalChunkSize=Math.floor(blob.size/times);// adjust final chunk size
|
|
|
592
594
|
}if(times<2||blob.size<this.options.minFileSize){// single chunk it is
|
|
593
595
|
byteRanges.push({start:0,end:blob.size});}else {for(var i=0;i<=times;i+=1){var start=finalChunkSize*i;var end=finalChunkSize*i+finalChunkSize;// if the remainig bytes to be transfered is less than minChunkSize
|
|
594
596
|
var remainder=blob.size-finalChunkSize*i;if(remainder<=minChunkSize){end=blob.size;}var range={start:start,end:end};byteRanges.push(range);if(end===blob.size){break;// all byteranges till the end are covered, no more chunks
|
|
595
|
-
}}}return byteRanges;}},{key:"addChunksFromBlob",value:function addChunksFromBlob(blob){var _this4=this;var byteranges=this.getByteRangesForChunks(blob);byteranges.forEach(function(byterange){var chunk=new Chunk({start:byterange.start,end:byterange.end,blobSlice:blob.slice(byterange.start,byterange.end),fileSize:blob.size,api:_this4.options.api});chunk.events.on(constants.events.progress,function(){_this4.onProgress();});chunk.events.on(constants.events.complete,function(){_this4.onProgress();});_this4.state.chunks.push(chunk);});}},{key:"retry",value:function retry(){if(this.state.status===constants.statuses.failed){this.resume();this.events.trigger(constants.events.retry);}}},{key:"resume",value:function resume(){this.state.status=constants.statuses.transfering;this.
|
|
597
|
+
}}}return byteRanges;}},{key:"addChunksFromBlob",value:function addChunksFromBlob(blob){var _this4=this;var byteranges=this.getByteRangesForChunks(blob);byteranges.forEach(function(byterange){var chunk=new Chunk({start:byterange.start,end:byterange.end,blobSlice:blob.slice(byterange.start,byterange.end),fileSize:blob.size,api:_this4.options.api});chunk.events.on(constants.events.progress,function(){_this4.onProgress();});chunk.events.on(constants.events.complete,function(){_this4.onProgress();});_this4.state.chunks.push(chunk);});}},{key:"retry",value:function retry(){if(this.state.status===constants.statuses.failed){this.resume();this.events.trigger(constants.events.retry);}}},{key:"resume",value:function resume(){this.state.status=constants.statuses.transfering;this.events.trigger(constants.events.resuming);if(this.state.chunks.length>0){this.state.chunks.forEach(function(chunkInstance){chunkInstance.resume();});}}},{key:"pause",value:function pause(){var _this5=this;this.state.status=constants.statuses.paused;// run a loop that pauses all Chunk instances (cancel network request / promise?)
|
|
596
598
|
if(this.state.chunks.length>0){this.state.chunks.forEach(function(chunkInstance){chunkInstance.pause();});}// wait for the rest of chunks to complete
|
|
597
599
|
var pausedPromise=Promise.all(this.state.transferPromises);this.events.trigger(constants.events.pausing);pausedPromise.then(function(){_this5.events.trigger(constants.events.paused);});return Promise.all(this.state.transferPromises);}},{key:"cancel",value:function cancel(){var _this6=this;// TODO - check what to destruct
|
|
598
600
|
this.state.status=constants.statuses.canceled;if(this.state.chunks.length>0){this.state.chunks.forEach(function(chunkInstance){chunkInstance.cancel();});}this.upload=function(){};var transfersFinishedPromise=Promise.all(this.state.transferPromises);transfersFinishedPromise.then(function(){_this6.events.trigger(constants.events.removed,_this6);});// remaining transfers finishing, this can take a long time
|
|
@@ -611,7 +613,8 @@ this.state.rate=stats.avgTransferRate;return stats;}// if a setter is used, stop
|
|
|
611
613
|
return this.state.rate;},set:function set(_int2){// sets target rate
|
|
612
614
|
this.state.targetRate=_int2;}},{key:"finalResponse",get:function get(){var times=this.state.chunks.length-1;var response=false;for(var i=times;i>=0;i-=1){var chunk=this.state.chunks[i];if(_typeof(chunk.state.response.data)==='object'){return chunk.state.response;}}return response;}},{key:"transferId",get:function get(){return this.state.transferId;}}]);return ChunkedUpload;}();var ChunkedTransferManager=/*#__PURE__*/function(){function ChunkedTransferManager(options){_classCallCheck(this,ChunkedTransferManager);this.initialState=Object.freeze({status:constants.statuses.unstarted,transfers:{},bytesDone:0,bytesTotal:0,lastStats:{// helps evaluate progress change
|
|
613
615
|
bytesDone:0,bytesTotal:0}});this.state=_objectSpread$V({},this.initialState);this.options=_objectSpread$V({maxConcurrentFileTransfers:constants.defaults.maxConcurrentFileTransfers,autoResume:constants.defaults.autoResume},options);this.events=new CUEvents();this.bindNetworkEvents();}_createClass(ChunkedTransferManager,[{key:"bindNetworkEvents",value:function bindNetworkEvents(){var _this8=this;if(!(typeof window==='undefined')){// check if on browser
|
|
614
|
-
window.addEventListener(constants.events.online,function(){_this8.events.trigger(constants.events.online,_this8.state);if(_this8.options.autoResume){setTimeout(function(){_this8.retry();},1500);}});window.addEventListener(constants.events.offline,function(){_this8.events.trigger(constants.events.offline,_this8.state);
|
|
616
|
+
window.addEventListener(constants.events.online,function(){_this8.events.trigger(constants.events.online,_this8.state);_this8.state.status=constants.statuses.transfering;if(_this8.options.autoResume){setTimeout(function(){_this8.retry();},1500);}});window.addEventListener(constants.events.offline,function(){_this8.events.trigger(constants.events.offline,_this8.state);_this8.state.status=constants.statuses.offline;// if (this.options.autoResume) this.pause();
|
|
617
|
+
});}}},{key:"addChunkedUpload",value:function addChunkedUpload(cuInstance){var _this9=this;// for chunked uploads
|
|
615
618
|
if(cuInstance.transferId!==null){this.state.transfers[cuInstance.transferId]=cuInstance;// bind to ChunkedUpload events
|
|
616
619
|
cuInstance.events.on(constants.events.progress,function(){// a chunk is finished
|
|
617
620
|
_this9.onProgress();});cuInstance.events.on(constants.events.complete,function(){// a transfer is finished
|