import { Meta, Story } from '@storybook/react'; import React, { useState, useEffect, useRef } from 'react'; import { VideoTile, VideoTileProps } from '.'; import VideoTileDocs from './VideoTile.mdx'; import { getVideoTileLabel } from '../../utils'; import { VideoTileControls } from './Controls'; import { MicOffIcon, MicOnIcon } from '../Icons'; import { HMSThemeProvider } from '../../hooks/HMSThemeProvider'; import { storyBookSDK } from '../../storybook/store/SetUpFakeStore'; declare global { interface HTMLVideoElement { captureStream(frameRate?: number): MediaStream; } } const meta: Meta = { title: 'Video / Tile', component: VideoTile, parameters: { docs: { page: VideoTileDocs, }, }, argTypes: { audioLevel: { control: { type: 'range' } }, stream: { control: { disable: true } }, controlsComponent: { control: { disable: true } }, }, //decorators: [addDummyVideos] //TODO this is a placeholder for future use }; export default meta; const Template: Story = (args: VideoTileProps) => { const [videoTrack, setVideoTrack] = useState(); const [audioTrack, setAudioTrack] = useState(); const dummyVideoRef = useRef(null); //const testVideoRef = useRef(null); // Stream is not added in dependency array to avoid creating a new stream for every mute/unmute change which causes visual flicker in the storybook canvas. useEffect(() => { const track = videoTrack; if (track) { track.enabled = !args.isVideoMuted; } //eslint-disable-next-line react-hooks/exhaustive-deps }, [args.isVideoMuted]); useEffect(() => { const track = audioTrack; if (track) { track.enabled = !args.isAudioMuted; } //eslint-disable-next-line react-hooks/exhaustive-deps }, [args.isAudioMuted]); return (
{/*
); }; const MeetTemplate: Story = args => { const [videoTrack, setVideoTrack] = useState(); const [audioTrack, setAudioTrack] = useState(); const dummyVideoRef = useRef(null); return ( <>
{ storyBookSDK.getRandomPeer())()} videoTrack={videoTrack} audioTrack={audioTrack} controlsComponent={ <> {args.allowRemoteMute && (
{args.isAudioMuted ? : }
)} } /> }
); }; // By passing using the Args format for exported stories, you can control the props for a component for reuse in a test // https://storybook.js.org/docs/react/workflows/unit-testing export const DefaultVideoTile = Template.bind({}); export const GoogleMeetVideoTile = MeetTemplate.bind({}); export const CampFireVideoTile = Template.bind({}); export const ClassesOverrideVideoTile = Template.bind({}); DefaultVideoTile.args = { isLocal: true, aspectRatio: { width: 16, height: 9 }, displayShape: 'rectangle', showAudioLevel: true, audioLevelDisplayType: 'border', audioLevel: 40, classes: { root: 'hello' }, }; GoogleMeetVideoTile.args = { isLocal: true, aspectRatio: { width: 16, height: 9 }, displayShape: 'rectangle', showAudioLevel: true, audioLevelDisplayType: 'inline-wave', audioLevel: 40, }; CampFireVideoTile.args = { isLocal: true, displayShape: 'circle', showAudioLevel: true, audioLevelDisplayType: 'border', audioLevel: 40, }; ClassesOverrideVideoTile.args = { isLocal: true, aspectRatio: { width: 16, height: 9 }, displayShape: 'rectangle', showAudioLevel: true, audioLevelDisplayType: 'border', audioLevel: 40, classes: { videoContainer: 'border-8 border-red-800' }, };