@@ -24,7 +24,7 @@ const CollaborationSpace = () => {
24
24
const [ userId , setUserId ] = useState ( "" ) ; // Current user
25
25
const [ language , setLanguage ] = useState ( "python" ) ; // Set default language to python
26
26
const [ output , setOutput ] = useState ( "" ) ;
27
-
27
+
28
28
const LANGUAGEVERSIONS = {
29
29
"python" : "3.10.0" ,
30
30
"java" : "15.0.2" ,
@@ -40,7 +40,8 @@ const CollaborationSpace = () => {
40
40
navigate ( "/home" ) ;
41
41
} ;
42
42
43
- // Set up websockets for room management on client side, and collaboration for Yjs
43
+
44
+ { /* Set up websockets for room management on client side, and collaboration for Yjs */ }
44
45
useEffect ( ( ) => {
45
46
const fetchUser = async ( ) => {
46
47
const user = await getUserFromToken ( ) ;
@@ -66,14 +67,18 @@ const CollaborationSpace = () => {
66
67
67
68
const initiateWebSocket = ( userId ) => {
68
69
if ( websocketRef . current ) return ; // Prevent duplicate connections
70
+
69
71
const websocket = new WebSocket ( "ws://localhost:3004" ) ;
70
72
websocketRef . current = websocket ;
71
73
72
74
websocket . onopen = ( ) => {
75
+
73
76
websocket . send ( JSON . stringify ( { type : 'joinRoom' , roomId, userId } ) ) ;
74
77
websocket . send ( JSON . stringify ( { type : 'requestUserList' , roomId } ) ) ;
75
78
} ;
76
79
80
+
81
+ // on getting a reply from server
77
82
websocket . onmessage = ( event ) => {
78
83
const data = JSON . parse ( event . data ) ;
79
84
console . log ( `[FRONTEND] data message is ${ JSON . stringify ( data ) } ` ) ;
@@ -113,6 +118,7 @@ const CollaborationSpace = () => {
113
118
114
119
const handleExit = ( ) => {
115
120
if ( websocketRef . current ) websocketRef . current . send ( JSON . stringify ( { type : 'leaveRoom' , roomId, userId } ) ) ;
121
+
116
122
// Clean up Yjs document and provider before going back to home
117
123
if ( provider ) {
118
124
provider . destroy ( ) ;
@@ -127,9 +133,13 @@ const CollaborationSpace = () => {
127
133
const handleCodeRun = ( ) => {
128
134
const code_message = {
129
135
"language" : language ,
130
- "files" : [ { "content" : code } ] ,
136
+ "files" : [
137
+ {
138
+ "content" : code
139
+ }
140
+ ] ,
131
141
"version" : LANGUAGEVERSIONS [ language ]
132
- } ;
142
+ }
133
143
134
144
collabService . getCodeOutput ( code_message )
135
145
. then ( result => {
0 commit comments