From 0adb1a22e1a92cfe361c4be6682d6e3d86df1e9b Mon Sep 17 00:00:00 2001 From: 071yoon Date: Wed, 27 Jul 2022 11:57:45 +0900 Subject: [PATCH 1/4] FIRE-332 add videoSocket file --- src/adapters/video/videoSocket.ts | 11 +++++++++++ src/pages/Room.tsx | 10 ++-------- 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 src/adapters/video/videoSocket.ts diff --git a/src/adapters/video/videoSocket.ts b/src/adapters/video/videoSocket.ts new file mode 100644 index 00000000..9d704de4 --- /dev/null +++ b/src/adapters/video/videoSocket.ts @@ -0,0 +1,11 @@ +import { io } from 'socket.io-client'; + +const videoSocket = io(process.env.REACT_APP_SOCKET_VIDEO_URL as string); + +function videoSocketInit() { + videoSocket.on('connect', () => { + console.log('socket server connected.'); + }); +} + +export { videoSocketInit, videoSocket }; diff --git a/src/pages/Room.tsx b/src/pages/Room.tsx index af9df85f..164ec17f 100644 --- a/src/pages/Room.tsx +++ b/src/pages/Room.tsx @@ -1,5 +1,4 @@ import styled from 'styled-components'; -import io from 'socket.io-client'; import axios from 'axios'; import { useEffect, useState, useCallback } from 'react'; import { useParams } from 'react-router-dom'; @@ -17,9 +16,9 @@ import { onChatMessage, onLeftRoom, } from '../adapters/chat/socketio'; +import { videoSocket, videoSocketInit } from '../adapters/video/videoSocket'; export default function Room() { - const videoSocket = io(process.env.REACT_APP_SOCKET_VIDEO_URL as string); const [userList, setUserList] = useState({}); const [messages, setMessages] = useState([]); const { isOpen } = controlModal(); @@ -28,12 +27,7 @@ export default function Room() { const { connectedUsers, appendUser, removeUser } = connectedUsersStore(); useEffect(() => { - videoSocket.on('connect', () => { - console.log('video socket connected'); - const payload = { room: roomId, uid: localStorage.getItem('uid') }; - console.log('payload', payload); - videoSocket.emit('joinRoom', payload); - }); + videoSocketInit(); videoSocket.on(`${roomId}-update-user-list`, ({ users }) => { users.map((user) => { From 64134fd3eeca03d09ea06bd9f03c6904224fc2a8 Mon Sep 17 00:00:00 2001 From: 071yoon Date: Wed, 27 Jul 2022 15:48:10 +0900 Subject: [PATCH 2/4] FIRE-332 add chat at video MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 비디오 화면에서 5초동안 나오는 채팅 완료 --- src/components/room/LocalScreen.tsx | 24 +++++++++++++++---- src/components/room/ScreenShare.tsx | 4 +++- src/components/room/SingleScreen.tsx | 35 ++++++++++++++++------------ 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/components/room/LocalScreen.tsx b/src/components/room/LocalScreen.tsx index 33836891..60cbdf0d 100644 --- a/src/components/room/LocalScreen.tsx +++ b/src/components/room/LocalScreen.tsx @@ -1,11 +1,12 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import styled from 'styled-components'; import MyAvatar from '../../assets/avatar/MyAvatar'; import controlModal from '../../stores/controlModal'; import { useCreateMediaStream } from '../rtc/hooks/useCreateLocalStream'; -export default function LocalScreen({ nickname, avatar, uid }) { +export default function LocalScreen({ nickname, avatar, uid, messages }) { const { userMediaStream, createMediaStream } = useCreateMediaStream(); + const [currentTime, setCurrentTime] = useState(new Date()); useEffect(() => { createMediaStream(); }, []); @@ -24,14 +25,29 @@ export default function LocalScreen({ nickname, avatar, uid }) { } }, [videoRef, userMediaStream]); + useEffect(() => { + const timer = setInterval(() => { + setCurrentTime(new Date()); + }, 250); + return () => clearInterval(timer); + }, []); + + const newMessage = messages.filter( + (message) => + message.uid === uid && + new Date(message.createdAt).getTime() > currentTime.getTime() - 5000, + ); return (