lien editor -> live editor
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

Bastien OLLIER 11 months ago
parent 09b0e1b2ee
commit 5f66c6e534

@ -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!);
@ -161,7 +165,8 @@ export class EditorComponent {
constructor( constructor(
private router: Router, private router: Router,
private backendService: BackendService private backendService: BackendService
) {} ) {
}
// Efface le contenu de l'éditeur // Efface le contenu de l'éditeur
clear(): void { clear(): void {
@ -169,7 +174,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}`]);
} }

@ -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