Skip to content

Commit

Permalink
fix announcements and train map
Browse files Browse the repository at this point in the history
  • Loading branch information
Phipsiart committed Sep 28, 2024
1 parent 7a42102 commit 76e6fc8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 62 deletions.
120 changes: 59 additions & 61 deletions components/BOB/BOBAnsagen.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,94 @@
'use client';
import { useEffect, useRef } from 'react';
import { useEffect, useRef, useState } from 'react';

const BOBAnsagen = ({ conditionString, IBNR, audiourl }) => {
const germanAudioRef = useRef(null);
const germanGoodbyeRef = useRef(null);
const englishAudioRef = useRef(null);
const germanGoodbyeRef = useRef(null);
const englishGoodbyeRef = useRef(null);
const [playedOnce, setPlayedOnce] = useState(false);

console.log(IBNR, conditionString);

useEffect(() => {
if (!IBNR) return;

const germanAudio = germanAudioRef.current;
const germanGoodbye = germanGoodbyeRef.current;
const englishAudio = englishAudioRef.current;
const englishGoodbye = englishGoodbyeRef.current;

if (germanAudio) {
germanAudio.src = `https://${audiourl}/de/${IBNR}.wav`;
}
if (germanGoodbye) {
germanGoodbye.src = `https://${audiourl}/de/goodbye-message.wav`;
}
if (englishAudio) {
englishAudio.src = `https://${audiourl}/en/${IBNR}.wav`;
}
if (englishGoodbye) {
englishGoodbye.src = `https://${audiourl}/en/goodbye-message.wav`;
}
}, [IBNR, audiourl]);

useEffect(() => {
const germanAudio = germanAudioRef.current;
const germanGoodbye = germanGoodbyeRef.current;
const englishAudio = englishAudioRef.current;
const englishGoodbye = englishGoodbyeRef.current;

if (conditionString === undefined && germanAudio) {
germanAudio
.play()
.then(() => {
if (playedOnce) return;

if (conditionString === 'In Kürze erreichen wir') {
if (germanAudio) {
germanAudio.play().then(() => {
germanAudio.onended = () => {
if (englishAudio) {
englishAudio.play().catch((error) => {
console.error('Englische IBNR-Audiodatei konnte nicht automatisch abgespielt werden:', error);
});
}
};
}).catch((error) => {
console.error('Deutsche IBNR-Audiodatei konnte nicht automatisch abgespielt werden:', error);
});
}
} else if (conditionString === undefined) {
if (germanAudio) {
germanAudio.play().then(() => {
germanAudio.onended = () => {
const germanGoodbye = germanGoodbyeRef.current;
if (germanGoodbye) {
germanGoodbye
.play()
.then(() => {
germanGoodbye.onended = () => {
if (englishAudio) {
englishAudio
.play()
.then(() => {
englishAudio.onended = () => {
if (englishGoodbye) {
englishGoodbye.play().catch((error) => {
console.error(
'Englische goodbye-message konnt ned automatisch abgespuid werdn:',
error
);
});
}
};
})
.catch((error) => {
console.error('Englische IBNR-Audiodatei konnt ned automatisch abgespuid werdn:', error);
});
}
};
})
.catch((error) => {
console.error('Deitsche goodbye-message konnt ned automatisch abgespuid werdn:', error);
});
germanGoodbye.src = `https://${audiourl}/de/goodbye-message.wav`;
germanGoodbye.play().then(() => {
germanGoodbye.onended = () => {
if (englishAudio) {
englishAudio.play().then(() => {
englishAudio.onended = () => {
const englishGoodbye = englishGoodbyeRef.current;
if (englishGoodbye) {
englishGoodbye.src = `https://${audiourl}/en/goodbye-message.wav`;
englishGoodbye.play().catch((error) => {
console.error('Englische goodbye-message konnte nicht automatisch abgespielt werden:', error);
});
}
};
}).catch((error) => {
console.error('Englische IBNR-Audiodatei konnte nicht automatisch abgespielt werden:', error);
});
}
};
}).catch((error) => {
console.error('Deutsche goodbye-message konnte nicht automatisch abgespielt werden:', error);
});
}
};
})
.catch((error) => {
console.error('Deitsche IBNR-Audiodatei konnt ned automatisch abgespuid werdn:', error);
}).catch((error) => {
console.error('Deutsche IBNR-Audiodatei konnte nicht automatisch abgespielt werden:', error);
});
}
}
}, [conditionString, IBNR, audiourl]);

setPlayedOnce(true);
}, [conditionString, playedOnce, audiourl]);

return (
<div className="__ansagen" style={{ display: 'none' }}>
<audio ref={germanAudioRef} controls>
<source src={`https://${audiourl}/de/${IBNR}.wav`} type="audio/wav" />
</audio>
<audio ref={germanGoodbyeRef} controls>
<source src={`https://${audiourl}/de/goodbye-message.wav`} type="audio/wav" />
</audio>
<audio ref={englishAudioRef} controls>
<source src={`https://${audiourl}/en/${IBNR}.wav`} type="audio/wav" />
</audio>
<audio ref={englishGoodbyeRef} controls>
<source src={`https://${audiourl}/en/goodbye-message.wav`} type="audio/wav" />
</audio>
<div className='__ansagen' style={{ display: 'none' }}>
<audio ref={germanAudioRef} controls />
<audio ref={englishAudioRef} controls />
<audio ref={germanGoodbyeRef} controls />
<audio ref={englishGoodbyeRef} controls />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion components/core/TrainMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function TrainMap({ tripId }) {
const fetchIntervalId = setInterval(fetchData, 17000); // Fetch data every 5 seconds

return () => clearInterval(fetchIntervalId);
}, [tripId, lng, lat]);
}, [tripId, lng, lat, speed]);

useEffect(() => {
if (!map.current) {
Expand Down

0 comments on commit 76e6fc8

Please sign in to comment.