npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@twokei/shoukaku

v1.0.3

Published

Forked Shoukaku module with session dump & recovery

Downloads

8

Readme

Shoukaku

A stable and updated wrapper around Lavalink

This is a modified version used in our application infrastructure. Shoukaku: https://github.com/Deivu/Shoukaku Documentation: https://deivu.github.io/Shoukaku/ Also modified by: https://github.com/MoscowMusic

What's the difference?

We added the "player.info" interface, which wasn't included in Shoukaku, and implemented session recovery from a dump stored in Redis or a Database.

Please, make sure that only the added changes and examples of their usage will be shown, so it's recommended to familiarize yourself with the original repository before starting to read.

Track Interface:

export interface Track {
    encoded: string;
    info: TrackInfo;
};

export interface TrackInfo {
    identifier: string;
    isSeekable: boolean;
    author: string;
    duration: number;
    isStream: boolean;
    position: number;
    title: string;
    uri?: string;
    sourceName?: string;
    artworkUrl?: string;
    isrc?: string;
};
shoukaku.players.get("id").track.info

Session Restore:

You should listen to the "raw" event from Shoukaku and redirect it to your functions, as regular "player.on" will stop working after a restart and will need to be reassigned manually.

shoukaku.on("raw", (name: string, json: any) => {
    // Forward to your functions like that
    this.listeners[(json.op.type || json.op) as keyof PlayerListeners]?.(name, json)
});

"this.listeners" — the "PlayerListeners" assigned through the constructor. An example class is provided below.

import { PlayerUpdate } from "@twokei/shoukaku";

export class PlayerListeners {
    playerUpdate(name: string, data: PlayerUpdate) {
        // Updating data for the received guild
        this.database.updateData("queue", { guild: data.guildId }, 
            { session: this.shoukaku.playersDump.get(data.guildId) }
        );
    };
};

Upon restart, we retrieve the data from the model and give it to Shoukaku.

// queue.session is a PlayerDump that we previously saved using this.shoukaku.playersDump.get(data.guildId).
const previousSessions = await kil.select().from(sessions);

// It doesn't matter how you store the session, but you need to convert them to [String, PlayerDump], where String = guildId
const playerDumps = previousSessions.map((session) => [sessions.guildId, session.state]);

this.shoukaku = new Shoukaku(..., playerDumps);

⚡Twokei Music Bot