UNPKG

@itwin/presentation-frontend

Version:

Frontend of iModel.js Presentation library

49 lines 2.06 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 { _currentStatus; _unsubscribeFromInternetConnectivityChangedEvent; onInternetConnectivityChanged = new BeEvent(); constructor() { 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; } } [Symbol.dispose]() { this._unsubscribeFromInternetConnectivityChangedEvent && this._unsubscribeFromInternetConnectivityChangedEvent(); } onNativeAppInternetConnectivityChanged = (status) => { if (this._currentStatus === status) { return; } this._currentStatus = status; this.onInternetConnectivityChanged.raiseEvent({ status }); }; get status() { return this._currentStatus ?? InternetConnectivityStatus.Offline; } } //# sourceMappingURL=ConnectivityInformationProvider.js.map