From 2ce7bde884a72824e9ff1be646c2c057a21294dd Mon Sep 17 00:00:00 2001 From: ExostFlash Date: Mon, 2 Jun 2025 17:40:08 +0200 Subject: [PATCH] Test failed websocket --- .idea/gradle.xml | 15 +++ .idea/kotlinc.xml | 9 ++ .idea/misc.xml | 2 +- .../essentials/footer/footer.component.html | 5 - .../app/services/matches/matches.service.ts | 113 ++++++++---------- db.lock.db | 6 + db.mv.db | Bin 0 -> 20480 bytes jpe-controle.iml | 1 + 8 files changed, 83 insertions(+), 68 deletions(-) create mode 100644 .idea/gradle.xml create mode 100644 .idea/kotlinc.xml create mode 100644 db.lock.db create mode 100644 db.mv.db diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..cac49ff --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..eeec968 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a7e1300..cb90649 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html b/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html index 01eca56..bd1e916 100644 --- a/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html +++ b/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html @@ -48,11 +48,6 @@
© FencerJudge - Tous droits réservés - Mentions légales - Cookies - Accessibilité - Nous contacter - Presse
diff --git a/FencerJudgeFront/src/app/services/matches/matches.service.ts b/FencerJudgeFront/src/app/services/matches/matches.service.ts index fef45dd..68cd948 100644 --- a/FencerJudgeFront/src/app/services/matches/matches.service.ts +++ b/FencerJudgeFront/src/app/services/matches/matches.service.ts @@ -1,81 +1,70 @@ import { Injectable } from '@angular/core'; -import { Observable, of } from 'rxjs'; -import { Matches, MatchState } from '@interfaces/matches'; +import { Observable, Subject, BehaviorSubject } from 'rxjs'; +import { Matches } from '@interfaces/matches'; @Injectable({ providedIn: 'root' }) export class MatchesService { - private matches: Matches[] = [ - { - id: 1, - refereeID: 10, - player1ID: 1, - score1: 15, - player2ID: 2, - score2: 13, - country: 'France', - city: 'Paris', - weapon: 'Fleuret', - date: new Date('2025-06-10T14:00:00'), - state: MatchState.OVER, - }, - { - id: 2, - refereeID: 11, - player1ID: 3, - score1: 5, - player2ID: 4, - score2: 7, - country: 'France', - city: 'Lyon', - weapon: 'Épée', - date: new Date('2025-06-15T10:00:00'), - state: MatchState.ONGOING, - }, - { - id: 3, - refereeID: 12, - player1ID: 5, - score1: 0, - player2ID: 6, - score2: 0, - country: 'Belgique', - city: 'Bruxelles', - weapon: 'Sabre', - date: new Date('2025-06-20T16:30:00'), - state: MatchState.NOT_STARTED, - }, - ]; + private socket?: WebSocket; + private matchUpdates$ = new Subject(); + private allMatches: Matches[] = []; constructor() { - console.log('[MatchesService] Initial matches loaded:', this.matches); + this.connectToMatchUpdatesWebSocket(); + } + + private connectToMatchUpdatesWebSocket(): void { + const wsUrl = 'ws://localhost:8080/ws/matches'; + this.socket = new WebSocket(wsUrl); + + this.socket.onopen = () => { + console.log('[WebSocket] ✅ Connecté à', wsUrl); + }; + + this.socket.onmessage = (event) => { + try { + const data = JSON.parse(event.data) as Matches[]; + console.log('[WebSocket] 📥 Données reçues :', data); + this.matchUpdates$.next(data); + } catch (e) { + console.error('[WebSocket] ❌ Erreur de parsing JSON', e); + } + }; + + this.socket.onerror = (err) => { + console.error('[WebSocket] ❌ Erreur :', err); + }; + + this.socket.onclose = () => { + console.warn('[WebSocket] 🔌 Fermeture de la connexion'); + }; } getMatches(): Observable { - console.log('[MatchesService] Fetching all matches'); - return of(this.matches); + return this.matchUpdates$.asObservable(); } getMatchById(id: number): Observable { - const match = this.matches.find((m) => m.id === id); - console.log(`[MatchesService] Fetching match ID: ${id}`, match); - return of(match); - } - - // Préparation future pour WebSocket - connectToMatchUpdatesWebSocket(): void { - console.log( - '[MatchesService] WebSocket connection placeholder initialized' - ); - // ici tu pourrais plus tard faire : this.socket = new WebSocket('ws://...') etc. + const match = this.allMatches.find((m) => m.id === id); + console.log(`[MatchesService] Match ID ${id} récupéré :`, match); + return new BehaviorSubject(match).asObservable(); } updateMatch(id: number, updatedData: Partial): void { - const match = this.matches.find((m) => m.id === id); - if (match) { - Object.assign(match, updatedData); - console.log(`[MatchesService] Match ${id} mis à jour :`, match); + const matchIndex = this.allMatches.findIndex((m) => m.id === id); + if (matchIndex !== -1) { + const updatedMatch = { ...this.allMatches[matchIndex], ...updatedData }; + this.allMatches[matchIndex] = updatedMatch; + this.matchUpdates$.next([...this.allMatches]); // émettre un nouveau tableau + console.log( + `[MatchesService] Match ${id} mis à jour localement :`, + updatedMatch + ); } else { - console.warn(`[MatchesService] Match ${id} introuvable`); + console.warn(`[MatchesService] Match ${id} non trouvé pour mise à jour`); } } + + ngOnDestroy(): void { + this.socket?.close(); + } } diff --git a/db.lock.db b/db.lock.db new file mode 100644 index 0000000..9c75c64 --- /dev/null +++ b/db.lock.db @@ -0,0 +1,6 @@ +#FileLock +#Mon Jun 02 17:12:33 CEST 2025 +hostName=ExostFlash +id=197313393c88a931fa21bf5ce1281b7253870b00683 +method=file +server=192.167.2.100\:54366 diff --git a/db.mv.db b/db.mv.db new file mode 100644 index 0000000000000000000000000000000000000000..b765537d4bf6815912d09f20ce8932fc43c7bacf GIT binary patch literal 20480 zcmeHPy>Ht_6enfNR-CBuQlL}8D0XbMib@_S@dIcPN}??_vg}B75>Ez2o*W~xWXO_Z zcM95U1==D*5uixtZbhdKU9%ME)IXwI$L@VRlKQe`$*5AK&1pD(y}Nt&d+(h5-g{(T zLy2m=X+N&)e}*-I=lO))!d4qQnxM*}Ad0FatBG2(bzrqMF;T1Iw*3gVG)2LZjB5)F z{ZRxc0u%v?07ZZzKoOt_Py{Ff6ak6=MSvpkr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