"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onlineInitialized$ = exports.online$ = void 0;
const tslib_1 = require("tslib");
const is_online_1 = require("./is-online");
const rxjs_1 = require("rxjs");
let initialValue = null;
exports.online$ = new rxjs_1.BehaviorSubject(false);
exports.onlineInitialized$ = (0, rxjs_1.defer)(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    if (initialValue === null) {
        // Call the isOnline function only once
        initialValue = yield (0, is_online_1.isOnline)({ timeout: 2000 });
        exports.online$.next(initialValue);
    }
    // On subsequent subscriptions, immediately emit true
    return true;
}));
// @ts-ignore
if (typeof window !== 'undefined' && typeof Worker !== 'undefined' && !(self instanceof Worker)) {
    (0, rxjs_1.interval)(5000)
        .pipe((0, rxjs_1.switchMap)(() => (0, is_online_1.isOnline)({ timeout: 3000 })))
        .subscribe((online) => exports.online$.next(online));
}
//# sourceMappingURL=online.js.map