❌ AirDCPP code cleaned up from App.tsx
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { create } from "zustand";
|
||||
import { isEmpty, isUndefined } from "lodash";
|
||||
import { isEmpty } from "lodash";
|
||||
import AirDCPPSocket from "../services/DcppSearchService";
|
||||
import axios from "axios";
|
||||
|
||||
export const useStore = create((set, get) => ({
|
||||
// AirDC++ state
|
||||
airDCPPSocketConnected: false,
|
||||
disconnectionInfo: {},
|
||||
airDCPPDisconnectionInfo: {},
|
||||
airDCPPClientConfiguration: {},
|
||||
socketConnectionInformation: {},
|
||||
airDCPPSocketConnectionInformation: {},
|
||||
setAirDCPPSocketConnectionStatus: () =>
|
||||
set((value) => ({
|
||||
airDCPPSocketConnected: value,
|
||||
@@ -15,6 +16,7 @@ export const useStore = create((set, get) => ({
|
||||
getAirDCPPConnectionStatus: () => {
|
||||
const airDCPPSocketConnectionStatus = get().airDCPPSocketConnected;
|
||||
},
|
||||
// Socket.io state
|
||||
}));
|
||||
|
||||
const { getState, setState } = useStore;
|
||||
@@ -44,11 +46,45 @@ const initializeAirDCPPSocket = async (configuration) => {
|
||||
airDCPPSocketConnected: false,
|
||||
});
|
||||
};
|
||||
// AirDC++ Socket-related connection and post-connection
|
||||
// Attempt connection
|
||||
const socketConnectionInformation = await initializedAirDCPPSocket.connect();
|
||||
const airDCPPSocketConnectionInformation =
|
||||
await initializedAirDCPPSocket.connect();
|
||||
setState({
|
||||
socketConnectionInformation,
|
||||
airDCPPSocketConnectionInformation,
|
||||
});
|
||||
|
||||
// Set up event listeners
|
||||
initializedAirDCPPSocket.addListener(
|
||||
`queue`,
|
||||
"queue_bundle_tick",
|
||||
async (downloadProgressData) => {
|
||||
console.log(downloadProgressData);
|
||||
},
|
||||
);
|
||||
initializedAirDCPPSocket.addListener(
|
||||
"queue",
|
||||
"queue_bundle_added",
|
||||
async (data) => {
|
||||
console.log("JEMEN:", data);
|
||||
},
|
||||
);
|
||||
|
||||
initializedAirDCPPSocket.addListener(
|
||||
`queue`,
|
||||
"queue_bundle_status",
|
||||
async (bundleData) => {
|
||||
let count = 0;
|
||||
if (bundleData.status.completed && bundleData.status.downloaded) {
|
||||
// dispatch the action for raw import, with the metadata
|
||||
if (count < 1) {
|
||||
console.log(`[AirDCPP]: Download complete.`);
|
||||
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
// 1. get settings from mongo
|
||||
|
||||
Reference in New Issue
Block a user