Skip to content

Commit a352b2c

Browse files
committed
feat: Rework code execution engine
1 parent 7920154 commit a352b2c

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/views/GameRoom/GameRoom.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,14 @@ const GameRoom = () => {
9191
roomId,
9292
language,
9393
code,
94+
socketId: socketRef.current?.id,
9495
};
9596

9697
try {
9798
const response: any = await apiClient.post("/execute/run", payload);
9899
console.log("Run Output:", response);
99-
setConsoleOutput(response);
100100
} catch (error) {
101101
console.error("Error executing code:", error);
102-
} finally {
103-
setIsRunLoading(false);
104-
setIsSubmitLoading(false);
105102
}
106103
}
107104
};
@@ -121,16 +118,14 @@ const GameRoom = () => {
121118
roomId,
122119
language,
123120
code,
121+
socketId: socketRef.current?.id,
124122
};
125123

126124
try {
127125
const response: any = await apiClient.post("/execute/submit", payload);
128126
console.log("Run Output:", response);
129127
} catch (error) {
130128
console.error("Error executing code:", error);
131-
} finally {
132-
setIsRunLoading(false);
133-
setIsSubmitLoading(false);
134129
}
135130
}
136131
};
@@ -259,6 +254,18 @@ const GameRoom = () => {
259254
});
260255
});
261256

257+
socket.on("compilationResponse", (data) => {
258+
setConsoleOutput({
259+
stdout: data.stdout.split("\n"),
260+
stderr: data.stderr.split("\n"),
261+
execTime: data.execTime,
262+
timedOut: false,
263+
submissionId: data.submissionId,
264+
});
265+
setIsRunLoading(false);
266+
setIsSubmitLoading(false);
267+
});
268+
262269
socket.on("tokenExpired", async () => {
263270
console.log("Token expired, refreshing...");
264271
const newToken = await refreshAccessToken();
@@ -426,9 +433,8 @@ const GameRoom = () => {
426433
<option value="cpp">C++</option>
427434
<option value="csharp">C#</option>
428435
<option value="ruby">Ruby</option>
429-
<option value="go">Go</option>
430-
<option value="rust">Rust</option>
431-
<option value="ocaml">OCaml</option>
436+
<option value="javascript">JavaScript</option>
437+
<option value="typescript">TypeScript</option>
432438
</select>
433439
</div>
434440
</div>
@@ -486,7 +492,7 @@ const GameRoom = () => {
486492
<div>stdout</div>
487493
<div className="game-room-console-output">
488494
{consoleOutput.stdout.map((output: any, index) => (
489-
<div key={index}>{output.text}</div>
495+
<div key={index}>{output}</div>
490496
))}
491497
</div>
492498
</div>
@@ -495,7 +501,7 @@ const GameRoom = () => {
495501
<div>stderr</div>
496502
<div className="game-room-console-output">
497503
{consoleOutput.stderr.map((output: any, index) => (
498-
<div key={index}>{output.text}</div>
504+
<div key={index}>{output}</div>
499505
))}
500506
</div>
501507
</div>

0 commit comments

Comments
 (0)