import React, { useState, useEffect } from 'react'; import { Row, Col, Button } from 'react-bootstrap'; import Tabs from 'react-bootstrap/Tabs'; import Tab from 'react-bootstrap/Tab'; import ClosedList from '../Components/ClosedList'; import OpenList from '../Components/OpenList'; import Menu from '../Components/Menu'; import { io } from "socket.io-client"; //모듈 가져오기 import Chat from "../Components/Chat"; import RoomMake from "../Components/RoomMake" import EnterRoom from "../Components/EnterRoom" const socket = io(); function Home() { const userName = sessionStorage.getItem('name') const [showModal, setShowModal] = useState(false); const [showEnter, setEnter] = useState(false); const [chat, setChat] = useState(false); //소켓 const [singleChat, setSingleChat] = useState('') const [recievedMsg, setRecievedMsg] = useState('') const [roomCode, setRoomCode] = useState('') const [newUser, setNewUser] = useState('') //방참가 const [roomName, setRoomName] = useState('') const handleCloseModal = () => setShowModal(false); const handleShowModal = () => setShowModal(true); const handleCloseEnter = () => setEnter(false); const handleShowEnter = () => setEnter(true); const handleChato = () => setChat(true); const handleChatc = () => setChat(false); //SOCKET 관련 시작 function enterChatRoom(rCode) { //방 입장하기 socket.emit('joinRoom', rCode) socket.emit('newUser', { rmIf: rCode, userInfo: userName }) console.log(`joinRoom : ${rCode} 입장`) } const sendMsg = (e) => { e.preventDefault() } socket.on("sendUser", (data) => { setNewUser(data) }) useEffect(() => { if (!(singleChat == '')) { socket.emit("chat", { roomInfo: roomCode, username: userName, msg: singleChat, }) setSingleChat(['']) } }, [singleChat]) useEffect(() => { socket.on("sendedMSG", (msg) => { console.log('msg',msg) setRecievedMsg(msg) }) }, []) return ( <> {chat ? :
}
); } export default Home;