UNPKG

@appzung/react-native-code-push

Version:

React Native plugin for the CodePush service

50 lines (48 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemotePackageImpl = void 0; var _LogLevelEnum = require("../enums/LogLevel.enum.js"); var _CodePushEventEmitter = require("./CodePushEventEmitter.js"); var _LocalPackageImplementation = require("./LocalPackageImplementation.js"); var _NativeRNAppZungCodePushModule = require("./NativeRNAppZungCodePushModule.js"); var _log = require("./utils/log.js"); class RemotePackageImpl { constructor(remotePackageData, reportStatusDownload) { Object.assign(this, remotePackageData); this.download = async downloadProgressCallback => { if (!this.downloadUrl) { throw new Error('Cannot download an update without a download url'); } let downloadProgressSubscription; if (downloadProgressCallback) { // Use event subscription to obtain download progress. downloadProgressSubscription = _CodePushEventEmitter.CodePushEventEmitter.addListener('CodePushDownloadProgress', downloadProgressCallback); } // Use the downloaded package info. Native code will save the package info // so that the client knows what the current package version is. try { const { ...updatePackageCopy } = remotePackageData; // In dev mode, React Native deep freezes any object queued over the bridge const downloadedPackage = await _NativeRNAppZungCodePushModule.NativeRNAppZungCodePushModule.downloadUpdate(updatePackageCopy, !!downloadProgressCallback); if (reportStatusDownload) { const timeoutPromise = new Promise(resolve => setTimeout(resolve, 250)); const reportPromise = reportStatusDownload({ label: this.label }).catch(error => { (0, _log.log)(_LogLevelEnum.LogLevel.ERROR, `Report download status failed: ${error}`); }); await Promise.race([timeoutPromise, reportPromise]); } return new _LocalPackageImplementation.LocalPackageImplementation(downloadedPackage); } finally { downloadProgressSubscription && downloadProgressSubscription.remove(); } }; } isPending = false; // A remote package could never be in a pending state } exports.RemotePackageImpl = RemotePackageImpl; //# sourceMappingURL=RemotePackageImplementation.js.map