|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
|
import { SSE } from 'sse.js';
|
|
|
|
|
import { Observable, Subject } from 'rxjs';
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root',
|
|
|
|
|
})
|
|
|
|
|
export class CodeExecutionService {
|
|
|
|
|
private apiUrl = 'http://localhost:3000/run'; // Url du serveur Node.js en local
|
|
|
|
|
private apiUrl = 'http://localhost:3000/run';
|
|
|
|
|
private resultSubject = new Subject<string>();
|
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
|
|
|
|
|
@ -19,8 +21,17 @@ export class CodeExecutionService {
|
|
|
|
|
},
|
|
|
|
|
payload: JSON.stringify({ code, language }),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sse.addEventListener('message', (event: MessageEvent<string>) => {
|
|
|
|
|
console.log(event.data);
|
|
|
|
|
const result = event.data;
|
|
|
|
|
|
|
|
|
|
// Émettre le résultat à tous les abonnés
|
|
|
|
|
const text = decodeURIComponent(result.replace(/%00/g, ''));
|
|
|
|
|
this.resultSubject.next(text);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getResult(): Observable<string> {
|
|
|
|
|
return this.resultSubject.asObservable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|