UNPKG

tus-js-client-stall-detection

Version:

A pure JavaScript client for the tus resumable upload protocol (fork with stall detection)

55 lines 2.26 kB
import { DetailedError } from '../DetailedError.js'; import { NoopUrlStorage } from '../NoopUrlStorage.js'; import { enableDebugLog } from '../logger.js'; import { BaseUpload, defaultOptions as baseDefaultOptions, terminate } from '../upload.js'; import { BrowserFileReader } from './BrowserFileReader.js'; import { XHRHttpStack as DefaultHttpStack } from './XHRHttpStack.js'; import { fingerprint } from './fileSignature.js'; import { WebStorageUrlStorage, canStoreURLs } from './urlStorage.js'; const defaultOptions = { ...baseDefaultOptions, httpStack: new DefaultHttpStack(), fileReader: new BrowserFileReader(), urlStorage: canStoreURLs ? new WebStorageUrlStorage() : new NoopUrlStorage(), fingerprint, }; class Upload extends BaseUpload { constructor(file, options = {}) { const allOpts = { ...defaultOptions, ...options, // Deep merge stallDetection options if provided ...(options.stallDetection && { stallDetection: { ...defaultOptions.stallDetection, ...options.stallDetection, }, }), }; super(file, allOpts); } static terminate(url, options = {}) { const allOpts = { ...defaultOptions, ...options, // Deep merge stallDetection options if provided ...(options.stallDetection && { stallDetection: { ...defaultOptions.stallDetection, ...options.stallDetection, }, }), }; return terminate(url, allOpts); } } // Note: We don't reference `window` here because these classes also exist in a Web Worker's context. const isSupported = typeof XMLHttpRequest === 'function' && typeof Blob === 'function' && typeof Blob.prototype.slice === 'function'; // Note: The exported interface must be the same as in lib/node/index.ts. // Any changes should be reflected in both files. export { Upload, defaultOptions, isSupported, canStoreURLs, enableDebugLog, DetailedError }; export { XHRHttpStack } from './XHRHttpStack.js'; export { FetchHttpStack } from './FetchHttpStack.js'; //# sourceMappingURL=index.js.map