-
Notifications
You must be signed in to change notification settings - Fork 12
/
sound.js
83 lines (65 loc) · 1.43 KB
/
sound.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
import { Howl, Howler } from 'howler';
import { createSoundPlayer } from './sound-player';
export { AudioOutput };
function AudioOutput(audioData) {
return new Sound(audioData);
}
const BONG_SOUND = [ FETCHURL + 'sound/boing.mp3' ];
const NO_SOUND = {
url: [],
sample: {},
sprite: {},
};
class Sound {
constructor(audioData = NO_SOUND) {
Howler.unload();
this.bong = new Howl({
volume: 1.0,
src: BONG_SOUND,
});
this.player = createSoundPlayer(audioData);
}
callback(message = {}) {
switch (message.command) {
case 'PLAYSAMPLE': {
this.player.playId(message.id);
break;
}
case 'MAINVOLUME': {
const volume = (message.value / 31);
this.setVolume(volume);
break;
}
case 'STOPSOUND':
this.player.stopAll();
break;
case 'CHANNELOFF':
console.log('CHANNELOFF_NOT_IMPLEMENTED YET', message.channel);
break;
default:
console.log('NOT_IMPLEMENTED YET', message.command);
break;
}
}
playBootSound() {
console.log('playbootsound');
this.bong.play();
}
setVolume(floatVolume) {
console.log('SET MAINVOLUME', floatVolume);
Howler.volume(floatVolume);
}
stop() {
this.player.stopAll();
}
pause() {
this.player.pause();
}
resume() {
this.player.resume();
}
getState() {
return this.player.soundState;
}
}