Remove useless logic in MessageAudio
`isLoading` was initially used to avoid duplicate loads of the audio on re-renders, but this has to be handled in GlobalAudioContext not in MessageAudio.
This commit is contained in:
parent
a3054ac0dc
commit
3eaa47ec72
1 changed files with 4 additions and 15 deletions
|
@ -230,7 +230,6 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
// NOTE: Avoid division by zero
|
// NOTE: Avoid division by zero
|
||||||
const [duration, setDuration] = useState(1e-23);
|
const [duration, setDuration] = useState(1e-23);
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [peaks, setPeaks] = useState<ReadonlyArray<number>>(
|
const [peaks, setPeaks] = useState<ReadonlyArray<number>>(
|
||||||
new Array(PEAK_COUNT).fill(0)
|
new Array(PEAK_COUNT).fill(0)
|
||||||
);
|
);
|
||||||
|
@ -248,10 +247,12 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
// This effect loads audio file and computes its RMS peak for dispalying the
|
// This effect loads audio file and computes its RMS peak for dispalying the
|
||||||
// waveform.
|
// waveform.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading || state !== State.Normal) {
|
if (state !== State.Normal) {
|
||||||
return noop;
|
return noop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.log.info('MessageAudio: loading audio and computing waveform');
|
||||||
|
|
||||||
let canceled = false;
|
let canceled = false;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
@ -275,25 +276,13 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
setDuration(Math.max(newDuration, 1e-23));
|
setDuration(Math.max(newDuration, 1e-23));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
window.log.error('MessageAudio: loadAudio error', err);
|
window.log.error('MessageAudio: loadAudio error', err);
|
||||||
} finally {
|
|
||||||
if (!canceled) {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
canceled = true;
|
canceled = true;
|
||||||
};
|
};
|
||||||
}, [
|
}, [attachment, audioContext, setDuration, setPeaks, state, waveformCache]);
|
||||||
attachment,
|
|
||||||
audioContext,
|
|
||||||
isLoading,
|
|
||||||
setDuration,
|
|
||||||
setPeaks,
|
|
||||||
state,
|
|
||||||
waveformCache,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// This effect attaches/detaches event listeners to the global <audio/>
|
// This effect attaches/detaches event listeners to the global <audio/>
|
||||||
// instance that we reuse from the GlobalAudioContext.
|
// instance that we reuse from the GlobalAudioContext.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue