diff --git a/frontend/src/app/services/chat/chat.service.ts b/frontend/src/app/services/chat/chat.service.ts index 2a95c2d..19bffd5 100644 --- a/frontend/src/app/services/chat/chat.service.ts +++ b/frontend/src/app/services/chat/chat.service.ts @@ -15,12 +15,13 @@ export interface ChatInfo { }) export class ChatService { - private socket: Socket; + private socket: Socket | undefined; private url: string; + private room: string; constructor() { this.url = ''; - this.socket = io(); + this.room = ''; } setUrl(url: string){ @@ -28,6 +29,10 @@ export class ChatService { this.setSocket(); } + setRoom(room: string){ + this.room = room; + } + setSocket(){ this.socket = io(this.url, { withCredentials: true @@ -35,6 +40,7 @@ export class ChatService { } sendMessage(username: string | null, room: string, message: string) { + // @ts-ignore this.socket.emit(room, { username: username, date: new Date(), @@ -43,10 +49,12 @@ export class ChatService { }); } - onNewMessage() { + onNewMessage(room: string): Observable { return new Observable(observer => { - this.socket.on('general', infos => { - observer.next(infos); + // @ts-ignore + this.socket.on(room, (data: ChatInfo[]) => { + console.log(data); + observer.next(data); }); }); }