Skip to content

Commit 36ee2b3

Browse files
committed
Ability to configure volume of announcer from frontend
1 parent 141deb0 commit 36ee2b3

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ A preview of major changes can be found in the Wiki ([Latest Changes](https://gi
88
- New "Explore" tab on player statistics, to explore darts thrown
99
- Support for `ANY` and `MASTER` outs for `x01` legs
1010
- Simplified input for `x01` legs
11+
- Ability to configure volume of announcer from frontend
1112

1213
#### Changed
1314
- Updated to use `Node.js v18`

src/components/navbar/components/configure-kcapp-modal/configure-kcapp-modal.component.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@ const localStorage = require('../../../../util/localstorage');
33
module.exports = {
44
onCreate(input) {
55
this.state = {
6-
buttonLayout: "wide"
6+
buttonLayout: "wide",
7+
volume: 100
78
}
89
},
910
onMount() {
1011
const buttonLayout = localStorage.get("button-layout");
1112
if (buttonLayout) {
1213
this.state.buttonLayout = buttonLayout
1314
}
15+
16+
const volume = localStorage.get("volume");
17+
if (volume) {
18+
this.state.volume = Math.min(Math.max(parseInt(volume * 100), 0), 100);
19+
}
1420
},
1521
onSave() {
1622
this.state.buttonLayout = document.getElementById("buttonLayout").value;
1723
localStorage.set('button-layout', this.state.buttonLayout);
1824
},
25+
updateVolume(event, selected) {
26+
this.state.volume = selected.value;
27+
localStorage.set('volume', this.state.volume / 100);
28+
},
1929
}

src/components/navbar/components/configure-kcapp-modal/configure-kcapp-modal.marko

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@
1919
</div>
2020
</div>
2121
</div>
22+
<div>
23+
<div class="block-container-header">
24+
<span>Announcer Volume</span>
25+
</div>
26+
<div class="block-container-with-header">
27+
<div class="form-group">
28+
<label for="volumeSlider">Set Volume: <span id="volumeValue">${state.volume}</span>%</label>
29+
<input type="range" id="volumeSlider" class="form-range" min="0" max="100" value=`${state.volume}` on-input("updateVolume")>
30+
</div>
31+
</div>
32+
</div>
2233
</div>
2334
<div class="modal-footer">
2435
<button class="btn btn-primary" type="button" on-click("onSave") data-dismiss="modal">Save</button>
2536
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
2637
</div>
2738
</div>
2839
</div>
29-
</div>
40+
</div>

src/util/socket.io-helper.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const io = require('socket.io-client');
33
const alertify = require('./alertify');
44
const speaker = require('./speaker');
55
const types = require('../components/scorecard/components/match_types');
6+
const localStorage = require('./localstorage');
67

78
exports.connect = (url) => {
89
const socket = io(url);
@@ -84,12 +85,17 @@ exports.say = (data, thiz) => {
8485
return;
8586
}
8687

88+
let volume = localStorage.get("volume");
89+
volume = volume ? Math.min(Math.max(parseFloat(volume), 0.0), 1.0) : 1.0;
90+
8791
const oldPlayer = thiz.state.audioAnnouncer;
8892
const isAudioAnnouncement = (oldPlayer.duration > 0 && !oldPlayer.paused) || (!isNaN(oldPlayer.duration) && !oldPlayer.ended && oldPlayer.paused);
8993
if (data.audios) {
9094
const audioPlayers = [ ];
9195
for (const file of data.audios) {
92-
audioPlayers.push(file.file ? new Audio(file.file) : speaker.getUtterance(file));
96+
const audioPlayer = file.file ? new Audio(file.file) : speaker.getUtterance(file);
97+
audioPlayer.volume = volume;
98+
audioPlayers.push(audioPlayer);
9399
}
94100

95101
for (let i = 0; i < audioPlayers.length; i++) {

0 commit comments

Comments
 (0)