2024-01-30 11:29:07 -05:00
|
|
|
const Audio = await Service.import('audio');
|
2023-11-13 16:19:09 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
if (Audio.speaker.stream?.is_muted) {
|
2024-02-11 02:18:59 -05:00
|
|
|
SpeakerIcon.setValue(speakerIcons[0]);
|
2023-11-13 16:19:09 -05:00
|
|
|
}
|
|
|
|
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) {
|
2024-02-11 02:18:59 -05:00
|
|
|
SpeakerIcon.setValue(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
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
if (Audio.microphone.stream?.is_muted) {
|
2024-02-11 02:18:59 -05:00
|
|
|
MicIcon.setValue(micIcons[0]);
|
2023-11-13 16:19:09 -05:00
|
|
|
}
|
|
|
|
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) {
|
2024-02-11 02:18:59 -05:00
|
|
|
MicIcon.setValue(micIcons[threshold + 1]);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-13 16:19:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|