Skip to content

Commit

Permalink
Merge pull request #304 from jiho-bae/dev
Browse files Browse the repository at this point in the history
방 인원 카운트방식 변경, 화면공유 버그 해결, 화면공유시에만 전체화면으로 변경
  • Loading branch information
zaehuun authored Dec 4, 2021
2 parents 79952b5 + b5d5711 commit 9102d8f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 26 deletions.
2 changes: 2 additions & 0 deletions client/src/components/room/RoomCard/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const RoomCardWrapper = styled.div`
flex-direction: column;
background-color: ${({ theme }) => theme.colors.white};
padding: ${({ theme }) => theme.paddings.base};
min-width: 15rem;
width: 100%;
height: ${ROOM_CARD.height}rem;
border-radius: ${({ theme }) => theme.borderRadius.base};
Expand Down Expand Up @@ -77,6 +78,7 @@ export const RoomCardBottom = styled.div`
`;

export const RoomFieldType = styled.div<{ bgColor: DevFieldType }>`
min-width: 5.1rem;
width: 6rem;
height: 2rem;
${({ theme, bgColor }) => css`
Expand Down
20 changes: 14 additions & 6 deletions client/src/components/video/Screenshare/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import { ICameraVideoTrack, IMicrophoneAudioTrack } from 'agora-rtc-react';
import { useClient, useScreenVideoTrack } from '@components/video/config';

Expand All @@ -19,27 +19,35 @@ const ScreenShare = ({
}: ScreenShareDivProps): JSX.Element => {
const client = useClient();
const { ready, tracks, error } = useScreenVideoTrack();
const firstRenderRef = useRef(true);

useEffect(() => {
const pulishScreenShare = async () => {
setStart(false);
await client.unpublish(preTracks[1]);
await client.publish(tracks);
setStart(true);
if (!Array.isArray(tracks)) {
tracks.on('track-ended', async () => {
setScreenShare(false);
await client.unpublish(tracks);
tracks.close();
if (trackState.video) {
await client.publish(preTracks[1]);
}
setScreenShare(false);
});
}
};
if (ready) pulishScreenShare();
if (ready && tracks) pulishScreenShare();
if (error) setScreenShare(false);

return () => {
client.unpublish(tracks);
if (firstRenderRef.current) {
firstRenderRef.current = false;
return;
}
if (!error && !Array.isArray(tracks)) {
client.unpublish(tracks);
tracks.close();
}
};
}, [setStart, setScreenShare, screenShare, client, preTracks, trackState, tracks, ready, error]);

Expand Down
7 changes: 4 additions & 3 deletions client/src/components/video/VideoCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AgoraVideoPlayer,
} from 'agora-rtc-react';
import { VideoWrap, VolumeVisualizer } from './style';
import { SPEAK } from '@utils/constant';
import { SCREEN_SHARE_HEIGHT, SPEAK } from '@utils/constant';
import { useToast } from '@hooks/useToast';
import { TOAST_MESSAGE } from '@utils/constant';

Expand Down Expand Up @@ -69,8 +69,9 @@ const VideoCard = ({ videoTrack, audioTrack }: VideoCardProps): JSX.Element => {
<VideoWrap
onClick={onClickInfo}
onDoubleClick={() => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
videoTrack?.getMediaStreamTrack().readyState === 'live' && openFullscreen();
if (videoTrack?.getCurrentFrameData()?.height === SCREEN_SHARE_HEIGHT) {
openFullscreen();
}
}}
ref={videoRef}>
{videoTrack && (
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/video/VideoController/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const VideoController = ({ tracks, setStart, uuid, ownerId }: VideoControllerPro
}
};

const handleScreenShare = () => setScreenShare(!screenShare);
const handleScreenShare = useCallback(() => {
setScreenShare((prev) => !prev);
}, []);

const leaveChannel = useCallback(async () => {
if (ownerId === user.id) {
Expand Down
25 changes: 18 additions & 7 deletions client/src/components/video/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
createMicrophoneAndCameraTracks,
createMicrophoneAudioTrack,
createScreenVideoTrack,
ILocalAudioTrack,
ILocalVideoTrack,
AgoraRTCError,
} from 'agora-rtc-react';
import { SCREEN_SHARE_HEIGHT } from '@utils/constant';

const config: ClientConfig = {
mode: 'rtc',
Expand All @@ -14,12 +18,19 @@ const config: ClientConfig = {
const useClient = createClient(config);
const useMicrophoneAndCameraTracks = createMicrophoneAndCameraTracks();
const useMicrophoneTrack = createMicrophoneAudioTrack();
const useScreenVideoTrack = createScreenVideoTrack(
{
encoderConfig: '1080p_1',
optimizationMode: 'detail',
},
'disable',
);
const useScreenVideoTrack = (): {
ready: boolean;
tracks: ILocalVideoTrack | [ILocalVideoTrack, ILocalAudioTrack];
error: AgoraRTCError | null;
} => {
const screenShare = createScreenVideoTrack(
{
encoderConfig: `${SCREEN_SHARE_HEIGHT}p_1`,
optimizationMode: 'detail',
},
'disable',
);
return screenShare();
};

export { useClient, useMicrophoneAndCameraTracks, useMicrophoneTrack, useScreenVideoTrack };
2 changes: 0 additions & 2 deletions client/src/pages/Campfire/Campfire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import BGMContextProvider from '@contexts/bgmContext';
import { useUser } from '@contexts/userContext';
import { RoomType } from '@utils/constant';
import { RoomInfoType } from '@src/types';
import { postLeaveRoom } from '@src/apis';

interface LocationProps {
pathname: string;
Expand All @@ -35,7 +34,6 @@ const Campfire = ({ location }: RoomProps): JSX.Element => {

useEffect(() => {
if (!userInfo.login) {
postLeaveRoom(uuid);
history.goBack();
return;
}
Expand Down
12 changes: 6 additions & 6 deletions client/src/pages/Tadak/Tadak.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import VideoList from '@components/video/VideoList';
import Loader from '@components/common/Loader';
import { useUser } from '@contexts/userContext';
import { RoomInfoType } from '@src/types';
import { postLeaveRoom } from '@src/apis';

interface LocationProps {
pathname: string;
Expand All @@ -23,15 +22,15 @@ interface TadakProps {
const Tadak = ({ location }: TadakProps): JSX.Element => {
const { agoraAppId, agoraToken, uuid, owner, maxHeadcount } = location?.state;
const [users, setUsers] = useState<IAgoraRTCRemoteUser[]>([]);
const [start, setStart] = useState<boolean>(false);
const [start, setStart] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const client = useClient();
const { ready, tracks } = useMicrophoneAndCameraTracks();
const userInfo = useUser();
const history = useHistory();

useEffect(() => {
if (!userInfo.login) {
postLeaveRoom(uuid);
history.goBack();
return;
}
Expand Down Expand Up @@ -74,6 +73,7 @@ const Tadak = ({ location }: TadakProps): JSX.Element => {
await tracks[1].setEnabled(false);
await tracks[0].setEnabled(false);
}
setIsLoading(false);
setStart(true);
};

Expand All @@ -85,14 +85,14 @@ const Tadak = ({ location }: TadakProps): JSX.Element => {

return (
<TadakWrapper>
{!start ? (
{isLoading ? (
<Loader isWholeScreen={true} />
) : (
<>
<RoomSideBar uuid={uuid} hostNickname={owner?.nickname} maxHeadcount={maxHeadcount} />
<TadakContainer>
{tracks && <VideoList users={users} tracks={tracks} />}
{tracks && <VideoController tracks={tracks} setStart={setStart} uuid={uuid} ownerId={owner?.id} />}
{start && tracks && <VideoList users={users} tracks={tracks} />}
{ready && tracks && <VideoController tracks={tracks} setStart={setStart} uuid={uuid} ownerId={owner?.id} />}
</TadakContainer>
</>
)}
Expand Down
4 changes: 3 additions & 1 deletion client/src/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const INPUT = {

export const TOAST_TIME = 2000;

export const SCREEN_SHARE_HEIGHT = 1080;

export const MODAL_NAME = {
login: '로그인',
join: '회원가입',
Expand Down Expand Up @@ -86,7 +88,7 @@ export const TOAST_MESSAGE = {
introduceHost:
'호스트는 참가자를 강퇴할 수 있습니다.  강퇴 당한 사용자는 다시 이 방에 들어올 수 없으니 신중하게 사용해주세요!',
narcissism: '누구나 자기 자신을 좋아합니다...!',
infoDoubleClick: '더블 클릭 하면 어떤 일이 일어날까요...?',
infoDoubleClick: '화면공유된 블록을 더블 클릭 하면 어떤 일이 일어날까요...?',
introFireAnimation: '자세히 보시면 불꽃이 일렁입니다...!',
introMoon: '자세히 보시면 달이 반짝입니다...!',
introSky: '자세히 보시면 별이 반짝이고 별똥별이 떨어집니다...!',
Expand Down

0 comments on commit 9102d8f

Please sign in to comment.