More signals
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user