UNPKG

@appzung/react-native-code-push

Version:

React Native plugin for the CodePush service

51 lines (49 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemotePackageImpl = void 0; var _reactNative = require("react-native"); var _LogLevelEnum = require("../enums/LogLevel.enum.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) { const codePushEventEmitter = new _reactNative.NativeEventEmitter(_NativeRNAppZungCodePushModule.NativeRNAppZungCodePushModule); // Use event subscription to obtain download progress. downloadProgressSubscription = 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