NetworkMonitor.js 512 B

123456789101112131415161718
  1. class NetworkMonitor {
  2. constructor(e) {
  3. E(this, "_listener");
  4. this._listener = e
  5. }
  6. get isOnline() {
  7. const e = window.navigator;
  8. return typeof e.onLine == "boolean" ? e.onLine : !0
  9. }
  10. start() {
  11. window.addEventListener("online", this._listener),
  12. window.addEventListener("offline", this._listener)
  13. }
  14. stop() {
  15. window.removeEventListener("online", this._listener),
  16. window.removeEventListener("offline", this._listener)
  17. }
  18. }