partey_workadventure/front/src/Network/ServiceWorker.ts

32 lines
995 B
TypeScript
Raw Normal View History

import { NODE_ENV } from "../Enum/EnvironmentVariable";
export class _ServiceWorker {
constructor() {
if ("serviceWorker" in navigator) {
this.init();
}
}
init() {
if (NODE_ENV === "development") {
navigator.serviceWorker
.register("/service-worker-dev.js")
.then((serviceWorker) => {
console.info("Service Worker registered: ", serviceWorker);
})
.catch((error) => {
console.error("Error registering the Service Worker: ", error);
});
return;
}
2021-08-04 13:33:58 +02:00
navigator.serviceWorker
.register("/service-worker-prod.js")
2021-08-04 13:33:58 +02:00
.then((serviceWorker) => {
console.info("Service Worker registered: ", serviceWorker);
})
.catch((error) => {
console.error("Error registering the Service Worker: ", error);
});
}
}