36 lines
916 B
TypeScript
Raw Normal View History

2019-11-11 18:09:47 +09:00
import { NotificationRequest } from '@ucap-webmessenger/native';
export class NotificationService {
notificationPermission: NotificationPermission;
constructor() {
this.notificationPermission = this.isSupported() ? 'default' : 'denied';
}
public isSupported(): boolean {
return 'Notification' in window;
}
requestPermission(): void {
const self = this;
if ('Notification' in window) {
Notification.requestPermission().then(result => {
self.notificationPermission = result;
});
}
}
notify(noti: NotificationRequest) {
const notification = new Notification(noti.title, { body: noti.contents });
notification.onclick = e => {
console.log('notification.onclick');
};
notification.onclose = e => {
console.log('notification.onclose');
};
notification.onerror = e => {
console.log('notification.onerror');
};
}
}