OLD | NEW |
---|---|
(Empty) | |
1 self.onfetch = function(e) { | |
2 if (e.request.url.indexOf("clients-get-frame.html") >= 0) { | |
3 if (e.clientId === null) { | |
nhiroki
2016/02/08 06:27:03
Can you add a comment like this?
// On navigation
jungkees
2016/02/12 15:03:22
Done.
| |
4 e.respondWith(fetch(e.request)); | |
5 } else { | |
6 e.respondWith(Response.error()); | |
7 } | |
8 return; | |
9 } | |
10 e.respondWith(new Response(e.clientId)); | |
11 }; | |
12 | |
13 self.onmessage = function(e) { | |
14 var port = e.data.port; | |
15 if (e.data.message == 'get_client_ids') { | |
nhiroki
2016/02/08 06:27:03
The first if-block is almost equal to the second e
jungkees
2016/02/12 15:03:22
I merged them but posted undefined instead of [und
| |
16 var clientIds = e.data.clientIds; | |
17 var message = []; | |
18 | |
19 Promise.all( | |
20 clientIds.map(function(clientId) { | |
21 return self.clients.get(clientId); | |
22 }).concat(self.clients.get("invalid-id")) | |
23 ).then(function(clients) { | |
24 clients.forEach(function(client) { | |
25 if (client instanceof Client) { | |
26 message.push([client.visibilityState, | |
27 client.focused, | |
28 client.url, | |
29 client.frameType]); | |
30 } else { | |
31 message.push(client); | |
32 } | |
33 }); | |
34 port.postMessage(message); | |
35 }); | |
36 } else if (e.data.message == 'get_other_client_id') { | |
37 var clientId = e.data.clientId; | |
38 var message; | |
39 | |
40 self.clients.get(clientId) | |
41 .then(function(client) { | |
42 if (client instanceof Client) { | |
43 message = [client.visibilityState, | |
44 client.focused, | |
45 client.url, | |
46 client.frameType]; | |
47 } else { | |
48 message = client; | |
49 } | |
50 port.postMessage(message); | |
51 }); | |
52 } | |
53 }; | |
OLD | NEW |