Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

Commit 095e050

Browse files
Tamás GörgicsAdam Haglund
authored andcommitted
Add Sound Effect to Notification (#59)
* Add sound effect to notification * - Capitalize constant variable name - Add tslint ignore for floating promise
1 parent 6ed2e35 commit 095e050

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/state/epics/timerEpics.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import timer from '../../assets/timer.svg'
1414
type EpicType = Epic<IRootActions, IRootActions, IRootState>
1515
const { stopTimer, countDownFinished, countDownOneSecond } = timerActions
1616

17+
const SOUND_EFFECT = new Audio('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3')
18+
1719
export const startTimerEpic: EpicType = action$ =>
1820
action$.pipe(
1921
filter(isOfType(START_TIMER)),
@@ -49,6 +51,7 @@ export const alertEpic: EpicType = (action$, state$) =>
4951
badge: timer,
5052
icon: timer,
5153
vibrate: [2000, 2000, 2000],
54+
sound: SOUND_EFFECT,
5255
}),
5356
]
5457
}),

src/utils/notifications.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface INotificationOptions {
99
lang?: string
1010
tag?: string
1111
vibrate?: number[]
12+
sound?: HTMLAudioElement
1213
onClose?: (e: Event) => any
1314
}
1415

@@ -21,6 +22,9 @@ export function requestPermission() {
2122
export function notify(title: string, options?: INotificationOptions) {
2223
const notification = new Notification(title, options)
2324

25+
// tslint:disable-next-line: no-floating-promises
26+
if (options && options.sound) options.sound.play()
27+
2428
notification.onclick = () => {
2529
notification.close()
2630
}

0 commit comments

Comments
 (0)