Changed search socket code to receive videos in batches
All checks were successful
gitea/video-server-frontend/pipeline/head This commit looks good
All checks were successful
gitea/video-server-frontend/pipeline/head This commit looks good
This commit is contained in:
parent
71b9cb8f49
commit
e28a4d056f
@ -31,29 +31,42 @@ export class SearchComponent implements OnInit {
|
|||||||
|
|
||||||
performSearch(query: string): void {
|
performSearch(query: string): void {
|
||||||
this.searching = true;
|
this.searching = true;
|
||||||
const ws: WebSocketSubject<any> = webSocket<any>(`ws://192.168.0.100:8190/search?q=${query}`);
|
const ws: WebSocketSubject<string> = webSocket<any>({
|
||||||
|
url: `ws://192.168.0.100:8190/search?q=${query}`,
|
||||||
|
deserializer: (e) => e.data,
|
||||||
|
serializer: (value) => value,
|
||||||
|
});
|
||||||
|
|
||||||
ws.pipe(
|
ws.pipe(
|
||||||
map((event: any) => {
|
map((event: string) => {
|
||||||
// Mapping to video
|
// Mapping to an array of videos
|
||||||
const video: any = event;
|
const msgReceived: string = event;
|
||||||
const title = video?.filename?.split('/').pop().replace('.mp4', '') ?? 'Unknown title';
|
const msgs = msgReceived.split('\n');
|
||||||
return { title: title, filepath: video.filename } as Video;
|
let videos: Video[] = [];
|
||||||
|
msgs.forEach(msg => {
|
||||||
|
if (msg) {
|
||||||
|
const video = JSON.parse(msg);
|
||||||
|
const title = video?.filename?.split('/').pop().replace('.mp4', '') ?? 'Unknown title';
|
||||||
|
videos.push({ title: title, filepath: video.filename } as Video);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return videos;
|
||||||
})
|
})
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: video => {
|
next: videos => {
|
||||||
if (video) {
|
if (videos) {
|
||||||
this.foundVideos.unshift(video);
|
videos.forEach(video => this.foundVideos.unshift(video));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: err => {
|
error: err => {
|
||||||
if (err instanceof CloseEvent) {
|
if (err instanceof CloseEvent) {
|
||||||
console.log('WebSocket closed');
|
console.log('WebSocket closed', err);
|
||||||
this.searching = false;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error('Error on the socket', err);
|
console.error('Error on the socket', err);
|
||||||
}
|
}
|
||||||
|
this.searching = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user