Giter Site home page Giter Site logo

lavaclient / lavaclient Goto Github PK

View Code? Open in Web Editor NEW
112.0 5.0 15.0 672 KB

A simple, easy-to-use, and flexible lavalink client for node.js

Home Page: https://lavaclient.js.org

License: Apache License 2.0

TypeScript 98.78% JavaScript 1.22%
lavalink audio client discord typescript nodejs

lavaclient's Introduction

A lightweight and powerful lavalink client for nodejs.

  • Easy-to-use: lavaclient has a neat and user-friendly promise-based api.
  • Performant: designed to be small and lightweight, it's a great choice for any project.
  • Library Agnostic: lavaclient doesn't require you to use a specific discord library. Use anything you want!

Support Server


lavaclient © 2018 - 2022

lavaclient's People

Contributors

alphalupine avatar birongliu avatar dastormer avatar dependabot-preview[bot] avatar dependabot[bot] avatar diced avatar huskydog9988 avatar iitzhyper avatar matievisthekat avatar muh9049 avatar serenmodz21 avatar skye-31 avatar soudblox avatar suspiciouslookingowl avatar viztea avatar xgraza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lavaclient's Issues

Replace centra with undici

Lavaclient currently uses centra for HTTP/S requests, and centra uses Node.js build-in HTTP/S modules which are quite slower than undici, on a small benchmark lavaclient with undici way 2x more faster than centra to performing requests.

It would be really nice, if lavaclient replace centra with undici for performance improvement.

Weirdly behaving queue

Describe the bug

Hello, I am currently using lavaclient in production in bot with 4000 servers and I am having issues when using any sharder, that uses clusters(I tried kurasuta and discord-hybrid-sharding), the bot works fine, but after a random time(few hours to 1 day), it starts to glitch, when skipping a song it throws an error TypeError: Cannot read properties of undefined (reading 'title') and when you try to queue another song, it starts to play the song you queued and skips the last one.
I am also using @lavaclient/queue and @lavaclient/spotify

To Reproduce

Steps to reproduce the behavior:

Use kurasuta for example and let the bot run for a few hours to 1 day.

Expected behavior

The bot should work as it should.

Environment

nodejs versions: 18.2.0 and 16.6.2
lavalink version: 3.4
lavaclient version: 4.0.8

bug: position value reverted back to lastPosition when paused

Describe the bug

When player.pause() is called, position value reverted back to lastPosition for few milliseconds

To Reproduce

Steps to reproduce the behavior:

// show current position and lastPosition every second
setInterval(() => {
  const { position, lastPosition } = player;
  console.log("tick", { position, lastPosition });
}, 1000);

// log value before pause
console.log("before", {
  position: player.position,
  lastPosition: player.lastPosition,
});

await player.pause();

// log value after paused
console.log("after", {
  position: player.position,
  lastPosition: player.lastPosition,
});

Output:

tick { position: 967, lastPosition: 0 }
tick { position: 1976, lastPosition: 0 }
tick { position: 2986, lastPosition: 0 }
tick { position: 3992, lastPosition: 0 }
tick { position: 4875, lastPosition: 4840 }
before { position: 5286, lastPosition: 4840 }
after { position: 4840, lastPosition: 4840 } // position value reverted back to lastPosition value
tick { position: 5280, lastPosition: 5280 } // fixed here
tick { position: 5280, lastPosition: 5280 }
tick { position: 5280, lastPosition: 5280 }
tick { position: 5280, lastPosition: 5280 }

I have to add some delay before logging after to get the accurate position value

// log value before pause
console.log("before", {
  position: player.position,
  lastPosition: player.lastPosition,
});

await player.pause();
await new Promise((r) => setTimeout(r, 1000));

// log value after paused
console.log("after", {
  position: player.position,
  lastPosition: player.lastPosition,
});

Output:

tick { position: 975, lastPosition: 0 }
tick { position: 1984, lastPosition: 0 }
tick { position: 2999, lastPosition: 0 }
tick { position: 4009, lastPosition: 0 }
before { position: 4806, lastPosition: 0 }
tick { position: 4760, lastPosition: 4760 }
after { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }

Expected behavior

