2023-11-13 16:19:09 -05:00
|
|
|
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
|
|
|
|
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
|
|
|
|
|
|
|
const speakerIcons = {
|
|
|
|
101: 'audio-volume-overamplified-symbolic',
|
|
|
|
67: 'audio-volume-high-symbolic',
|
|
|
|
34: 'audio-volume-medium-symbolic',
|
|
|
|
1: 'audio-volume-low-symbolic',
|
|
|
|
0: 'audio-volume-muted-symbolic',
|
|
|
|
};
|
|
|
|
|
|
|
|
const micIcons = {
|
|
|
|
67: 'audio-input-microphone-high-symbolic',
|
|
|
|
34: 'audio-input-microphone-medium-symbolic',
|
|
|
|
1: 'audio-input-microphone-low-symbolic',
|
|
|
|
0: 'audio-input-microphone-muted-symbolic',
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
export const SpeakerIcon = Variable('');
|
2023-11-13 16:19:09 -05:00
|
|
|
Audio.connect('speaker-changed', () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (!Audio.speaker) {
|
2023-11-13 16:19:09 -05:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-13 16:19:09 -05:00
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
if (Audio.speaker.stream.is_muted) {
|
2023-11-13 16:19:09 -05:00
|
|
|
SpeakerIcon.value = speakerIcons[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const vol = Audio.speaker.volume * 100;
|
|
|
|
|
|
|
|
for (const threshold of [-1, 0, 33, 66, 100]) {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (vol > threshold + 1) {
|
2023-11-13 16:19:09 -05:00
|
|
|
SpeakerIcon.value = speakerIcons[threshold + 1];
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-13 16:19:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
export const MicIcon = Variable('');
|
2023-11-13 16:19:09 -05:00
|
|
|
Audio.connect('microphone-changed', () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (!Audio.microphone) {
|
2023-11-13 16:19:09 -05:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-13 16:19:09 -05:00
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
if (Audio.microphone.stream.is_muted) {
|
2023-11-13 16:19:09 -05:00
|
|
|
MicIcon.value = micIcons[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const vol = Audio.microphone.volume * 100;
|
|
|
|
|
|
|
|
for (const threshold of [-1, 0, 33, 66]) {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (vol > threshold + 1) {
|
2023-11-13 16:19:09 -05:00
|
|
|
MicIcon.value = micIcons[threshold + 1];
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-13 16:19:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|