Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shoukaku

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shoukaku - npm Package Compare versions

Comparing version 0.0.9 to 0.1.0

2

package.json
{
"name": "shoukaku",
"version": "0.0.9",
"version": "0.1.0",
"description": "A lavalink client for Discord.js v12 only",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -53,2 +53,10 @@ # Shoukaku

const { Shoukaku } = require('shoukaku');
const MyLavalinkServer = [
{
name: 'my_lavalink_server',
host: 'localhost',
port: 6969,
auth: 'owo_your_password'
}
];
const client = new Client();

@@ -71,10 +79,3 @@

// You need to build shoukaku on your client's ready event for her to work like how its done in this example.
Carrier.build([{
name: 'my_lavalink_server',
host: 'localhost',
port: 6969,
auth: 'owo_your_password'
}], {
id: client.user.id
});
Carrier.build(MyLavalinkServer, { id: client.user.id });
console.log('Bot Initialized');

@@ -126,2 +127,3 @@ })

link.player.on('voiceClose', (reason) => {
// Make sure you log the reason because it may be an error.
console.log(reason);

@@ -128,0 +130,0 @@

@@ -7,4 +7,5 @@ const { SHOUKAKU_STATUS } = require('./ShoukakuConstants.js');

* @param {ShoukakuSocket} node The node where this class initialization is called.
* @param {number} shardID The shardID of the guild.
*/
constructor(node) {
constructor(node, shardID) {
/**

@@ -31,2 +32,7 @@ * The node that governs this Link

/**
* The ID of the shard where this guild is in
* @type {number}
*/
this.shardID = shardID;
/**
* The ID of the voice channel that is being governed by this link.

@@ -88,8 +94,7 @@ * @type {string}

this._timeout = setTimeout(() => {
this.node.links.delete(options.guild_id);
this.state = SHOUKAKU_STATUS.DISCONNECTED;
this._callback(new Error('The voice connection is not established in 15 seconds'));
}, 15000);
this.state = SHOUKAKU_STATUS.CONNECTING;
this._queueConnection(options);
this.state = SHOUKAKU_STATUS.CONNECTING;
}

@@ -102,6 +107,5 @@ /**

this.state = SHOUKAKU_STATUS.DISCONNECTING;
this._clearVoice();
this.player._clearTrack();
this.player.removeAllListeners();
this.node.links.delete(this.guildID);
this.player.removeAllListeners() && this._clearVoice();
this.player._clearTrack() && this.player._clearPlayer();
if (this.state !== SHOUKAKU_STATUS.DISCONNECTED) {

@@ -152,16 +156,21 @@ this._destroy();

event: data
}).then(() => {
clearTimeout(this._timeout);
this.player._listen();
this.state = SHOUKAKU_STATUS.CONNECTED;
this._callback(null, this);
}).catch((error) => {
clearTimeout(this._timeout);
this.node.links.delete(this.guildID);
this.state = SHOUKAKU_STATUS.DISCONNECTED;
this._callback(error);
}).finally(() => {
this._callback = null;
this._timeout = null;
});
})
.then(() => {
if (this.state !== SHOUKAKU_STATUS.CONNECTING) return;
clearTimeout(this._timeout);
this.state = SHOUKAKU_STATUS.CONNECTED;
this._callback(null, this);
})
.catch((error) => {
if (this.state === SHOUKAKU_STATUS.CONNECTING) {
clearTimeout(this._timeout);
this.state = SHOUKAKU_STATUS.DISCONNECTED;
return this._callback(error);
}
this.player.emit('voiceClose', error);
})
.finally(() => {
this._callback = null;
this._timeout = null;
});
}

@@ -177,5 +186,5 @@

this._removeConnection(this.guildID);
this.player.emit('nodeDisconnect', this.name);
this.player._listen('nodeDisconnect', this.name);
}
}
module.exports = ShoukakuLink;
const EventEmitter = require('events');
const { ShoukakuPlayOptions } = require('./ShoukakuConstants.js');
const endEvents = ['end', 'stuck', 'voiceClose', 'nodeDisconnect'];
class ShoukakuPlayer extends EventEmitter {

@@ -60,5 +62,11 @@ /**

/**
* Emitted when the Client's Voice Connection got closed by Discord and not by you.
* Emitted when the Client's Voice Connection got closed by Discord. This can also throw errors so make sure you handle this.
* @event ShoukakuPlayer#voiceClose
* @param {Object} reason
* @example
* // <Player> is your ShoukakuPlayer instance
* <Player>.on('voiceClose', (reason) => {
* console.error(reason);
* <Player>.link.disconnect();
* })
*/

@@ -69,2 +77,8 @@ /**

* @param {string} name The name of the node that disconnected.
* @example
* // <Player> is your ShoukakuPlayer instance
* <Player>.on('nodeDisconnect', (name) => {
* console.log(`Node ${name} which governs this player disconnected.`);
* <Player>.link.disconnect();
* })
*/

@@ -171,9 +185,11 @@ /**

_listen() {
this.on('end', () => this._clearTrack());
this.on('stuck', () => this._clearTrack());
this.on('voiceClose', () => this._clearTrack());
this.on('nodeDisconnect', () => this._clearTrack() && this._clearPlayer());
this.on('playerUpdate', (state) => this.position = state.position);
}
_listen(event, data) {
if (endEvents.includes(event)) {
event === 'nodeDisconnect' ? this._clearTrack() && this._clearPlayer() : this._clearTrack();
this.emit(event, data);
return;
}
this.position = data.position;
this.emit(event, data);
}

@@ -180,0 +196,0 @@ _clearTrack() {

const { SHOUKAKU_STATUS } = require('./ShoukakuConstants.js');
class ShoukakuRouter {
static ReconnectRouter() {
static ReconnectRouter(id) {
for (const node of this.nodes.values()) {
for (const link of node.links.values()) {
if (!link.voiceChannelID) continue;
if (link.state === SHOUKAKU_STATUS.CONNECTING) continue;
node.links.forEach((link) => {
if (!link.voiceChannelID) return;
if (link.state === SHOUKAKU_STATUS.CONNECTING) return;
if (link.shardID !== id) return;
link.connect({

@@ -14,5 +15,5 @@ guild_id: link.guildID,

}, (error) => {
if (error) link.player.emit('voiceClose', error);
if (error) link.player._listen('voiceClose', error);
});
}
});
}

@@ -44,9 +45,9 @@ }

const link = this.links.get(json.guildId);
if (!link) return false;
if (json.op === 'playerUpdate') return link.player.emit('playerUpdate', json.state);
if (!link) return;
if (json.op === 'playerUpdate') return link.player._listen('playerUpdate', json.state);
if (json.op === 'event') {
if (json.type === 'TrackEndEvent') return link.player.emit('end', json);
if (json.type === 'TrackExceptionEvent') return link.player.emit('exception', json);
if (json.type === 'TrackStuckEvent') return link.player.emit('stuck', json);
if (json.type === 'WebSocketClosedEvent') return link.player.emit('voiceClose', json);
if (json.type === 'TrackEndEvent') return link.player._listen('end', json);
if (json.type === 'TrackExceptionEvent') return link.player._listen('exception', json);
if (json.type === 'TrackStuckEvent') return link.player._listen('stuck', json);
if (json.type === 'WebSocketClosedEvent') return link.player._listen('voiceClose', json);
}

@@ -53,0 +54,0 @@ }

@@ -122,3 +122,6 @@ const { SHOUKAKU_STATUS, ShoukakuNodeStats, ShoukakuJoinOptions } = require('./ShoukakuConstants.js');

return reject(new Error('A voice connection is already established in this channel.'));
const newLink = new ShoukakuLink(this);
const guild = this.shoukaku.client.guilds.get(options.guildID);
if (!guild)
return reject(new Error('Guild not found. Cannot continue creating the voice connection.'));
const newLink = new ShoukakuLink(this, guild.shardID);
this.links.set(options.guildID, newLink);

@@ -132,3 +135,7 @@ options = {

newLink.connect(options, (error, value) => {
if (error) return reject(error);
if (error) {
this.links.delete(options.guildID);
reject(error);
return;
}
resolve(value);

@@ -135,0 +142,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc