This commit is contained in:
syuilo 2017-11-21 05:09:45 +09:00
parent 3fa7215f39
commit c598a9cba2
7 changed files with 91 additions and 31 deletions

View file

@ -1,31 +0,0 @@
/**
* Service Worker
*/
// インストールされたとき
self.addEventListener('install', () => {
console.log('[sw]', 'Your ServiceWorker is installed');
});
// プッシュ通知を受け取ったとき
self.addEventListener('push', ev => {
// クライアント取得
self.clients.matchAll({
includeUncontrolled: true
}).then(clients => {
// クライアントがあったらストリームに接続しているということなので通知しない
if (clients.length != 0) return;
const { type, body } = ev.data.json();
handlers[type](body);
});
});
const handlers = {
mention: body => {
self.registration.showNotification('mentioned', {
body: body.text,
icon: body.user.avatar_url + '?thumbnail&size=64',
});
}
};