Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set service worker timeout #973

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ document.addEventListener("DOMContentLoaded", async () => {
} catch (e) {
subscriptions.setRegistrationFailed();
}
} else {
subscriptions.setRegistrationFailed();
}

const scene = document.querySelector("a-scene");
Expand Down
4 changes: 3 additions & 1 deletion src/subscriptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nextTick from "./utils/next-tick.js";
const INIT_TIMEOUT_MS = 5000;

// Manages web push subscriptions
//
Expand Down Expand Up @@ -46,9 +47,10 @@ export default class Subscriptions {

getCurrentEndpoint = async () => {
if (!navigator.serviceWorker) return null;
const startedAt = performance.now();

// registration becomes null if failed, non null if registered
while (this.registration === undefined) await nextTick();
while (this.registration === undefined && performance.now() - startedAt < INIT_TIMEOUT_MS) await nextTick();
if (!this.registration || !this.registration.pushManager) return null;

while (this.vapidPublicKey === undefined) await nextTick();
Expand Down