mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Update audiomanager.ts
fix: Audio menu frequencies list not working, radios reset when changing input/output
This commit is contained in:
parent
5d274a3efb
commit
874e01b031
@ -2,7 +2,7 @@ import { AudioManagerState, AudioMessageType, BLUE_COMMANDER, GAME_MASTER, Olymp
|
||||
import { MicrophoneSource } from "./microphonesource";
|
||||
import { RadioSink } from "./radiosink";
|
||||
import { getApp } from "../olympusapp";
|
||||
import { coalitionToEnum, makeID } from "../other/utils";
|
||||
import { coalitionToEnum, deepCopyTable, makeID } from "../other/utils";
|
||||
import { FileSource } from "./filesource";
|
||||
import { AudioSource } from "./audiosource";
|
||||
import { Buffer } from "buffer";
|
||||
@ -465,7 +465,9 @@ export class AudioManager {
|
||||
if (this.#devices.includes(input)) {
|
||||
this.#input = input;
|
||||
AudioManagerInputChangedEvent.dispatch(input);
|
||||
let sessionData = deepCopyTable(getApp().getSessionDataManager().getSessionData());
|
||||
this.stop();
|
||||
getApp().getSessionDataManager().setSessionData(sessionData);
|
||||
this.start();
|
||||
this.#options.input = input.deviceId;
|
||||
AudioOptionsChangedEvent.dispatch(this.#options);
|
||||
@ -478,8 +480,11 @@ export class AudioManager {
|
||||
if (this.#devices.includes(output)) {
|
||||
this.#input = output;
|
||||
AudioManagerOutputChangedEvent.dispatch(output);
|
||||
let sessionData = deepCopyTable(getApp().getSessionDataManager().getSessionData());
|
||||
this.stop();
|
||||
getApp().getSessionDataManager().setSessionData(sessionData);
|
||||
this.start();
|
||||
|
||||
this.#options.output = output.deviceId;
|
||||
AudioOptionsChangedEvent.dispatch(this.#options);
|
||||
} else {
|
||||
|
||||
@ -187,6 +187,12 @@ export class SessionDataManager {
|
||||
return this.#sessionData;
|
||||
}
|
||||
|
||||
setSessionData(sessionData: SessionData) {
|
||||
this.#sessionData = sessionData;
|
||||
|
||||
this.#saveSessionData();
|
||||
}
|
||||
|
||||
#saveSessionData() {
|
||||
if (getApp().getState() === OlympusState.SERVER) return;
|
||||
|
||||
|
||||
@ -281,7 +281,7 @@ export function AudioMenu(props: { open: boolean; onClose: () => void; children?
|
||||
|
||||
/* Count how many radios have a non null frequency */
|
||||
const activeRadios = clientData.radios.reduce((acc, radio) => {
|
||||
if (radio.frequency > 10) acc++;
|
||||
if (radio.frequency > 1000) acc++;
|
||||
return acc;
|
||||
}, 0);
|
||||
|
||||
@ -299,10 +299,23 @@ export function AudioMenu(props: { open: boolean; onClose: () => void; children?
|
||||
<div className="my-auto truncate text-gray-400">{clientData.name}</div>
|
||||
<OlDropdown label={"Tuned radios: " + activeRadios}>
|
||||
{clientData.radios.map((radio, idx) => {
|
||||
return radio.frequency > 10 ?
|
||||
return radio.frequency > 1000 ?
|
||||
(
|
||||
<OlDropdownItem key={idx}>
|
||||
<div className="flex gap-2 text-white">
|
||||
<div className="flex gap-2 text-white" onClick={() => {
|
||||
// Find if any radio is already tuned to this frequency
|
||||
const alreadyTuned = sinks.find((sink) => {
|
||||
if (sink instanceof RadioSink) {
|
||||
return sink.getFrequency() === radio.frequency && sink.getModulation() === radio.modulation;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (!alreadyTuned) {
|
||||
let newRadio = getApp().getAudioManager().addRadio();
|
||||
newRadio.setFrequency(radio.frequency);
|
||||
newRadio.setModulation(radio.modulation);
|
||||
}
|
||||
}}>
|
||||
{`${zeroAppend(radio.frequency / 1e6, 3, true, 3)} ${radio.modulation ? "FM" : "AM"}`}
|
||||
</div>
|
||||
</OlDropdownItem>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user