Keep exiting code when creating a room (#12)
continuous-integration/drone/push Build is passing Details

Co-authored-by: bastien ollier <bastien.ollier@etu.uca.fr>
Reviewed-on: #12
Reviewed-by: Clément FRÉVILLE <clement.freville2@etu.uca.fr>
Co-authored-by: Bastien OLLIER <bastien.ollier@noreply.codefirst.iut.uca.fr>
Co-committed-by: Bastien OLLIER <bastien.ollier@noreply.codefirst.iut.uca.fr>
chore/angular18
Bastien OLLIER 11 months ago committed by Clément FRÉVILLE
parent 5505f9d3e7
commit 6a6fc064ef

@ -59,10 +59,7 @@
</div> </div>
} }
<button <button class="button-join" (click)="onCreateRoomButtonClicked()">
class="button-join"
(click)="onCreateRoomButtonClicked()"
>
Créer une salle Créer une salle
</button> </button>

@ -140,6 +140,10 @@ export class EditorComponent {
private client: WebSocket | undefined; private client: WebSocket | undefined;
@Input() @Input()
set idRoom(idRoom: string) { set idRoom(idRoom: string) {
if (idRoom === undefined) {
return;
}
this.client = new WebSocket(`ws://127.0.0.1:3000/live/${idRoom}`); this.client = new WebSocket(`ws://127.0.0.1:3000/live/${idRoom}`);
this.client.addEventListener('open', async () => { this.client.addEventListener('open', async () => {
let conn = new Connection(this.client!); let conn = new Connection(this.client!);
@ -166,7 +170,7 @@ export class EditorComponent {
if (msg.type === 'stdout' || msg.type === 'stderr') { if (msg.type === 'stdout' || msg.type === 'stderr') {
this.resultContent += msg.text; this.resultContent += msg.text;
} }
}) });
} }
// Efface le contenu de l'éditeur // Efface le contenu de l'éditeur
@ -175,7 +179,7 @@ export class EditorComponent {
} }
async onCreateRoomButtonClicked() { async onCreateRoomButtonClicked() {
const idRoom = await this.backendService.createRoom(); const idRoom = await this.backendService.createRoom(this.editorContent);
await this.router.navigate([`./editor-live/${idRoom}`]); await this.router.navigate([`./editor-live/${idRoom}`]);
} }
@ -183,10 +187,7 @@ export class EditorComponent {
// Le code à exécuter est le contenu de l'éditeur // Le code à exécuter est le contenu de l'éditeur
const codeToExecute = this.editorContent; const codeToExecute = this.editorContent;
this.backendService.executeCode( this.backendService.executeCode(codeToExecute, this.selectedLanguage.name);
codeToExecute,
this.selectedLanguage.name
);
this.resultContent = ''; this.resultContent = '';
} }

@ -1,8 +1,13 @@
import { LanguageDescription, LanguageSupport, StreamLanguage, StreamParser } from '@codemirror/language'; import {
LanguageDescription,
LanguageSupport,
StreamLanguage,
StreamParser,
} from '@codemirror/language';
import { javascript } from '@codemirror/lang-javascript'; import { javascript } from '@codemirror/lang-javascript';
function legacy(parser: StreamParser<unknown>): LanguageSupport { function legacy(parser: StreamParser<unknown>): LanguageSupport {
return new LanguageSupport(StreamLanguage.define(parser)) return new LanguageSupport(StreamLanguage.define(parser));
} }
export const CODE_DEFAULTS = { export const CODE_DEFAULTS = {
@ -59,7 +64,9 @@ export const LANGUAGES = [
extensions: ['sh', 'ksh', 'bash'], extensions: ['sh', 'ksh', 'bash'],
filename: /^PKGBUILD$/, filename: /^PKGBUILD$/,
load() { load() {
return import('@codemirror/legacy-modes/mode/shell').then(m => legacy(m.shell)) return import('@codemirror/legacy-modes/mode/shell').then((m) =>
} legacy(m.shell)
);
},
}), }),
]; ];

@ -16,8 +16,14 @@ export class BackendService {
constructor() {} constructor() {}
async createRoom() { async createRoom(code: string) {
const reponse = await fetch(`${this.apiUrl}/live`, { method: 'POST' }); const reponse = await fetch(`${this.apiUrl}/live`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ code }),
});
return reponse.text(); return reponse.text();
} }

Loading…
Cancel
Save