OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Empty service worker script. | 5 this.onmessage = function(event) { |
| 6 console.log(event); |
| 7 console.log(event.data); |
| 8 sendDataToClients('Message from service worker.'); |
| 9 }; |
6 | 10 |
7 // TODO(mvanouwerkerk): Add test coverage for push event delivery. | 11 this.onpush = function(event) { |
| 12 console.log(event); |
| 13 console.log(event.data); |
| 14 sendDataToClients(event.data); |
| 15 }; |
| 16 |
| 17 function sendDataToClients(data) { |
| 18 this.clients.getAll().then(function(clients) { |
| 19 clients.forEach(function(client) { |
| 20 client.postMessage(data); |
| 21 }); |
| 22 }, function(error) { |
| 23 console.log(error); |
| 24 }); |
| 25 } |
OLD | NEW |