Websocket and stuffs

This commit is contained in:
aditya.chandel
2024-12-19 16:10:08 -07:00
parent 9e3b45fffc
commit e175a7e255
24 changed files with 569 additions and 496 deletions
+18 -1
View File
@@ -1,5 +1,9 @@
import {Component, OnInit} from '@angular/core';
import {LibraryService} from './book/service/library.service';
import {RxStompService} from './rx-stomp.service';
import {Message} from '@stomp/stompjs';
import {BookService} from './book/service/book.service';
import {Book} from './book/model/book.model';
@Component({
selector: 'app-root',
@@ -9,9 +13,22 @@ import {LibraryService} from './book/service/library.service';
})
export class AppComponent implements OnInit {
constructor(private libraryService: LibraryService) {}
constructor(private libraryService: LibraryService, private bookService: BookService, private rxStompService: RxStompService) {
}
ngOnInit(): void {
this.libraryService.initializeLibraries();
this.bookService.loadBooksSignal(1);
this.rxStompService.watch('/topic/books').subscribe((message: Message) => {
const book: Book = JSON.parse(message.body); // Parse the incoming message to book DTO
this.bookService.appendBookToLibrary(book); // Call method to append to libraryBooks
});
}
sendMessage() {
const message = `Message generated at ${new Date()}`;
this.rxStompService.publish({destination: '/app/send', body: message});
}
}