Skip to content

Commit 7d28f38

Browse files
committed
Update worker-channel.js
1 parent 5fcf98d commit 7d28f38

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

worker/worker-channel.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,36 @@ async function setupWorkerChannel() {
1818

1919
await workerInstallPromise;
2020

21-
workerInstallPromise = null;
2221

23-
console.debug('[ServiceWorker] Installed');
22+
async function pingWorkerForClientId() {
23+
24+
// get client ID from worker
25+
let resp = await axios.get('/worker/getClientId', '', true);
26+
27+
try {
28+
resp = JSON.parse(resp);
29+
} catch(e) {
30+
resp = '';
31+
}
32+
33+
if (!resp || !resp.clientId) {
34+
35+
return await pingWorkerForClientId();
36+
37+
} else {
38+
39+
return resp.clientId;
40+
41+
}
42+
43+
}
2444

45+
// ping worker for client ID
46+
47+
workerInstallPromise = pingWorkerForClientId();
48+
49+
workerClientId = await workerInstallPromise;
50+
2551

2652
// create worker channel
2753
workerChannel = new BroadcastChannel('worker-channel');

0 commit comments

Comments
 (0)