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KAAK,IAAM,EAAQ,UACnB,KAAK,YACL,KAAK,cACT,KAEJ,KAAK,cAAc,KAAK,gBAAgB,YAAY,WAAW,IACvD,EAAQ,WAAa,KAAK,UAC1B,KAAK,QAAQ,EAAQ,MACzB,KAEJ,KAAK,cAAc,KAAK,gBAAgB,YAAY,cAAc,IAC1D,EAAQ,WAAa,KAAK,UAC1B,KAAK,WAAW,EAAQ,aAAc,EAAQ,WAClD,IAER,CAEA,WAAA,GACI,KAAK,cAAc,SAAQ,GAAgB,EAAa,UAC5D,CAEA,SAAA,GACI,KAAK,QAAQ,WAAa,KAAK,QAAQ,WAC3C,CAEA,UAAA,CAAW,EAAe,GACtB,KAAK,QAAQ,YACN,KAAK,QAAQ,WAAW,EAAe,EAClD,CAEA,OAAA,CAAQ,GACJ,KAAK,QAAQ,SAAW,KAAK,QAAQ,QAAQ,EACjD,SAGK","file":"/npm/react-native-tus-client@1.1.0/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/react-native-tus-client@1.1.0/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { NativeModules, NativeEventEmitter } from 'react-native';\n\nconst { RNTusClient } = NativeModules;\nconst tusEventEmitter = new NativeEventEmitter(RNTusClient);\n\nconst defaultOptions = {\n    headers: {},\n    metadata: {}\n};\n\n/** Class representing a tus upload */\nclass Upload {\n\n  /**\n     *\n     * @param file The file absolute path.\n     * @param settings The options argument used to setup your tus upload.\n     */\n    constructor(file, options) {\n        this.subscriptions = [];\n        this.file = file;\n        this.options = Object.assign({}, defaultOptions, options);\n    }\n\n    /**\n     * Start or resume the upload using the specified file.\n     * If no file property is available the error handler will be called.\n     */\n    start() {\n        if (!this.file) {\n            this.emitError(new Error('tus: no file or stream to upload provided'));\n            return;\n        }\n        if (!this.options.endpoint) {\n            this.emitError(new Error('tus: no endpoint provided'));\n            return;\n        }\n        (this.uploadId\n            ? Promise.resolve()\n            : this.createUpload())\n            .then(() => this.resume())\n            .catch(e => this.emitError(e));\n    }\n\n    /**\n     * Abort the currently running upload request and don't continue.\n     * You can resume the upload by calling the start method again.\n     */\n    abort() {\n        if (this.uploadId) {\n            RNTusClient.abort(this.uploadId, (err) => {\n                if (err) {\n                    this.emitError(err);\n                }\n            });\n        }\n    }\n\n    resume() {\n        RNTusClient.resume(this.uploadId, (hasBeenResumed) => {\n            if (!hasBeenResumed) {\n                this.emitError(new Error('Error while resuming the upload'));\n            }\n        });\n    }\n\n    emitError(error) {\n        if (this.options.onError) {\n            this.options.onError(error);\n        }\n        else {\n            throw error;\n        }\n    }\n\n    createUpload() {\n        return new Promise((resolve, reject) => {\n            const { metadata, headers, endpoint } = this.options;\n            const settings = { metadata, headers, endpoint };\n            RNTusClient.createUpload(this.file, settings, (uploadId, errorMessage) => {\n                this.uploadId = uploadId;\n                if (uploadId == null) {\n                    const error = errorMessage\n                        ? new Error(errorMessage)\n                        : null;\n                    reject(error);\n                }\n                else {\n                    this.subscribe();\n                    resolve();\n                }\n            });\n        });\n    }\n\n    subscribe() {\n        this.subscriptions.push(tusEventEmitter.addListener('onSuccess', payload => {\n            if (payload.uploadId === this.uploadId) {\n                this.url = payload.uploadUrl;\n                this.onSuccess();\n                this.unsubscribe();\n            }\n        }));\n        this.subscriptions.push(tusEventEmitter.addListener('onError', payload => {\n            if (payload.uploadId === this.uploadId) {\n                this.onError(payload.error);\n            }\n        }));\n        this.subscriptions.push(tusEventEmitter.addListener('onProgress', payload => {\n            if (payload.uploadId === this.uploadId) {\n                this.onProgress(payload.bytesWritten, payload.bytesTotal);\n            }\n        }));\n    }\n\n    unsubscribe() {\n        this.subscriptions.forEach(subscription => subscription.remove());\n    }\n\n    onSuccess() {\n        this.options.onSuccess && this.options.onSuccess();\n    }\n\n    onProgress(bytesUploaded, bytesTotal) {\n        this.options.onProgress\n            && this.options.onProgress(bytesUploaded, bytesTotal);\n    }\n\n    onError(error) {\n        this.options.onError && this.options.onError(error);\n    }\n}\n\nexport { Upload };\n"]}