UNPKG

@itwin/presentation-frontend

Version:

Frontend of iModel.js Presentation library

47 lines 2.02 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Core */ import { BeEvent } from "@itwin/core-bentley"; import { InternetConnectivityStatus } from "@itwin/core-common"; import { NativeApp } from "@itwin/core-frontend"; /** * A helper that wraps connectivity-related APIs in NativeApp * to give a unified information for interested parties in presentation. * * @internal */ export class ConnectivityInformationProvider { constructor() { this.onInternetConnectivityChanged = new BeEvent(); this.onNativeAppInternetConnectivityChanged = (status) => { if (this._currentStatus === status) { return; } this._currentStatus = status; this.onInternetConnectivityChanged.raiseEvent({ status }); }; if (NativeApp.isValid) { this._unsubscribeFromInternetConnectivityChangedEvent = NativeApp.onInternetConnectivityChanged.addListener(this.onNativeAppInternetConnectivityChanged); // eslint-disable-next-line @typescript-eslint/no-floating-promises NativeApp.checkInternetConnectivity().then((status) => { if (undefined === this._currentStatus) { this._currentStatus = status; } }); } else { this._currentStatus = InternetConnectivityStatus.Online; } } dispose() { this._unsubscribeFromInternetConnectivityChangedEvent && this._unsubscribeFromInternetConnectivityChangedEvent(); } get status() { return this._currentStatus ?? InternetConnectivityStatus.Offline; } } //# sourceMappingURL=ConnectivityInformationProvider.js.map