More signals

This commit is contained in:
aditya.chandel
2024-12-18 16:08:22 -07:00
parent 71f5927364
commit ce515649f6
14 changed files with 160 additions and 129 deletions
@@ -6,24 +6,21 @@ import {BookUpdateEvent} from '../model/book.model';
providedIn: 'root',
})
export class BookProgressService {
private eventSource: EventSource | null = null;
connect(libraryId: number): Observable<BookUpdateEvent> {
const url = `http://localhost:8080/v1/library/${libraryId}/parse`;
return new Observable((observer) => {
this.eventSource = new EventSource(url);
this.eventSource.onmessage = (event) => {
const data: BookUpdateEvent = JSON.parse(event.data);
observer.next(data);
};
this.eventSource.onerror = (error) => {
console.error('SSE connection error:', error);
observer.error(error);
};
return () => {
this.closeConnection();
};