OLD | NEW |
---|---|
(Empty) | |
1 self.onfetch = function(e) { | |
2 if (e.request.url.indexOf('clients-get-frame.html') >= 0) { | |
3 // On navigation, the client id should be null. | |
4 if (e.clientId === null) { | |
5 e.respondWith(fetch(e.request)); | |
6 } else { | |
7 e.respondWith(Response.error()); | |
8 } | |
9 return; | |
10 } | |
11 e.respondWith(new Response(e.clientId)); | |
12 }; | |
13 | |
14 self.onmessage = function(e) { | |
15 var port = e.data.port; | |
16 var clientIds = e.data.clientIds; | |
17 var message = []; | |
18 | |
19 Promise.all( | |
nhiroki
2016/02/16 06:09:31
e.waitUntil(Promise.all(...)); ?
(ExtendableMessa
jungkees
2016/02/16 16:28:58
Ahh.. Great! Addressed.
| |
20 clientIds.map(function(clientId) { | |
21 return self.clients.get(clientId); | |
22 })) | |
23 .then(function(clients) { | |
24 // No matching client for a given id or a matched client is off-origin | |
25 // from the service worker. | |
26 if (clients.length == 1 && clients[0] == undefined) { | |
27 port.postMessage(clients[0]); | |
28 } else { | |
29 clients.forEach(function(client) { | |
30 if (client instanceof Client) { | |
31 message.push([client.visibilityState, | |
32 client.focused, | |
33 client.url, | |
34 client.frameType]); | |
35 } else { | |
36 message.push(client); | |
37 } | |
38 }); | |
39 port.postMessage(message); | |
40 } | |
41 }); | |
42 }; | |
OLD | NEW |