@@ -15,39 +15,36 @@ function AppelProf(callId) {
15
15
} ) ;
16
16
const { user } = useFirebase ( ) ;
17
17
18
- const ip = "localhost" ;
18
+ const ip = process . env . REACT_APP_IP ;
19
19
const [ users , setUsers ] = useState ( [ ] ) ;
20
20
const [ usersPresent , setUsersPresent ] = useState ( [ ] ) ;
21
21
const [ inRoom , setInRoom ] = useState ( false ) ;
22
- const dataFetchedRef = useRef ( false ) ;
23
22
const generated = useRef ( false ) ;
24
- const [ tempCall , setTempCall ] = useState ( { } ) ;
25
-
26
23
const ws = useMemo ( ( ) => {
27
24
return new w3cwebsocket ( `ws://${ ip } :5050/call` ) ;
28
25
} , [ ] ) ;
29
26
30
27
const LogToExistingRoom = useCallback ( async ( ) => {
31
28
try {
32
29
axios
33
- . get ( `http://localhost:5050/call/getRoomPo/${ user ?. id } ` )
30
+ . get ( `http://localhost:5050/call/getRoomPo/${ user ?. id } ` , {
31
+ params : { callId : callId } ,
32
+ } )
34
33
. then ( ( res ) => {
35
34
if ( res . data . length > 0 ) {
36
35
const message = {
37
36
type : "joinRoom" ,
38
37
data : {
39
38
userID : user ?. id ,
40
39
name : user ?. firstname ,
41
- class : user ? .class ,
40
+ class : res . data [ 0 ] . class ,
42
41
type : "call" ,
43
42
} ,
44
43
} ;
45
- ws . send ( JSON . stringify ( message ) ) ;
44
+ console . log ( "sending" ) ;
45
+ const msgToSend = JSON . stringify ( message ) ;
46
+ ws . send ( msgToSend ) ;
46
47
setInRoom ( true ) ;
47
- generated . current = true ;
48
- setTempCall ( res . data ) ;
49
- setCall ( res . data ) ;
50
- setQrcode ( res . data . qrcode ) ;
51
48
}
52
49
} ) ;
53
50
} catch ( error ) {
@@ -58,7 +55,9 @@ function AppelProf(callId) {
58
55
useEffect ( ( ) => {
59
56
const handleOpen = async ( ) => {
60
57
if ( user . status === "po" ) {
61
- await LogToExistingRoom ( ) ;
58
+ if ( ! inRoom ) {
59
+ await LogToExistingRoom ( ) ;
60
+ }
62
61
}
63
62
64
63
if ( inRoom ) {
@@ -67,7 +66,13 @@ function AppelProf(callId) {
67
66
68
67
switch ( messageReceive . type ) {
69
68
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 ) ;
71
76
break ;
72
77
default :
73
78
break ;
@@ -83,12 +88,24 @@ function AppelProf(callId) {
83
88
}
84
89
85
90
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
+ } */
89
99
} ;
90
100
} , [ LogToExistingRoom , call , inRoom , user . class , user . id , user . status , ws ] ) ;
91
101
102
+ const getUsers = ( coursId ) => {
103
+ axios
104
+ . get ( `http://localhost:5050/call/getUsersFromClassiId/${ coursId } ` )
105
+ . then ( ( res ) => {
106
+ setUsers ( res . data ) ;
107
+ } ) ;
108
+ } ;
92
109
useEffect ( ( ) => {
93
110
if ( generated . current ) {
94
111
setUsersPresent ( call . student_scan ) ;
@@ -105,9 +122,7 @@ function AppelProf(callId) {
105
122
106
123
return (
107
124
< div className = "ContentProf" >
108
- < div className = "Timer" >
109
- < Timer />
110
- </ div >
125
+ < div className = "Timer" > { /* <Timer /> */ } </ div >
111
126
< div className = "ContentInfo" >
112
127
< div className = "DivQr" >
113
128
< img src = { qrcode } className = "Qrcode" alt = "" />
@@ -139,7 +154,7 @@ function AppelProf(callId) {
139
154
< div className = "DivChat" >
140
155
< h1 > Chat</ h1 >
141
156
< div className = "Chat" >
142
- { call . chats . map ( ( chat ) => {
157
+ { /* { call.chats.map((chat) => {
143
158
return (
144
159
<div className="ChatContent">
145
160
<div className="ChatContentHeader">
@@ -155,7 +170,7 @@ function AppelProf(callId) {
155
170
</div>
156
171
</div>
157
172
);
158
- } ) }
173
+ }) } */ }
159
174
</ div >
160
175
</ div >
161
176
</ div >
0 commit comments