🧪 AirDCPP Socket scaffold

This commit is contained in:
2021-07-31 13:24:54 -07:00
parent ae5f0b2c0f
commit 802dee8857
3 changed files with 63 additions and 1 deletions

2
.gitignore vendored
View File

@@ -5,7 +5,7 @@ docs/
userdata/
dist/
src/client/assets/scss/App.css
server/
/server/
node_modules/
src/**/*.jsx
tests/__coverage__/

View File

@@ -0,0 +1,42 @@
import SocketService from "../utils/airdcpp.socket.service";
export const foo = SocketService.connect("admin", "password");
interface SearchInstance {
current_search_id: string;
expires_in: number;
id: number;
owner: string;
query: Record<string, unknown>;
queue_time: number;
queued_count: number;
result_count: number;
searches_sent_ago: number;
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
foo.then(async (data) => {
const instance: SearchInstance = await SocketService.post("search");
await sleep(10000);
const searchInfo = await SocketService.post(
`search/${instance.id}/hub_search`,
{
query: {
pattern: "H.P. Lovecraft",
file_type: "compressed",
extensions: ["cbz", "cbr"],
},
hub_urls: [
"nmdcs://piter.feardc.net:411",
"dchub://dc.rutrack.net",
"dchub://dc.elitedc.ru",
],
priority: 1,
},
);
await sleep(10000);
const results = await SocketService.get(`search/${instance.id}/results/0/5`);
console.log(results);
});

View File

@@ -0,0 +1,20 @@
import { Socket } from "airdcpp-apisocket";
import WebSocket from "ws";
const options = {
url: "wss://sab.rishighan.com/api/v1/",
autoReconnect: false,
reconnectInterval: 5,
logLevel: "verbose",
ignoredListenerEvents: [
"transfer_statistics",
"hash_statistics",
"hub_counts_updated",
],
};
const APISocket = Socket(options, WebSocket as any);
type SocketType = typeof APISocket;
export { SocketType as APISocket };
export default APISocket;