@@ -15,39 +15,36 @@ function AppelProf(callId) {
1515 } ) ;
1616 const { user } = useFirebase ( ) ;
1717
18- const ip = "localhost" ;
18+ const ip = process . env . REACT_APP_IP ;
1919 const [ users , setUsers ] = useState ( [ ] ) ;
2020 const [ usersPresent , setUsersPresent ] = useState ( [ ] ) ;
2121 const [ inRoom , setInRoom ] = useState ( false ) ;
22- const dataFetchedRef = useRef ( false ) ;
2322 const generated = useRef ( false ) ;
24- const [ tempCall , setTempCall ] = useState ( { } ) ;
25-
2623 const ws = useMemo ( ( ) => {
2724 return new w3cwebsocket ( `ws://${ ip } :5050/call` ) ;
2825 } , [ ] ) ;
2926
3027 const LogToExistingRoom = useCallback ( async ( ) => {
3128 try {
3229 axios
33- . get ( `http://localhost:5050/call/getRoomPo/${ user ?. id } ` )
30+ . get ( `http://localhost:5050/call/getRoomPo/${ user ?. id } ` , {
31+ params : { callId : callId } ,
32+ } )
3433 . then ( ( res ) => {
3534 if ( res . data . length > 0 ) {
3635 const message = {
3736 type : "joinRoom" ,
3837 data : {
3938 userID : user ?. id ,
4039 name : user ?. firstname ,
41- class : user ? .class ,
40+ class : res . data [ 0 ] . class ,
4241 type : "call" ,
4342 } ,
4443 } ;
45- ws . send ( JSON . stringify ( message ) ) ;
44+ console . log ( "sending" ) ;
45+ const msgToSend = JSON . stringify ( message ) ;
46+ ws . send ( msgToSend ) ;
4647 setInRoom ( true ) ;
47- generated . current = true ;
48- setTempCall ( res . data ) ;
49- setCall ( res . data ) ;
50- setQrcode ( res . data . qrcode ) ;
5148 }
5249 } ) ;
5350 } catch ( error ) {
@@ -58,7 +55,9 @@ function AppelProf(callId) {
5855 useEffect ( ( ) => {
5956 const handleOpen = async ( ) => {
6057 if ( user . status === "po" ) {
61- await LogToExistingRoom ( ) ;
58+ if ( ! inRoom ) {
59+ await LogToExistingRoom ( ) ;
60+ }
6261 }
6362
6463 if ( inRoom ) {
@@ -67,7 +66,13 @@ function AppelProf(callId) {
6766
6867 switch ( messageReceive . type ) {
6968 case "updateRoom" :
70- setCall ( messageReceive . appel ) ;
69+ const keys = Object . keys (
70+ messageReceive . data . currentRoom . appel
71+ ) [ 0 ] ;
72+ const appel = messageReceive . data . currentRoom . appel [ keys ] . appel ;
73+ setCall ( appel ) ;
74+ setQrcode ( appel . qrcode ) ;
75+ getUsers ( appel . id_lesson ) ;
7176 break ;
7277 default :
7378 break ;
@@ -83,12 +88,24 @@ function AppelProf(callId) {
8388 }
8489
8590 return ( ) => {
86- if ( ws . readyState === WebSocket . OPEN ) {
87- ws . send ( { type : "leaveRoom" , data : { userID : user ?. id , class : user ?. class } } ) ;
88- }
91+ /* if (ws.readyState === WebSocket.OPEN) {
92+ ws.send(
93+ JSON.stringify({
94+ type: "leaveRoom",
95+ data: { userID: user?.id, class: user?.class },
96+ })
97+ );
98+ } */
8999 } ;
90100 } , [ LogToExistingRoom , call , inRoom , user . class , user . id , user . status , ws ] ) ;
91101
102+ const getUsers = ( coursId ) => {
103+ axios
104+ . get ( `http://localhost:5050/call/getUsersFromClassiId/${ coursId } ` )
105+ . then ( ( res ) => {
106+ setUsers ( res . data ) ;
107+ } ) ;
108+ } ;
92109 useEffect ( ( ) => {
93110 if ( generated . current ) {
94111 setUsersPresent ( call . student_scan ) ;
@@ -105,9 +122,7 @@ function AppelProf(callId) {
105122
106123 return (
107124 < div className = "ContentProf" >
108- < div className = "Timer" >
109- < Timer />
110- </ div >
125+ < div className = "Timer" > { /* <Timer /> */ } </ div >
111126 < div className = "ContentInfo" >
112127 < div className = "DivQr" >
113128 < img src = { qrcode } className = "Qrcode" alt = "" />
@@ -139,7 +154,7 @@ function AppelProf(callId) {
139154 < div className = "DivChat" >
140155 < h1 > Chat</ h1 >
141156 < div className = "Chat" >
142- { call . chats . map ( ( chat ) => {
157+ { /* { call.chats.map((chat) => {
143158 return (
144159 <div className="ChatContent">
145160 <div className="ChatContentHeader">
@@ -155,7 +170,7 @@ function AppelProf(callId) {
155170 </div>
156171 </div>
157172 );
158- } ) }
173+ }) } */ }
159174 </ div >
160175 </ div >
161176 </ div >
0 commit comments