signal-desktop/ts/components/CallingAudioIndicator.stories.tsx

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-05-19 03:28:51 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2022-05-23 22:00:01 +00:00
import React, { useState, useEffect } from 'react';
import { boolean } from '@storybook/addon-knobs';
2022-05-19 03:28:51 +00:00
import { CallingAudioIndicator } from './CallingAudioIndicator';
2022-05-23 22:00:01 +00:00
import { AUDIO_LEVEL_INTERVAL_MS } from '../calling/constants';
2022-05-19 03:28:51 +00:00
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/CallingAudioIndicator',
};
2022-05-19 03:28:51 +00:00
2022-06-07 00:48:02 +00:00
export const Extreme = (): JSX.Element => {
2022-05-23 22:00:01 +00:00
const [audioLevel, setAudioLevel] = useState(1);
useEffect(() => {
const timer = setTimeout(() => {
setAudioLevel(1 - audioLevel);
}, 2 * AUDIO_LEVEL_INTERVAL_MS);
return () => {
clearTimeout(timer);
};
}, [audioLevel, setAudioLevel]);
return (
<CallingAudioIndicator
hasAudio={boolean('hasAudio', true)}
audioLevel={audioLevel}
/>
);
2022-06-07 00:48:02 +00:00
};
2022-05-23 22:00:01 +00:00
2022-06-07 00:48:02 +00:00
export const Random = (): JSX.Element => {
2022-05-23 22:00:01 +00:00
const [audioLevel, setAudioLevel] = useState(1);
useEffect(() => {
const timer = setTimeout(() => {
setAudioLevel(Math.random());
}, AUDIO_LEVEL_INTERVAL_MS);
return () => {
clearTimeout(timer);
};
}, [audioLevel, setAudioLevel]);
return (
<CallingAudioIndicator
hasAudio={boolean('hasAudio', true)}
audioLevel={audioLevel}
/>
);
2022-06-07 00:48:02 +00:00
};