From d4c17bf132167fe1bd9a110daff46ed5ba368f37 Mon Sep 17 00:00:00 2001 From: TamasGorgics Date: Tue, 9 Jul 2019 23:25:23 +0200 Subject: [PATCH 1/2] Add sound effect to notification --- src/state/epics/timerEpics.ts | 3 +++ src/utils/notifications.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/state/epics/timerEpics.ts b/src/state/epics/timerEpics.ts index 1385bc0..2aeeedc 100644 --- a/src/state/epics/timerEpics.ts +++ b/src/state/epics/timerEpics.ts @@ -14,6 +14,8 @@ import timer from '../../assets/timer.svg' type EpicType = Epic const { stopTimer, countDownFinished, countDownOneSecond } = timerActions +const soundEffect = new Audio('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3') + export const startTimerEpic: EpicType = action$ => action$.pipe( filter(isOfType(START_TIMER)), @@ -49,6 +51,7 @@ export const alertEpic: EpicType = (action$, state$) => badge: timer, icon: timer, vibrate: [2000, 2000, 2000], + sound: soundEffect, }), ] }), diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index 56ce554..7f2ce7a 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -9,6 +9,7 @@ interface INotificationOptions { lang?: string tag?: string vibrate?: number[] + sound?: HTMLAudioElement onClose?: (e: Event) => any } @@ -21,6 +22,8 @@ export function requestPermission() { export function notify(title: string, options?: INotificationOptions) { const notification = new Notification(title, options) + if (options && options.sound) options.sound.play().then().catch() + notification.onclick = () => { notification.close() } From e7642c777dc7299ca84ecb2b6f03957de6942492 Mon Sep 17 00:00:00 2001 From: TamasGorgics Date: Wed, 10 Jul 2019 00:02:40 +0200 Subject: [PATCH 2/2] - Capitalize constant variable name - Add tslint ignore for floating promise --- src/state/epics/timerEpics.ts | 4 ++-- src/utils/notifications.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/state/epics/timerEpics.ts b/src/state/epics/timerEpics.ts index 2aeeedc..9acff94 100644 --- a/src/state/epics/timerEpics.ts +++ b/src/state/epics/timerEpics.ts @@ -14,7 +14,7 @@ import timer from '../../assets/timer.svg' type EpicType = Epic const { stopTimer, countDownFinished, countDownOneSecond } = timerActions -const soundEffect = new Audio('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3') +const SOUND_EFFECT = new Audio('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3') export const startTimerEpic: EpicType = action$ => action$.pipe( @@ -51,7 +51,7 @@ export const alertEpic: EpicType = (action$, state$) => badge: timer, icon: timer, vibrate: [2000, 2000, 2000], - sound: soundEffect, + sound: SOUND_EFFECT, }), ] }), diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index 7f2ce7a..4e397ee 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -22,7 +22,8 @@ export function requestPermission() { export function notify(title: string, options?: INotificationOptions) { const notification = new Notification(title, options) - if (options && options.sound) options.sound.play().then().catch() + // tslint:disable-next-line: no-floating-promises + if (options && options.sound) options.sound.play() notification.onclick = () => { notification.close()