🔧 WIP AirDCPP sockets
This commit is contained in:
@@ -19,15 +19,41 @@ function sleep(ms: number): Promise<NodeJS.Timeout> {
|
||||
|
||||
export const search = async (data: SearchData) => {
|
||||
await SocketService.connect("admin", "password");
|
||||
await sleep(10000);
|
||||
const instance: SearchInstance = await SocketService.post("search");
|
||||
await SocketService.post<SearchResponse>(
|
||||
`${SearchConstants.INSTANCES_URL}/${instance.id}/hub_search`,
|
||||
const unsubscribe = await SocketService.addListener(
|
||||
"search",
|
||||
"search_hub_searches_sent",
|
||||
(searchInfo) => {
|
||||
onSearchSent(data, instance, unsubscribe, searchInfo);
|
||||
},
|
||||
instance.id,
|
||||
);
|
||||
|
||||
const searchQueueInfo = await SocketService.post(
|
||||
`search/${instance.id}/hub_search`,
|
||||
data,
|
||||
);
|
||||
await sleep(10000);
|
||||
const results = await SocketService.get(`search/${instance.id}/results/0/20`);
|
||||
console.log("results", results);
|
||||
SocketService.disconnect();
|
||||
return results;
|
||||
};
|
||||
|
||||
const onSearchSent = async (item, instance, unsubscribe, searchInfo): any => {
|
||||
// Collect the results for 5 seconds
|
||||
await sleep(5000);
|
||||
|
||||
// Get only the first result (results are sorted by relevance)
|
||||
const results = await SocketService.get(
|
||||
`search/${instance.id}/results/0/100`,
|
||||
);
|
||||
|
||||
if (results.length > 0) {
|
||||
// We have results, download the best one
|
||||
console.log("SASAAAA", results);
|
||||
// const result = results[0];
|
||||
// SocketService.post(`search/${instance.id}/results/${result.id}/download`, {
|
||||
// priority: Utils.toApiPriority(item.priority),
|
||||
// target_directory: item.target_directory,
|
||||
// });
|
||||
}
|
||||
return results;
|
||||
// Remove listener for this search instance
|
||||
unsubscribe();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user