Skip to content

Commit

Permalink
feature: #1
Browse files Browse the repository at this point in the history
 - adds sound on timer
 - on (3,2,1) one click
 - on 0 two clicks
  • Loading branch information
michilehr committed Mar 8, 2018
1 parent 7d17906 commit 855edb8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from "react";
import Control from "./Components/Control/Control";
import Content from "./Components/Content/Content";
import NoSleep from "./Components/NoSleep/NoSleep";
import AudioNotification from "./Components/AudioNotification/AudioNotification";

class App extends React.Component {

Expand Down Expand Up @@ -148,6 +149,10 @@ class App extends React.Component {
onClickPlay={this.start}
/>
<NoSleep ref={(noSleep) => { this._noSleep = noSleep; }} />
<AudioNotification
timer={this.state.timer}
currentMode={this.state.currentMode}
/>
</div>
</div>
)
Expand Down
42 changes: 42 additions & 0 deletions src/App/Components/AudioNotification/AudioNotification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";

import audioPipe from './Media/Pipes.ogg';

const audio = new Audio(audioPipe);

class AudioNotification extends React.Component {

sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async playPipe(double = false) {
audio.play();

if (double) {
await this.sleep(125);
audio.cloneNode().play();
}
}

render() {
const {
currentMode,
timer,
} = this.props;

const playModes = ['delay', 'start', 'rest'];

if (playModes.includes(currentMode)) {
if (timer === 0) {
this.playPipe(true);
} else if (timer <= 3) {
this.playPipe();
}
}

return (null)
}
}

export default AudioNotification;
Binary file not shown.

0 comments on commit 855edb8

Please sign in to comment.