Skip to content

Commit

Permalink
play notification sound when estimated time is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
entorb committed Oct 14, 2023
1 parent c6c4ea7 commit 9c40ccb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ src/lib/
.DS_Store
src/1.js
src/2.js
src/audio/*.wav
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ GitHub Actions are used to perform automated code quality checks upon PR creatio

Spell checking via CSpell
See `spelling.json` for custom dictionary

## Credits

* the notification sound `481151__matrixxx__cow-bells-01.wav` is from [freesound.org](https://freesound.org/people/MATRIXXX_/sounds/481151/)
1 change: 1 addition & 0 deletions scripts/sync_to_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cd $script_dir/..
rsync -rvhu --delete --no-perms --exclude *.test.js src/*.js entorb@entorb.net:html/eta/
rsync -rvhu --delete --no-perms src/*.html entorb@entorb.net:html/eta/
rsync -rvhu --delete --no-perms src/*.css entorb@entorb.net:html/eta/
rsync -rvhu --delete --no-perms src/audio/*.mp3 entorb@entorb.net:html/eta/audio/
Binary file added src/audio/481151__matrixxx__cow-bells-01.mp3
Binary file not shown.
20 changes: 20 additions & 0 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ function read_html_input_number(html_input) {
return Number(value_str);
}

/**
* play a sound of mp3 format
* @param {*} url of mp3 sound file
*/
function playSound(url) {
const audio = new Audio(url);
audio.play();
}

/**
* Play sound file for timer done
*/
function playSoundTimerDone() {
playSound('audio/481151__matrixxx__cow-bells-01.mp3');
}



// Export functions, needed for Jest unittests
// Using this hack it works for both, jest and browser.
// from https://stackoverflow.com/questions/66349868/jest-unit-testing-module-export-error-in-browser-console
Expand All @@ -295,4 +313,6 @@ module.exports = {
calc_row_new_delta,
sort_data,
read_html_input_number,
playSound,
playSoundTimerDone,
};
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ prevent entering non-numbers
add delta1
html placeholders
weighted linreg instead, to put more weight on the latest items
play notification sound when estimated time is reached
TODO/IDEAS
chart: choose to display remaining instead of items
tabulator: use global data, and update column speed name upon switching unit
echarts: use global data, and update speed unit
store "hide_intro" as setting
add simple time-only countdown+notification
*/

//
Expand Down Expand Up @@ -178,6 +181,7 @@ function update_runtime_and_remaining() {
let ms_remaining = total_timestamp_eta - Date.now();
if (ms_remaining < 0) {
ms_remaining = 0;
playSoundTimerDone();
// stop timer
clearInterval(interval_auto_refresh);
}
Expand Down

0 comments on commit 9c40ccb

Please sign in to comment.