Skip to content

Commit

Permalink
feat(player): make options property public
Browse files Browse the repository at this point in the history
  • Loading branch information
larsrickert committed Aug 5, 2022
1 parent 3c4c2f2 commit b39853b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
12 changes: 12 additions & 0 deletions docs/api/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,18 @@ The guild/discord server id passed on player creation.
readonly guildId: string
```

### options

The options passed on player creation.

- **Type**

```ts
readonly options: PlayerOptions
```

For available player options see [PlayerOptions](#playeroptions).

## PlayerEngine

Player engines are the heart of `discord-player-plus`. They are responsible for searching and streaming tracks from streaming providers like YouTube or Spotify.
Expand Down
6 changes: 5 additions & 1 deletion src/engines/spotify.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Readable } from "stream";
import { describe, expect, it, vi } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Playlist, Track } from "../types/engines";
import { spotifyEngine } from "./spotify";
import { youtubeEngine } from "./youtube";
Expand All @@ -13,6 +13,10 @@ describe("spotify engine", () => {
artist: "Luis Fonsi, Daddy Yankee",
};

beforeEach(() => {
vi.resetAllMocks();
});

it("is responsible", async () => {
const queries: string[] = [
"https://open.spotify.com/",
Expand Down
54 changes: 54 additions & 0 deletions src/player-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { beforeEach, describe, expect, it } from "vitest";
import { Player } from "./player";
import { PlayerManager } from "./player-manager";

describe("player manager", () => {
let playerManager: PlayerManager;

beforeEach(() => {
playerManager = new PlayerManager();
});

it("gets and creates player", () => {
const player = playerManager.get("TEST_GUILD_ID");
expect(player).toBeDefined();
expect(player.guildId).toBe("TEST_GUILD_ID");

const player2 = playerManager.get("TEST_GUILD_ID");
expect(player).toBe(player2);
});

it("overrides player settings", () => {
expect(playerManager.options).toBeUndefined();

playerManager = new PlayerManager({
playerDefault: {
initialVolume: 123,
},
});

expect(playerManager.options).toBeDefined();
expect(playerManager.options?.playerDefault?.initialVolume).toBe(123);

const player = playerManager.get("TEST_GUILD_ID", { fileRoot: "./test" });
expect(player.options.initialVolume).toBe(123);
expect(player.options.fileRoot).toBe("./test");
});

it("finds player", () => {
let player = playerManager.find("TEST_GUILD_ID");
expect(player).toBeUndefined();

playerManager.get("TEST_GUILD_ID");
player = playerManager.find("TEST_GUILD_ID");
expect(player).toBeDefined();
});

it("removes player", () => {
let player: Player | undefined = playerManager.get("TEST_GUILD_ID");
expect(player).toBeDefined();
playerManager.remove("TEST_GUILD_ID");
player = playerManager.find("TEST_GUILD_ID");
expect(player).toBeUndefined();
});
});
2 changes: 1 addition & 1 deletion src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Player extends TypedEmitter<PlayerEvents> {

constructor(
public readonly guildId: string,
private readonly options: PlayerOptions = {}
public readonly options: PlayerOptions = {}
) {
super();

Expand Down

0 comments on commit b39853b

Please sign in to comment.