Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
fix: revert regressions (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored Mar 27, 2021
1 parent aa5033d commit a3bf758
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
45 changes: 28 additions & 17 deletions src/core/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
return this.node.voiceServers.get(this.guildID) ?? null;
}

public async moveTo(node: BaseNode) {
public async moveTo(node: BaseNode): Promise<void> {
if (this.node === node) return;

const { voiceState, voiceServer } = this;
Expand All @@ -96,11 +96,11 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
await Promise.all([node.voiceStateUpdate(voiceState), node.voiceServerUpdate(voiceServer)]);
}

public leave() {
public leave(): Promise<void> {
return this.join(null);
}

public join(channel: string | null, { deaf = false, mute = false }: JoinOptions = {}) {
public join(channel: string | null, { deaf = false, mute = false }: JoinOptions = {}): Promise<void> {
this.node.voiceServers.delete(this.guildID);
this.node.voiceStates.delete(this.guildID);

Expand All @@ -117,7 +117,7 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
return this.node.send(this.guildID, data);
}

public async play(track: string | Track, { start, end, noReplace, pause }: PlayerOptions = {}) {
public async play(track: string | Track, { start, end, noReplace, pause }: PlayerOptions = {}): Promise<void> {
await this.send({
op: 'play',
guildId: this.guildID,
Expand All @@ -132,7 +132,12 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
else this.status = Status.Playing;
}

public setFilters(options: FilterOptions) {
/**
* Sets the filters for the player.
* @note This is not available in Lavalink v3.3.
* @param options The filters to be sent.
*/
public setFilters(options: FilterOptions): Promise<void> {
return this.send({
op: 'filters',
guildId: this.guildID,
Expand All @@ -141,30 +146,36 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
}

/**
* @deprecated Please use `setFilters({ volume })` instead.
* @param volume The new volume to be set.
*/
public setVolume(volume: number) {
return this.setFilters({ volume });
public setVolume(volume: number): Promise<void> {
return this.send({
op: 'volume',
guildId: this.guildID,
volume
});
}

/**
* @deprecated Please use `setFilters({ bands })` instead.
* @param equalizer The equalizer bads to be set.
*/
public setEqualizer(equalizer: readonly EqualizerBand[]) {
return this.setFilters({ equalizer });
public setEqualizer(equalizer: readonly EqualizerBand[]): Promise<void> {
return this.send({
op: 'equalizer',
guildId: this.guildID,
bands: equalizer
});
}

public seek(position: number) {
public seek(position: number): Promise<void> {
return this.send({
op: 'seek',
guildId: this.guildID,
position
});
}

public async pause(pause = true) {
public async pause(pause = true): Promise<void> {
await this.send({
op: 'pause',
guildId: this.guildID,
Expand All @@ -175,7 +186,7 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
else this.status = Status.Playing;
}

public async stop() {
public async stop(): Promise<void> {
await this.send({
op: 'stop',
guildId: this.guildID
Expand All @@ -184,7 +195,7 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
this.status = Status.Ended;
}

public async destroy() {
public async destroy(): Promise<void> {
if (this.node.connected) {
await this.send({
op: 'destroy',
Expand All @@ -195,7 +206,7 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
this.node.players.delete(this.guildID);
}

public voiceUpdate(sessionId: string, event: VoiceServerUpdate) {
public voiceUpdate(sessionId: string, event: VoiceServerUpdate): Promise<void> {
return this.send({
op: 'voiceUpdate',
guildId: this.guildID,
Expand All @@ -204,7 +215,7 @@ export class Player<T extends BaseNode = BaseNode> extends EventEmitter {
});
}

public send(data: OutgoingPayload) {
public send(data: OutgoingPayload): Promise<void> {
const conn = this.node.connection;
if (conn) return conn.send(data);
return Promise.reject(new Error('no WebSocket connection available'));
Expand Down
30 changes: 22 additions & 8 deletions src/types/OutgoingPayloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ export interface OutgoingVoiceUpdatePayload extends BaseOutgoingPayload {
event: VoiceServerUpdate;
}

/**
* @deprecated Use `OutgoingFilterPayload` instead.
*/
export interface OutgoingVolumePayload extends BaseOutgoingPayload {
op: 'volume';

Expand All @@ -114,14 +111,11 @@ export interface EqualizerBand {
* The multiplier of the band. Valid values range from -0.25 to 1.0, where -0.25 means the given band is
* completely muted, and 0.25 means it is doubled. Modifying the gain could also change the volume of the output.
* @default 0
* @range [-0.25, -1]
* @range [-0.25, 1]
*/
gain: number;
}

/**
* @deprecated Use `OutgoingFilterPayload` instead.
*/
export interface OutgoingEqualizerPayload extends BaseOutgoingPayload {
op: 'equalizer';

Expand All @@ -146,11 +140,16 @@ export interface OutgoingConfigureResumingPayload {
timeout?: number;
}

/**
* @note This is not available in Lavalink v3.3.
*/
export interface OutgoingFilterPayload extends BaseOutgoingPayload {
op: 'filters';

/**
* The volume to set the track.
* The volume to set the track. Valid values range from 0 to 5.0, where 0 means the stream is completely muted, and
* 2 means it is doubled.
* @range [0, 5]
*/
volume?: number;

Expand Down Expand Up @@ -192,6 +191,9 @@ export interface OutgoingFilterPayload extends BaseOutgoingPayload {
rotation?: RotationOptions;
}

/**
* @note This is not available in Lavalink v3.3.
*/
export interface KaraokeOptions {
/**
* The level.
Expand All @@ -218,6 +220,9 @@ export interface KaraokeOptions {
filterWidth?: number;
}

/**
* @note This is not available in Lavalink v3.3.
*/
export interface TimescaleOptions {
/**
* The speed of the track. Must be >=0.
Expand All @@ -238,6 +243,9 @@ export interface TimescaleOptions {
rate?: number;
}

/**
* @note This is not available in Lavalink v3.3.
*/
export interface FrequencyDepthOptions {
/**
* The frequency to edit. Must be >0 and <=14.
Expand All @@ -252,6 +260,9 @@ export interface FrequencyDepthOptions {
depth?: number;
}

/**
* @note This is not available in Lavalink v3.3.
*/
export interface DistortionOptions {
/**
* The sine's offset.
Expand Down Expand Up @@ -302,6 +313,9 @@ export interface DistortionOptions {
scale?: number;
}

/**
* @note This is not available in Lavalink v3.3.
*/
export interface RotationOptions {
/**
* The frequency in Hz to rotate.
Expand Down

0 comments on commit a3bf758

Please sign in to comment.