Skip to content

Commit

Permalink
Show a notification when it's the player's turn. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Castelluccio committed Sep 30, 2015
1 parent a72ed9a commit 2930550
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions js/sw-push.js
@@ -1,6 +1,11 @@
var port;

self.addEventListener('push', function(event) {
event.waitUntil(self.registration.showNotification('TicTacToe', {
body: 'It\'s your turn!',
tag: 'tictactoe',
}));

port.postMessage(event.data.json());
});

Expand Down
2 changes: 2 additions & 0 deletions js/tictactoe.js
Expand Up @@ -110,6 +110,8 @@ function yourMove(x, y) {
localforage.setItem('game', [ gameRegistered, yourTurn, xBoard, oBoard ]);
}

Notification.requestPermission();

var subscriptionPromise = navigator.serviceWorker.ready.then(function(reg) {
var channel = new MessageChannel();
channel.port1.onmessage = function(e) {
Expand Down

0 comments on commit 2930550

Please sign in to comment.