Sounds: subtler sounds

This change sets different sounds to different volume levels, and
replaces the Play sound with one that sounds different than the Add
sound.
This commit is contained in:
Feross Aboukhadijeh
2016-03-23 20:44:40 -07:00
parent 1f2985bbc3
commit 4895fb930c
3 changed files with 48 additions and 21 deletions

View File

@@ -25,14 +25,38 @@ module.exports = {
ROOT_PATH: __dirname, ROOT_PATH: __dirname,
STATIC_PATH: path.join(__dirname, 'static'), STATIC_PATH: path.join(__dirname, 'static'),
SOUND_ADD: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'), SOUND_ADD: {
SOUND_DELETE: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'), url: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'),
SOUND_DISABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'), volume: 0.2
SOUND_DONE: 'file://' + path.join(__dirname, 'static', 'sound', 'done.wav'), },
SOUND_ENABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'enable.wav'), SOUND_DELETE: {
SOUND_ERROR: 'file://' + path.join(__dirname, 'static', 'sound', 'error.wav'), url: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'),
SOUND_PLAY: 'file://' + path.join(__dirname, 'static', 'sound', 'play.wav'), volume: 0.1
SOUND_STARTUP: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav') },
SOUND_DISABLE: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'),
volume: 0.2
},
SOUND_DONE: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'done.wav'),
volume: 0.2
},
SOUND_ENABLE: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'enable.wav'),
volume: 0.2
},
SOUND_ERROR: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'error.wav'),
volume: 0.2
},
SOUND_PLAY: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'play.wav'),
volume: 0.2
},
SOUND_STARTUP: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav'),
volume: 0.4
}
} }
function isProduction () { function isProduction () {

View File

@@ -131,7 +131,7 @@ function init () {
// Done! Ideally we want to get here <100ms after the user clicks the app // Done! Ideally we want to get here <100ms after the user clicks the app
document.querySelector('.loading').remove() /* TODO: no spinner once fast enough */ document.querySelector('.loading').remove() /* TODO: no spinner once fast enough */
playInterfaceSound(config.SOUND_STARTUP) playInterfaceSound('STARTUP')
console.timeEnd('init') console.timeEnd('init')
} }
@@ -423,7 +423,7 @@ function addTorrentToList (torrent) {
infoHash: torrent.infoHash infoHash: torrent.infoHash
}) })
saveState() saveState()
playInterfaceSound(config.SOUND_ADD) playInterfaceSound('ADD')
} }
} }
@@ -667,13 +667,13 @@ function stopServer () {
// Opens the video player // Opens the video player
function openPlayer (torrentSummary, index, cb) { function openPlayer (torrentSummary, index, cb) {
var torrent = state.client.get(torrentSummary.infoHash) var torrent = state.client.get(torrentSummary.infoHash)
if (!torrent || !torrent.done) playInterfaceSound(config.SOUND_PLAY) if (!torrent || !torrent.done) playInterfaceSound('PLAY')
torrentSummary.playStatus = 'requested' torrentSummary.playStatus = 'requested'
update() update()
var timeout = setTimeout(function () { var timeout = setTimeout(function () {
torrentSummary.playStatus = 'timeout' /* no seeders available? */ torrentSummary.playStatus = 'timeout' /* no seeders available? */
playInterfaceSound(config.SOUND_ERROR) playInterfaceSound('ERROR')
update() update()
}, 10000) /* give it a few seconds */ }, 10000) /* give it a few seconds */
@@ -681,7 +681,7 @@ function openPlayer (torrentSummary, index, cb) {
clearTimeout(timeout) clearTimeout(timeout)
if (err) { if (err) {
torrentSummary.playStatus = 'unplayable' torrentSummary.playStatus = 'unplayable'
playInterfaceSound(config.SOUND_ERROR) playInterfaceSound('ERROR')
update() update()
return onError(err) return onError(err)
} }
@@ -741,11 +741,11 @@ function toggleTorrent (torrentSummary) {
if (torrentSummary.status === 'paused') { if (torrentSummary.status === 'paused') {
torrentSummary.status = 'new' torrentSummary.status = 'new'
startTorrentingSummary(torrentSummary) startTorrentingSummary(torrentSummary)
playInterfaceSound(config.SOUND_ENABLE) playInterfaceSound('ENABLE')
} else { } else {
torrentSummary.status = 'paused' torrentSummary.status = 'paused'
stopTorrenting(torrentSummary.infoHash) stopTorrenting(torrentSummary.infoHash)
playInterfaceSound(config.SOUND_DISABLE) playInterfaceSound('DISABLE')
} }
} }
@@ -758,7 +758,7 @@ function deleteTorrent (torrentSummary) {
if (index > -1) state.saved.torrents.splice(index, 1) if (index > -1) state.saved.torrents.splice(index, 1)
saveState() saveState()
state.location.clearForward() // prevent user from going forward to a deleted torrent state.location.clearForward() // prevent user from going forward to a deleted torrent
playInterfaceSound(config.SOUND_DELETE) playInterfaceSound('DELETE')
} }
function toggleSelectTorrent (infoHash) { function toggleSelectTorrent (infoHash) {
@@ -812,7 +812,7 @@ function restoreBounds () {
function onError (err) { function onError (err) {
console.error(err.stack || err) console.error(err.stack || err)
playInterfaceSound(config.SOUND_ERROR) playInterfaceSound('ERROR')
state.errors.push({ state.errors.push({
time: new Date().getTime(), time: new Date().getTime(),
message: err.message || err message: err.message || err
@@ -836,12 +836,15 @@ function showDoneNotification (torrent) {
window.focus() window.focus()
} }
playInterfaceSound(config.SOUND_DONE) playInterfaceSound('DONE')
} }
function playInterfaceSound (url) { function playInterfaceSound (name) {
var sound = config[`SOUND_${name}`]
if (!sound) throw new Error('Invalid sound name')
var audio = new window.Audio() var audio = new window.Audio()
audio.volume = 0.3 audio.volume = sound.volume
audio.src = url audio.src = sound.url
audio.play() audio.play()
} }

Binary file not shown.