Basic error handling when reading peaks
This commit is contained in:
parent
97db31209c
commit
99659adb9e
|
@ -26,6 +26,7 @@ export const WaveformCanvas: React.FC<Props> = (props: Props) => {
|
|||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
(async function () {
|
||||
const canvas = canvasRef.current;
|
||||
if (canvas == null) {
|
||||
console.error('no canvas ref available');
|
||||
|
@ -49,7 +50,8 @@ export const WaveformCanvas: React.FC<Props> = (props: Props) => {
|
|||
const chanHeight = canvas.height / props.channels;
|
||||
|
||||
let frameIndex = 0;
|
||||
props.peaks.forEach((peaks) => {
|
||||
await props.peaks
|
||||
.forEach((peaks) => {
|
||||
for (let chanIndex = 0; chanIndex < peaks.length; chanIndex++) {
|
||||
const yOffset = chanHeight * chanIndex;
|
||||
const val = peaks[chanIndex];
|
||||
|
@ -64,7 +66,9 @@ export const WaveformCanvas: React.FC<Props> = (props: Props) => {
|
|||
ctx.globalAlpha = 1;
|
||||
}
|
||||
frameIndex++;
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
})();
|
||||
}, [props.peaks]);
|
||||
|
||||
const canvasStyles = {
|
||||
|
|
Loading…
Reference in New Issue