position value shouldn't revert back to lastPosition value when player paused.

Environment

  • nodejs version: v16.16.0
  • lavalink version: 3.7 (docker)
  • lavaclient version: 4.1.1

Out of memory on player.connect()

not sure if i did something wrong but any time i try connect a player to a channel i get an Out of memory error

Error: Out of memory
at Object.func (C:\Users\Gamer\Desktop\code\Asuna-Eris\node_modules\eris\lib\gateway\Shard.js:1999:52)
at Bucket.check (C:\Users\Gamer\Desktop\code\Asuna-Eris\node_modules\eris\lib\util\Bucket.js:61:22)
at Bucket.queue (C:\Users\Gamer\Desktop\code\Asuna-Eris\node_modules\eris\lib\util\Bucket.js:41:14)
at Shard.sendWS (C:\Users\Gamer\Desktop\code\Asuna-Eris\node_modules\eris\lib\gateway\Shard.js:2008:31)
at Manager.send (C:\Users\Gamer\Desktop\code\Asuna-Eris\src\asuna\functions\lavalink\index.js:22:36)
at Player.connect (C:\Users\Gamer\Desktop\code\Asuna-Eris\node_modules\lavaclient\dist\structures\Player.js:48:35)

v5 finishing touches

v5 seems to be ready for release but there are some things I want to touch up

  • improve docs
  • #88 decided to show up again, now I know how to fix it :D
  • rewrite clustering

might add more later

[Feature Request] Global Event Listener

Hello,

I'd like to discuss a point I noticed while using lavaclient. Currently, in order to listen to an event in lavaclient, we need to add a separate event listener for each player. However, this method can sometimes lead to unnecessary complexity.

My suggestion is to add a mechanism in the lavaclient that allows us to listen to events globally. For example, currently, it's not possible to use something like lavaclient.on('trackEnd', callback), but adding such a feature would provide a much more user-friendly experience.

The addition of this feature would allow users to use lavaclient with less code and in a cleaner way. Additionally, this feature would make existing code more modular and easier to maintain.

I kindly request you to consider my suggestion and to take this feature into account during the development process. I'm available for any additional information or feedback.

Thank you.

ECONNREFUSED error

about a second after the bot starts the console gets spammed with this error message
im not sure why this is occuring.

main ran into an error Error: connect ECONNREFUSED 127.0.0.1:2334 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) { errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 2334 }

Unexpected token in the module

/home/container/node_modules/lavaclient/dist/structures/Socket.js:22
this.secure = data.secure ?? false;
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:931:16)
at Module._compile (internal/modules/cjs/loader.js:979:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/container/node_modules/lavaclient/dist/Structures.js:4:18)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/container/node_modules/lavaclient/dist/index.js:14:20)
at Module._compile (internal/modules/cjs/loader.js:1015:30)

Getting this error when initilazing lavalink the code in my index.js is

const { Manager } = require("lavaclient");

// Create our nodes array.
const nodes = [
  {
    id: "main",
    host: "localhost",
    port: 2333,
    password: "youshallnotpass",
  },
];

// Create our client and manager.

const manager = new Manager(nodes, {
  // The shard count must be 1 or greater, or lavalink would break.
  shards: 1,

  // Send payloads to discord.
  // Note: If you're doing this inside of a class, use an arrow function.
  send(id, data) {
    const guild = client.guilds.cache.get(id);
    if (guild) guild.shard.send(data);
    return;
  }
});

client.on("ready", async  => {
  // lets initialize our manager. This connects to all of the given lavalink nodes.
  await; manager.init(client.user.id);
  console.log("ready");
});

// add our listeners, There are two more like "socketClose" and "socketDisconnect".
manager.on("socketError", ({ id }, error) => console.error(`${id} ran into an error`, error));
manager.on("socketReady", (node) => console.log(`${node.id} connected.`));

// Lets make sure we're supplying voice updates to lavaclient.
client.ws.on("VOICE_STATE_UPDATE", (upd) => manager.stateUpdate(upd));
client.ws.on("VOICE_SERVER_UPDATE", (upd) => manager.serverUpdate(upd));





















server.init(client);
 let vars = {
        data:Server
    };
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.