Skip to content

Commit

Permalink
Refactor Manager class to properly initialize nodes and decode tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
EvarinDev committed Sep 8, 2024
1 parent d75f9b0 commit c6da398
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ export class Manager extends TypedEmitter<ManagerEvents> {
super();

managerCheck(options);

Structure.get("Player").init(this);
Structure.get("Node").init(this);
TrackUtils.init(this);

if (options.trackPartial) {
TrackUtils.setTrackPartial(options.trackPartial);
delete options.trackPartial;
Expand Down Expand Up @@ -134,7 +133,10 @@ export class Manager extends TypedEmitter<ManagerEvents> {
}

if (this.options.nodes) {
for (const nodeOptions of this.options.nodes) new (Structure.get("Node"))(nodeOptions);
for (const nodeOptions of this.options.nodes) {
const node = new (Structure.get("Node"))(nodeOptions);
this.nodes.set(node.options.identifier, node);
}
}
}

Expand Down Expand Up @@ -263,17 +265,18 @@ export class Manager extends TypedEmitter<ManagerEvents> {
* @param tracks
*/
public decodeTracks(tracks: string[]): Promise<TrackData[]> {
return new Promise(async (resolve, reject) => {
return new Promise(async(resolve, reject) => {
const node = this.nodes.first();
if (!node) throw new Error("No available nodes.");

const res = (await node.rest.post("/v4/decodetracks", JSON.stringify(tracks)).catch((err) => reject(err))) as TrackData[];

if (!res) {
return reject(new Error("No data returned from query."));
if (!node) {
return reject(new Error("No available nodes."));
}

return resolve(res);

await node.rest.post("/v4/decodetracks", JSON.stringify(tracks))
.then((res) => {
if (!res) return reject(new Error("No data returned from query."));
resolve(res as TrackData[]);
})
.catch((err) => reject(err));
});
}

Expand Down

0 comments on commit c6da398

Please sign in to comment.