Skip to content

Commit 832580c

Browse files
committed
Merge pull request #14 from georgeOsdDev/feature/sound
#13 Add Notification.sound example
2 parents 5ba84a3 + 5725dac commit 832580c

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,12 @@ npm run start:example
7878

7979
```bash
8080
npm test
81-
```
81+
```
82+
83+
84+
### Known Issues
85+
86+
* [Notification.sound](https://github.com/georgeOsdDev/react-web-notification/issues/13)
87+
`Notification.sound` is [not supported in any browser](https://developer.mozilla.org/en/docs/Web/API/notification/sound#Browser_compatibility).
88+
You can emulate it with `onShow` callback. see [example](https://github.com/georgeOsdDev/react-web-notification/tree/develop/example).
89+

example/app.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ class App extends React.Component {
4848
}
4949

5050
handleNotificationOnShow(e, tag){
51+
this.playSound();
5152
console.log(e, 'Notification shown tag:' + tag);
5253
}
5354

55+
playSound(filename){
56+
document.getElementById('sound').play();
57+
}
58+
5459
handleButtonClick() {
5560

5661
if(this.state.ignore) {
@@ -72,7 +77,8 @@ class App extends React.Component {
7277
body: body,
7378
icon: icon,
7479
lang: 'en',
75-
dir: 'ltr'
80+
dir: 'ltr',
81+
sound: './sound.mp3' // no browsers supported https://developer.mozilla.org/en/docs/Web/API/notification/sound#Browser_compatibility
7682
}
7783
this.setState({
7884
title: title,
@@ -98,6 +104,11 @@ class App extends React.Component {
98104
title={this.state.title}
99105
options={this.state.options}
100106
/>
107+
<audio id='sound' preload='auto'>
108+
<source src='./sound.mp3' type='audio/mpeg' />
109+
<source src='./sound.ogg' type='audio/ogg' />
110+
<embed hidden='true' autostart='false' loop='false' src='./sound.mp3' />
111+
</audio>
101112
</div>
102113
)
103114
}

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css" rel="stylesheet">
77
</head>
88
<body>
9-
<a href="https://github.com/georgeosdev/react-web-notification"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
9+
<a href="https://github.com/georgeosddev/react-web-notification"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
1010
<div id="out" style="margin: 40px;"></div>
1111
<small>Icons made by <a href="http://www.flaticon.com/authors/google" title="Google">Google</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0">CC BY 3.0</a></small>
1212
<!--[if lt IE 9]>

example/sound.mp3

30.8 KB
Binary file not shown.

example/sound.ogg

32.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)