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

Commit

Permalink
fix: move send out of options
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Oct 15, 2020
1 parent 12a033a commit 8501306
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/Cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import type { ClusterNodeOptions } from './ClusterNode';

export interface ClusterOptions {
filter?: ClusterFilter;
send: ClusterSend;
nodes?: ClusterNodeOptions[];
}

export class Cluster extends BaseCluster {
public filter: ClusterFilter;
public send: ClusterSend;

public constructor(options: ClusterOptions) {
public constructor(options: ClusterOptions, send: ClusterSend) {
super(options.nodes);
this.filter = options.filter || (() => true);
this.send = options.send;
this.send = send;
}
}
4 changes: 2 additions & 2 deletions src/ClusterNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BaseCluster, ClusterSend } from './base/BaseCluster';
import { BaseNode, BaseNodeOptions } from './base/BaseNode';
import { BaseNode, NodeOptions } from './base/BaseNode';

export interface ClusterNodeOptions extends BaseNodeOptions {
export interface ClusterNodeOptions extends NodeOptions {
tags?: Iterable<string>;
}

Expand Down
25 changes: 3 additions & 22 deletions src/Node.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
import { BaseNode, BaseNodeOptions, NodeSend } from './base/BaseNode';

/**
* The options for the node.
*/
export interface NodeOptions extends BaseNodeOptions {
/**
* The send method, this is used by Lavalink to send gateway events to Discord.
* @note You are responsible for properly serializing and encoding the packet for transmission.
* @example
* ```typescript
* // Example for discord.js
* (guildID, packet) => {
* const guild = client.guilds.cache.get(guildID);
* if (guild) return guild.shard.send(packet);
* };
* ```
*/
send: NodeSend;
}
import { BaseNode, NodeOptions, NodeSend } from './base/BaseNode';

export class Node extends BaseNode {
public send: NodeSend;

public constructor(options: NodeOptions) {
public constructor(options: NodeOptions, send: NodeSend) {
super(options);
this.send = options.send;
this.send = send;
}
}
10 changes: 5 additions & 5 deletions src/base/BaseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type VoiceStateUpdate = GatewayVoiceState;
/**
* The options for the node.
*/
export interface BaseNodeOptions {
export interface NodeOptions {
/**
* The password to use to login to the Lavalink server.
* @example
Expand Down Expand Up @@ -102,12 +102,12 @@ export abstract class BaseNode extends EventEmitter {
public http: Http | null = null;
public connection: Connection | null = null;

public voiceStates: Map<string, VoiceStateUpdate> = new Map();
public voiceServers: Map<string, VoiceServerUpdate> = new Map();
public voiceStates = new Map<string, VoiceStateUpdate>();
public voiceServers = new Map<string, VoiceServerUpdate>();

private _expectingConnection: Set<string> = new Set();
private _expectingConnection = new Set<string>();

public constructor({ password, userID, shardCount, hosts, host }: BaseNodeOptions) {
public constructor({ password, userID, shardCount, hosts, host }: NodeOptions) {
super();
this.password = password;
this.userID = userID;
Expand Down

0 comments on commit 8501306

Please sign in to comment.