Improve MessageAudio peaks computation

There are two parts to this change:

1. The computation of peaks is moved from `MessageAudio` to the
   `GlobalAudioContext` and thus we can limit the concurrency of the
   computations (`p-queue`!) and de-duplicate the computations as well
2. While the peaks are computed the component has to display spinning
   animation instead of empty waveform and unclickable UI.
This commit is contained in:
Fedor Indutny 2021-04-15 14:02:24 -07:00 committed by GitHub
parent 2c3911cad0
commit 0b969f3f42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 135 additions and 113 deletions

View file

@ -4,17 +4,15 @@
import { connect } from 'react-redux';
import { MessageAudio } from '../../components/conversation/MessageAudio';
import { ComputePeaksResult } from '../../components/GlobalAudioContext';
import { mapDispatchToProps } from '../actions';
import { StateType } from '../reducer';
import { WaveformCache } from '../../types/Audio';
import { LocalizerType } from '../../types/Util';
import { AttachmentType } from '../../types/Attachment';
export type Props = {
audio: HTMLAudioElement;
audioContext: AudioContext;
waveformCache: WaveformCache;
direction?: 'incoming' | 'outgoing';
id: string;
@ -24,6 +22,8 @@ export type Props = {
withContentBelow: boolean;
buttonRef: React.RefObject<HTMLButtonElement>;
computePeaks(url: string, barCount: number): Promise<ComputePeaksResult>;
kickOffAttachmentDownload(): void;
onCorrupted(): void;
};