|
|
@ -1,6 +1,6 @@
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { SSE } from 'sse.js';
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root',
|
|
|
|
providedIn: 'root',
|
|
|
@ -10,7 +10,17 @@ export class CodeExecutionService {
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
|
|
|
|
|
|
|
|
executeCode(code: string, language: string): Observable<any> {
|
|
|
|
executeCode(code: string, language: string) {
|
|
|
|
return this.http.post<any>(this.apiUrl, { code, language });
|
|
|
|
const sse = new SSE(this.apiUrl, {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
|
|
Accept: 'text/event-stream',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
payload: JSON.stringify({ code, language }),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
sse.addEventListener('message', (event: MessageEvent<string>) => {
|
|
|
|
|
|
|
|
console.log(event.data);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|