Skip to content

Commit 30401f4

Browse files
committed
Resolve conflict try 2
1 parent b1327dc commit 30401f4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Frontend/src/components/collab/CollaborationSpace.jsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const CollaborationSpace = () => {
2424
const [userId, setUserId] = useState(""); // Current user
2525
const [language, setLanguage] = useState("python"); // Set default language to python
2626
const [output, setOutput] = useState("");
27-
27+
2828
const LANGUAGEVERSIONS = {
2929
"python" : "3.10.0",
3030
"java" : "15.0.2",
@@ -40,7 +40,8 @@ const CollaborationSpace = () => {
4040
navigate("/home");
4141
};
4242

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 */}
4445
useEffect(() => {
4546
const fetchUser = async () => {
4647
const user = await getUserFromToken();
@@ -66,14 +67,18 @@ const CollaborationSpace = () => {
6667

6768
const initiateWebSocket = (userId) => {
6869
if (websocketRef.current) return; // Prevent duplicate connections
70+
6971
const websocket = new WebSocket("ws://localhost:3004");
7072
websocketRef.current = websocket;
7173

7274
websocket.onopen = () => {
75+
7376
websocket.send(JSON.stringify({ type: 'joinRoom', roomId, userId }));
7477
websocket.send(JSON.stringify({ type: 'requestUserList', roomId }));
7578
};
7679

80+
81+
// on getting a reply from server
7782
websocket.onmessage = (event) => {
7883
const data = JSON.parse(event.data);
7984
console.log(`[FRONTEND] data message is ${JSON.stringify(data)}`);
@@ -113,6 +118,7 @@ const CollaborationSpace = () => {
113118

114119
const handleExit = () => {
115120
if (websocketRef.current) websocketRef.current.send(JSON.stringify({ type: 'leaveRoom', roomId, userId }));
121+
116122
// Clean up Yjs document and provider before going back to home
117123
if (provider) {
118124
provider.destroy();
@@ -127,9 +133,13 @@ const CollaborationSpace = () => {
127133
const handleCodeRun = () => {
128134
const code_message = {
129135
"language": language,
130-
"files": [{ "content": code }],
136+
"files": [
137+
{
138+
"content": code
139+
}
140+
],
131141
"version": LANGUAGEVERSIONS[language]
132-
};
142+
}
133143

134144
collabService.getCodeOutput(code_message)
135145
.then(result => {

0 commit comments

Comments
 (0)