Add sound notifications
This commit is contained in:
parent
ddee78fe19
commit
ce61dc7c60
5 changed files with 83 additions and 0 deletions
|
@ -52,3 +52,7 @@ ShareDrop uses WebRTC only and isn't compatible with Safari Browsers. Snapdrop u
|
|||
* `npm install & bower install`
|
||||
* run `gulp serve`
|
||||
* In a second shell run `node index.js`
|
||||
|
||||
|
||||
## Licences
|
||||
* Thanks to [Mark DiAngelo]() for the [Blop Sound](http://soundbible.com/2067-Blop.html)
|
|
@ -0,0 +1,24 @@
|
|||
<link rel="import" href="sound-notification.html">
|
||||
<script>
|
||||
'use strict';
|
||||
Chat = window.Chat || {};
|
||||
Chat.SoundNotificationBehavior = {
|
||||
sounds: function() {
|
||||
var sounds = document.querySelector('sound-notification');
|
||||
if (!sounds) {
|
||||
sounds = Polymer.Base.create('sound-notification');
|
||||
document.body.appendChild(sounds);
|
||||
}
|
||||
return sounds;
|
||||
},
|
||||
attached: function() {
|
||||
//lazy load sound files
|
||||
setTimeout(function() {
|
||||
this.sounds();
|
||||
}.bind(this), 1000);
|
||||
},
|
||||
playSound: function(e) {
|
||||
this.sounds().play();
|
||||
}
|
||||
};
|
||||
</script>
|
55
app/elements/sound-notification/sound-notification.html
Normal file
55
app/elements/sound-notification/sound-notification.html
Normal file
|
@ -0,0 +1,55 @@
|
|||
<dom-module id="sound-notification">
|
||||
<template>
|
||||
<audio id="blop" preload="auto" autobuffer="true">
|
||||
<source src="/sounds/blop.mp3" id="mp3Source" type="audio/mpeg">
|
||||
<source src="/sounds/blop.ogg" id="oggSource" type="audio/ogg">
|
||||
</audio>
|
||||
</template>
|
||||
</dom-module>
|
||||
<script>
|
||||
'use strict';
|
||||
Polymer({
|
||||
is: 'sound-notification',
|
||||
properties: {
|
||||
volumes: {
|
||||
value: {
|
||||
'blop': 0.8,
|
||||
}
|
||||
}
|
||||
},
|
||||
attached: function() {
|
||||
var that = this;
|
||||
var hackListener = function() {
|
||||
that.volumes.blop = 0.1;
|
||||
that.play();
|
||||
document.body.removeEventListener('touchstart', hackListener, false);
|
||||
that.volumes.blop = 0.8;
|
||||
};
|
||||
document.body.addEventListener('touchstart', hackListener, false);
|
||||
},
|
||||
play: function() {
|
||||
this._play('blop');
|
||||
},
|
||||
_play: function(sound) {
|
||||
var audio = this.$[sound];
|
||||
if (!audio) {
|
||||
console.warn('audio ', sound, ' doesn\'t exist.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (audio.readyState > 0) {
|
||||
audio.volume = this.volumes[sound];
|
||||
audio.pause();
|
||||
audio.currentTime = 0;
|
||||
audio.play();
|
||||
} else {
|
||||
console.warn('audio not ready yet...');
|
||||
//play when ready
|
||||
//TODO: play only if ready within next ~500ms
|
||||
audio.addEventListener('loadedmetadata', function() {
|
||||
this._play(sound);
|
||||
}.bind(this), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
BIN
app/sounds/blop.mp3
Executable file
BIN
app/sounds/blop.mp3
Executable file
Binary file not shown.
BIN
app/sounds/blop.ogg
Normal file
BIN
app/sounds/blop.ogg
Normal file
Binary file not shown.
Loading…
Reference in a new issue