-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: [FE] MediaControlButton 개선 (#226)
merge: [FE] MediaControlButton 개선 (#226)
- Loading branch information
Showing
14 changed files
with
126 additions
and
218 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import useMediaControl from '@/stores/useMediaControl'; | ||
import { MediaControlButtonProps } from './VideoControlButton'; | ||
import MicOffSvg from '@/assets/MicOffSvg'; | ||
import MicOnSvg from '@/assets/MicOnSvg'; | ||
|
||
export default function MicControlButton({ stream, className, onColor, offColor }: MediaControlButtonProps) { | ||
const { micOn, micToggle } = useMediaControl((state) => state); | ||
|
||
const muteMic = () => { | ||
stream?.getAudioTracks().forEach((track) => { | ||
track.enabled = !track.enabled; | ||
}); | ||
}; | ||
|
||
const handleMicClick = () => { | ||
muteMic(); | ||
micToggle(); | ||
}; | ||
|
||
return ( | ||
<button | ||
type="button" | ||
onClick={handleMicClick} | ||
className={className} | ||
style={{ backgroundColor: micOn ? 'transparent' : '#ea4335', transition: 'all 0.5s' }} | ||
> | ||
{micOn ? <MicOnSvg color={onColor} /> : <MicOffSvg color={offColor} />} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import VideoOffSvg from '@/assets/VideoOffSvg'; | ||
import VideoOnSvg from '@/assets/VideoOnSvg'; | ||
import useMediaControl from '@/stores/useMediaControl'; | ||
|
||
export interface MediaControlButtonProps { | ||
stream: MediaStream; | ||
className: string; | ||
onColor: string; | ||
offColor: string; | ||
} | ||
|
||
export default function VideoControlButton({ stream, className, onColor, offColor }: MediaControlButtonProps) { | ||
const { videoOn, videoToggle } = useMediaControl((state) => state); | ||
|
||
const offVideo = () => { | ||
stream?.getVideoTracks().forEach((track) => { | ||
track.enabled = !track.enabled; | ||
}); | ||
}; | ||
|
||
const handleClick = () => { | ||
offVideo(); | ||
videoToggle(); | ||
}; | ||
|
||
return ( | ||
<button | ||
type="button" | ||
onClick={handleClick} | ||
className={className} | ||
style={{ backgroundColor: videoOn ? 'transparent' : '#ea4335', transition: 'all 0.5s' }} | ||
> | ||
{videoOn ? <VideoOnSvg color={onColor} /> : <VideoOffSvg color={offColor} />} | ||
</button> | ||
); | ||
} |
29 changes: 0 additions & 29 deletions
29
frontEnd/src/components/common/tests/MediaControlButton.test.tsx
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
frontEnd/src/components/common/tests/MicControlButton.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import MicControlButton from '../MicControlButton'; | ||
|
||
const audioTrack = [{ enabled: true }]; | ||
|
||
const mockGetAudioTrack = jest.fn().mockImplementation(() => audioTrack); | ||
|
||
const mockStream = { | ||
getAudioTracks: mockGetAudioTrack, | ||
} as unknown as MediaStream; | ||
|
||
describe('MicControllButton테스트', () => { | ||
it('audio에 대한 MicControllButton을 누르면 audio 설정이 반전된다.', async () => { | ||
render(<MicControlButton onColor="white" offColor="white" stream={mockStream} className="" />); | ||
fireEvent.click(await screen.findByRole('button')); | ||
expect(mockGetAudioTrack).toHaveBeenCalled(); | ||
expect(audioTrack).toStrictEqual([{ enabled: false }]); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
frontEnd/src/components/common/tests/VideoControlButton.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import VideoControlButton from '../VideoControlButton'; | ||
|
||
const videoTrack = [{ enabled: true }]; | ||
|
||
const mockGetVideoTrack = jest.fn().mockImplementation(() => videoTrack); | ||
|
||
const mockStream = { | ||
getVideoTracks: mockGetVideoTrack, | ||
} as unknown as MediaStream; | ||
|
||
describe('MediaControllButton테스트', () => { | ||
it('video 대한 MediaControllButton을 누르면 video 설정이 반전된다.', async () => { | ||
render(<VideoControlButton onColor="white" offColor="white" stream={mockStream} className="" />); | ||
fireEvent.click(await screen.findByRole('button')); | ||
expect(mockGetVideoTrack).toHaveBeenCalled(); | ||
expect(videoTrack).toStrictEqual([{ enabled: false }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.