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.onpush = function(event) { |
| 6 sendMessageToClients('push', event.data); |
| 7 }; |
6 | 8 |
7 // TODO(mvanouwerkerk): Add test coverage for push event delivery. | 9 function sendMessageToClients(type, data) { |
| 10 var message = JSON.stringify({ |
| 11 'type': type, |
| 12 'data': data |
| 13 }); |
| 14 clients.getAll().then(function(clients) { |
| 15 clients.forEach(function(client) { |
| 16 client.postMessage(message); |
| 17 }); |
| 18 }, function(error) { |
| 19 console.log(error); |
| 20 }); |
| 21 } |
OLD | NEW |