@aws-amplify/datastore
Version:
AppSyncLocal support for aws-amplify
1 lines • 3.48 kB
Source Map (JSON)
{"version":3,"file":"datastoreConnectivity.mjs","sources":["../../../src/sync/datastoreConnectivity.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Observable } from 'rxjs';\nimport { ReachabilityMonitor } from './datastoreReachability';\nconst RECONNECTING_IN = 5000; // 5s this may be configurable in the future\nexport default class DataStoreConnectivity {\n constructor() {\n this.connectionStatus = {\n online: false,\n };\n }\n status() {\n if (this.observer) {\n throw new Error('Subscriber already exists');\n }\n return new Observable(observer => {\n this.observer = observer;\n // Will be used to forward socket connection changes, enhancing Reachability\n this.subscription = ReachabilityMonitor.subscribe(({ online }) => {\n this.connectionStatus.online = online;\n const observerResult = { ...this.connectionStatus }; // copyOf status\n observer.next(observerResult);\n });\n return () => {\n clearTimeout(this.timeout);\n this.unsubscribe();\n };\n });\n }\n unsubscribe() {\n if (this.subscription) {\n clearTimeout(this.timeout);\n this.subscription.unsubscribe();\n }\n }\n // for consistency with other background processors.\n async stop() {\n this.unsubscribe();\n }\n socketDisconnected() {\n if (this.observer && typeof this.observer.next === 'function') {\n this.observer.next({ online: false }); // Notify network issue from the socket\n this.timeout = setTimeout(() => {\n const observerResult = { ...this.connectionStatus }; // copyOf status\n this.observer.next(observerResult);\n }, RECONNECTING_IN); // giving time for socket cleanup and network status stabilization\n }\n }\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA,MAAM,eAAe,GAAG,IAAI,CAAC;AACd,MAAM,qBAAqB,CAAC;AAC3C,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,gBAAgB,GAAG;AAChC,YAAY,MAAM,EAAE,KAAK;AACzB,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,GAAG;AACb,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE;AAC3B,YAAY,MAAM,IAAI,KAAK,CAAC,2BAA2B,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