snapdrop

A Progressive Web App for local file sharing
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

commit ce61dc7c60a9bb80c046bb2fa2cbfa7fc9d12bcd
parent ddee78fe192a6505b3dc8c1b33a310972a5f3582
Author: Robin Linus <robin_woll@capira.de>
Date:   Sat,  2 Jan 2016 14:19:11 +0100

Add sound notifications

Diffstat:
MREADME.md | 5+++++
Aapp/elements/sound-notification/sound-notification-behavior.html | 24++++++++++++++++++++++++
Aapp/elements/sound-notification/sound-notification.html | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aapp/sounds/blop.mp3 | 0
Aapp/sounds/blop.ogg | 0
5 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -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) +\ No newline at end of file diff --git a/app/elements/sound-notification/sound-notification-behavior.html b/app/elements/sound-notification/sound-notification-behavior.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> diff --git a/app/elements/sound-notification/sound-notification.html b/app/elements/sound-notification/sound-notification.html @@ -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> diff --git a/app/sounds/blop.mp3 b/app/sounds/blop.mp3 Binary files differ. diff --git a/app/sounds/blop.ogg b/app/sounds/blop.ogg Binary files differ.