This commit is contained in:
subhajit 2026-07-31 18:07:02 +05:30
parent 367771772f
commit e3e1e8aaf5
3 changed files with 79 additions and 66 deletions

View File

@ -155,69 +155,71 @@ public function executeCode(Request $request)
$code = $request->code; $code = $request->code;
$output = ''; $output = '';
// 1. Instant Local CLI Process Execution (0.02s response for Node.js, Python, PHP) // 1. Ultra-Fast Piston Code Execution API (sub-second for C, C++, Java, JS, Python, PHP, Go, Rust)
try { $pistonLangMap = [
if (in_array($langKey, ['javascript', 'js'])) { 'python' => 'python',
$process = new \Symfony\Component\Process\Process(['node', '-e', $code]); 'py' => 'python',
$process->setTimeout(4); 'javascript' => 'javascript',
$process->run(); 'js' => 'javascript',
$out = $process->getOutput() ?: $process->getErrorOutput(); 'c' => 'c',
$output = trim($out) ?: 'JavaScript executed successfully (no stdout).'; 'cpp' => 'c++',
} elseif ($langKey === 'python') { 'c++' => 'c++',
$process = new \Symfony\Component\Process\Process(['python', '-c', $code]); 'java' => 'java',
$process->setTimeout(4); 'php' => 'php',
$process->run(); 'laravel' => 'php',
$out = $process->getOutput() ?: $process->getErrorOutput(); 'go' => 'go',
$output = trim($out) ?: 'Python executed successfully (no stdout).'; 'rust' => 'rust',
} elseif (in_array($langKey, ['php', 'laravel'])) { ];
ob_start();
try { if (isset($pistonLangMap[$langKey])) {
$cleanCode = preg_replace('/^\s*<\?php\s*/i', '', $code); try {
eval($cleanCode); $pistonLang = $pistonLangMap[$langKey];
$out = ob_get_clean(); $response = Http::timeout(4)->post('https://emkc.org/api/v2/piston/execute', [
$output = trim($out) ?: 'PHP code executed successfully.'; 'language' => $pistonLang,
} catch (\Throwable $e) { 'version' => '*',
ob_end_clean(); 'files' => [
$output = 'PHP Evaluation Error: ' . $e->getMessage(); ['content' => $code]
]
]);
if ($response->successful()) {
$resData = $response->json();
$output = $resData['run']['output'] ?? ($resData['run']['stdout'] ?? '');
if (empty($output) && !empty($resData['run']['stderr'])) {
$output = $resData['run']['stderr'];
}
} }
} } catch (\Exception $e) {}
} catch (\Exception $e) {
// Local execution exception; fall through to Judge0 API
} }
// 2. Remote Compiler API (Judge0 CE) for C, C++, Java or non-local runtimes // 2. Instant Local Process Runner Fallback
if (empty($output)) { if (empty($output)) {
$judge0Map = [ try {
'python' => 71, if (in_array($langKey, ['javascript', 'js'])) {
'c' => 50, $process = new \Symfony\Component\Process\Process(['node', '-e', $code]);
'cpp' => 54, $process->setTimeout(3);
'c++' => 54, $process->run();
'java' => 62, $out = $process->getOutput() ?: $process->getErrorOutput();
'php' => 68, $output = trim($out) ?: 'JavaScript executed successfully (no stdout).';
'laravel' => 68, } elseif ($langKey === 'python') {
'javascript' => 63, $process = new \Symfony\Component\Process\Process(['python', '-c', $code]);
'js' => 63, $process->setTimeout(3);
]; $process->run();
$out = $process->getOutput() ?: $process->getErrorOutput();
if (isset($judge0Map[$langKey])) { $output = trim($out) ?: 'Python executed successfully (no stdout).';
try { } elseif (in_array($langKey, ['php', 'laravel'])) {
$response = Http::timeout(5)->post('https://ce.judge0.com/submissions?wait=true', [ ob_start();
'source_code' => $code, try {
'language_id' => $judge0Map[$langKey], $cleanCode = preg_replace('/^\s*<\?php\s*/i', '', $code);
]); eval($cleanCode);
$out = ob_get_clean();
if ($response->successful()) { $output = trim($out) ?: 'PHP code executed successfully.';
$data = $response->json(); } catch (\Throwable $e) {
$stdout = $data['stdout'] ?? ''; ob_end_clean();
$stderr = $data['stderr'] ?? ''; $output = 'PHP Evaluation Error: ' . $e->getMessage();
$compile = $data['compile_output'] ?? '';
$msg = $data['message'] ?? '';
$outputParts = array_filter([$stdout, $stderr, $compile, $msg]);
$output = trim(implode("\n", $outputParts));
} }
} catch (\Exception $e) {} }
} } catch (\Exception $e) {}
} }
if (empty($output)) { if (empty($output)) {

View File

@ -368,7 +368,7 @@
<div style="color: #94a3b8; font-style: italic; text-align: center; padding-top: 40px;">No messages yet. Send a message below.</div> <div style="color: #94a3b8; font-style: italic; text-align: center; padding-top: 40px;">No messages yet. Send a message below.</div>
</div> </div>
<div style="display: flex; gap: 6px;"> <div style="display: flex; gap: 6px;">
<input type="text" id="candidate-chat-input" placeholder="Type message to panelist..." onkeydown="if(event.key==='Enter') sendCandidateMessage()" class="form-input" style="font-size: 0.75rem; background: #0b0f19; border: 1px solid var(--card-border); padding: 6px 10px; flex: 1;"> <input type="text" id="candidate-chat-input" placeholder="Type message to panelist..." onkeydown="if(event.key==='Enter') sendCandidateMessage()" class="form-input" style="font-size: 0.75rem; background: #0b0f19; color: #ffffff !important; border: 1px solid var(--card-border); padding: 6px 10px; flex: 1;">
<button onclick="sendCandidateMessage()" class="btn-ide" style="padding: 6px 10px; font-size: 0.75rem; background: #6366f1; border: none; font-weight: 600;"> <button onclick="sendCandidateMessage()" class="btn-ide" style="padding: 6px 10px; font-size: 0.75rem; background: #6366f1; border: none; font-weight: 600;">
Send Send
</button> </button>
@ -460,6 +460,11 @@
// Real-Time Instant BroadcastChannel + Backend Code Sync // Real-Time Instant BroadcastChannel + Backend Code Sync
const liveSyncChannel = new BroadcastChannel('live_sync_' + '{{ $interview->id }}'); const liveSyncChannel = new BroadcastChannel('live_sync_' + '{{ $interview->id }}');
liveSyncChannel.onmessage = function(event) {
if (event.data && event.data.type === 'chat_message' && typeof pollCandidateChat === 'function') {
pollCandidateChat();
}
};
let codeSyncTimeout = null; let codeSyncTimeout = null;
editor.onDidChangeModelContent(function () { editor.onDidChangeModelContent(function () {
const code = editor.getValue(); const code = editor.getValue();
@ -1824,6 +1829,10 @@ function sendCandidateMessage() {
if (!msg) return; if (!msg) return;
input.value = ''; input.value = '';
if (typeof liveSyncChannel !== 'undefined' && liveSyncChannel) {
liveSyncChannel.postMessage({ type: 'chat_message', message: msg, sender: 'candidate' });
}
fetch(`{{ route('interview.candidate.send-message', $interview->id) }}`, { fetch(`{{ route('interview.candidate.send-message', $interview->id) }}`, {
method: 'POST', method: 'POST',
headers: { headers: {
@ -1834,9 +1843,7 @@ function sendCandidateMessage() {
}) })
.then(r => r.json()) .then(r => r.json())
.then(res => { .then(res => {
if (res.success) { pollCandidateChat();
pollCandidateChat();
}
}); });
} }

View File

@ -749,7 +749,7 @@
<div style="color: #94a3b8; font-style: italic; text-align: center; padding-top: 40px;">No chat history. Send a message below.</div> <div style="color: #94a3b8; font-style: italic; text-align: center; padding-top: 40px;">No chat history. Send a message below.</div>
</div> </div>
<div style="display: flex; gap: 6px;"> <div style="display: flex; gap: 6px;">
<input type="text" id="warning-input" placeholder="Type message to candidate..." onkeydown="if(event.key==='Enter') sendSilentWarning()" class="form-input" style="font-size: 0.75rem; background: #0b0f19; padding: 6px 10px; flex: 1;"> <input type="text" id="warning-input" placeholder="Type message to candidate..." onkeydown="if(event.key==='Enter') sendSilentWarning()" class="form-input" style="font-size: 0.75rem; background: #0b0f19; color: #ffffff !important; border: 1px solid var(--card-border); padding: 6px 10px; flex: 1;">
<button onclick="sendSilentWarning()" class="btn-nav" style="background: #6366f1; color: white; border: none; font-size: 0.75rem; font-weight: 600; padding: 6px 12px; cursor: pointer;"> <button onclick="sendSilentWarning()" class="btn-nav" style="background: #6366f1; color: white; border: none; font-size: 0.75rem; font-weight: 600; padding: 6px 12px; cursor: pointer;">
Send Send
</button> </button>
@ -1270,6 +1270,8 @@ function subscribeLiveSync(interviewId) {
if (drawingImg) drawingImg.style.display = 'none'; if (drawingImg) drawingImg.style.display = 'none';
if (noDrawing) noDrawing.style.display = 'block'; if (noDrawing) noDrawing.style.display = 'block';
} }
} else if (data.type === 'chat_message') {
pollReviewData();
} }
}; };
} }
@ -2245,6 +2247,10 @@ function sendSilentWarning() {
if (!msg || !currentInterviewId) return; if (!msg || !currentInterviewId) return;
input.value = ''; input.value = '';
if (typeof liveSyncChannel !== 'undefined' && liveSyncChannel) {
liveSyncChannel.postMessage({ type: 'chat_message', message: msg, sender: 'interviewer' });
}
fetch(`{{ route('interview.warning', ':id') }}`.replace(':id', currentInterviewId), { fetch(`{{ route('interview.warning', ':id') }}`.replace(':id', currentInterviewId), {
method: 'POST', method: 'POST',
headers: { headers: {
@ -2255,9 +2261,7 @@ function sendSilentWarning() {
}) })
.then(r => r.json()) .then(r => r.json())
.then(res => { .then(res => {
if (res.success) { pollReviewData();
pollReviewData();
}
}); });
} }