2015-10-04 13:01:59 +00:00
|
|
|
class SoundController {
|
|
|
|
constructor () {
|
|
|
|
if (Howl === undefined) {
|
|
|
|
throw new Error("Howl.js required to created sound controller");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.MINIMUM_PLAY_INTERVAL = 120000;
|
|
|
|
|
|
|
|
this.playGatherMusic = _.throttle(() => {
|
|
|
|
this.gather.music.play();
|
|
|
|
}, this.MINIMUM_PLAY_INTERVAL);
|
|
|
|
|
|
|
|
this.isMuted = Howler._muted;
|
|
|
|
|
|
|
|
this.volume = Howler._volume;
|
|
|
|
|
|
|
|
this.tunes = {
|
|
|
|
"classic": {
|
|
|
|
description: "Classic",
|
|
|
|
url: 'http://www.ensl.org/sounds/gather-1.mp3'
|
|
|
|
},
|
|
|
|
"eyeofthegorgie": {
|
|
|
|
description: "Eye of the Gorgie",
|
|
|
|
url: 'http://www.ensl.org/files/audio/eyeofthegorgie.mp3'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setupGatherMusic("classic");
|
|
|
|
}
|
|
|
|
|
|
|
|
volume(val) {
|
|
|
|
if (typeof val === 'number' && Math.abs(val) <= 1) {
|
|
|
|
this.volume = val;
|
|
|
|
return Howler.volume(val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mute() {
|
|
|
|
this.isMuted = true;
|
|
|
|
return Howler.mute();
|
|
|
|
}
|
|
|
|
|
|
|
|
unMute() {
|
|
|
|
this.isMuted = false;
|
|
|
|
return Howler.unmute();
|
|
|
|
}
|
|
|
|
|
|
|
|
play(music) {
|
|
|
|
if (this.gather && this.gather.music) return this.gather.music.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
stop(music) {
|
|
|
|
if (this.gather && this.gather.music) return this.gather.music.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
setupGatherMusic (musicName) {
|
|
|
|
let self = this;
|
|
|
|
let gatherMusic = this.tunes[musicName];
|
|
|
|
|
|
|
|
if (!gatherMusic) return;
|
|
|
|
if (self.gather && self.gather.name === musicName) return;
|
|
|
|
|
|
|
|
// Stop if already playing
|
|
|
|
if (self.gather && self.gather.music) {
|
|
|
|
self.gather.music.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
let tune = self.tunes[musicName];
|
|
|
|
self.gather = {
|
|
|
|
name: musicName,
|
|
|
|
description: tune.description,
|
|
|
|
url: tune.url,
|
|
|
|
music: new Howl({
|
|
|
|
urls: [tune.url]
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-27 16:54:34 +00:00
|
|
|
var SoundPanel = React.createClass({
|
|
|
|
mute() {
|
2015-10-02 14:53:11 +00:00
|
|
|
this.props.soundController.mute();
|
2015-08-27 16:54:34 +00:00
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
unMute() {
|
2015-10-02 14:53:11 +00:00
|
|
|
this.props.soundController.unMute();
|
2015-08-27 16:54:34 +00:00
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2015-10-02 14:53:11 +00:00
|
|
|
let soundController = this.props.soundController;
|
2015-08-27 16:54:34 +00:00
|
|
|
if (soundController.isMuted) {
|
|
|
|
return (
|
|
|
|
<li>
|
|
|
|
<a href="#" onClick={this.unMute}>
|
2015-09-17 11:40:11 +00:00
|
|
|
Muted <i className="fa fa-volume-off fa-fw"></i>
|
2015-08-27 16:54:34 +00:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<li>
|
|
|
|
<a href="#" onClick={this.mute}>
|
2015-09-17 11:40:11 +00:00
|
|
|
Unmuted <i className="fa fa-volume-up fa-fw"></i>
|
2015-08-27 16:54:34 +00:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2015-10-02 14:53:11 +00:00
|
|
|
});
|