27 Commits
Author SHA1 Message Date
fraujulianandGitHub 199f9f84c5 Merge pull request #29 from FrauJulian/20-gigantic-update
Gigantic Update - A lot bug fixes and refactorings.
2025-12-16 16:05:24 +01:00
Lechner Julian - FrauJulian 78bc4b4f24 eslint changes; 2025-12-16 16:02:07 +01:00
Lechner Julian - FrauJulian b0dc3ba52b Added issue templates; Removed packet managers, switched to npm; Fixed a lot of Bugs; Added new Versioning; Added types and reworked docs; Refactored project structure; 2025-12-16 16:01:33 +01:00
fraujulianandGitHub 431c720162 Create SECURITY.md 2025-12-16 12:02:18 +01:00
fraujulianandGitHub 309eb75716 Configure Dependabot for npm and daily updates 2025-12-16 11:58:05 +01:00
Lechner Julian - FrauJulian ba9709ddd1 Updated types 2025-10-10 18:48:22 +02:00
fraujulianandGitHub bac8b41cb9 Merge pull request #19 from FrauJulian/fraujulian
Updated types;
2025-10-10 18:30:25 +02:00
Lechner Julian - FrauJulian ecc3189054 Updated pre-commit 2025-10-10 18:29:28 +02:00
Lechner Julian - FrauJulian 96ee35c1e4 Updated typing export/import; 2025-10-10 18:27:43 +02:00
Lechner Julian - FrauJulian f712ea73d7 Merge remote-tracking branch 'origin/fraujulian' into fraujulian 2025-10-10 18:26:30 +02:00
Lechner Julian - FrauJulian 21d8894629 Updated typing export/import; 2025-10-10 18:25:24 +02:00
fraujulianandGitHub fe79bfae5e Merge pull request #18 from FrauJulian/fraujulian
Updated types and dependencies
2025-10-10 18:12:12 +02:00
Lechner Julian - FrauJulian 0b0ae23c62 Updated package.json 2025-10-10 18:08:42 +02:00
Lechner Julian - FrauJulian 0a0bb40020 Updated README.md; Changed scripts in ci; 2025-10-10 18:05:20 +02:00
Lechner Julian - FrauJulian 36bfd035e9 Updated README.md 2025-10-10 18:01:10 +02:00
Lechner Julian - FrauJulian 20438ee041 Updated README.md 2025-10-10 17:58:19 +02:00
Lechner Julian - FrauJulian 3bb0784850 Merge remote-tracking branch 'origin/fraujulian' into fraujulian
# Conflicts:
#	package.json
2025-10-10 17:55:17 +02:00
Lechner Julian - FrauJulian 7412182b02 Added yarn, bun and pnpm config; Added eslint and prettier; Refactored Type import; Updated Version; 2025-10-10 17:52:56 +02:00
fraujulianandGitHub 9ed38deac9 Bump version from 0.6.13 to 0.6.14 2025-10-03 15:38:08 +02:00
fraujulianandGitHub f9aed907e6 Merge pull request #17 from FrauJulian/fraujulian
Fixed AudioTimeout (hopefully); Refactored; Updated Dependencies;
2025-10-03 15:37:21 +02:00
Lechner Julian - FrauJulian af7a7e266f Fixed AudioTimeout (hopefully); Refactored; Updated Dependencies; 2025-10-03 15:33:49 +02:00
fraujulianandGitHub a5edc62b6a Merge pull request #15 from FrauJulian/13_unit_tests_and_fix_memory_leak
13 unit tests and fix memory leak
2025-08-02 17:58:35 +02:00
Lechner Julian - FrauJulian 9abd7c1628 removed ,; 2025-08-02 17:57:16 +02:00
Lechner Julian - FrauJulian ba6a1e3cc7 update version; 2025-08-02 17:55:58 +02:00
Lechner Julian - FrauJulian 4d3351d81e fixed memory leak; removed unit tests; 2025-08-02 17:55:25 +02:00
Julian lechner 94328ef054 added unit test script; added dev dependencies; 2025-07-31 12:39:36 +02:00
fraujulian 520dee397f Add comprehensive jest unit tests 2025-07-31 09:30:21 +02:00
29 changed files with 8749 additions and 1569 deletions
+9
View File
@@ -0,0 +1,9 @@
*.ts text eol=crlf linguist-language=TypeScript
*.tsx text eol=crlf linguist-language=TypeScript
*.mts text eol=crlf linguist-language=TypeScript
*.cts text eol=crlf linguist-language=TypeScript
*.js text eol=crlf linguist-language=JavaScript
*.jsx text eol=crlf linguist-language=JavaScript
*.mjs text eol=crlf linguist-language=JavaScript
*.cjs text eol=crlf linguist-language=JavaScript
+42
View File
@@ -0,0 +1,42 @@
name: 🐛 Bug Report
description: Report a bug or unexpected behavior
title: '🐛 [BUG]: '
body:
- type: textarea
id: information
attributes:
label: Information
description: Provide all information about the issue.
placeholder: 'What happened? What did you expect to happen?'
validations:
required: false
- type: textarea
id: steps
attributes:
label: Steps to Reproduce
description: Step-by-step instructions to reproduce the issue.
placeholder: |
1. Go to ...
2. Click on ...
3. Observe ...
validations:
required: false
- type: textarea
id: logs
attributes:
label: Logs or Error Messages
description: Paste any relevant console output, stack traces, or screenshots.
placeholder: 'Console output, stacktrace, or screenshots here'
validations:
required: false
- type: input
id: occurrence
attributes:
label: Occurrence Version
description: Specify in which version the issue occurred
placeholder: 'v0.1.TTMMJJ-hhmm'
validations:
required: true
+1
View File
@@ -0,0 +1 @@
blank_issues_enabled: false
+29
View File
@@ -0,0 +1,29 @@
name: 💡 Enhancement
description: Suggest a new feature or improvement
title: '💡 [ENHANCEMENT]: '
body:
- type: textarea
id: description
attributes:
label: Description
description: Describe the new feature or improvement!
placeholder: 'What problem does it solve or what value does it add?'
validations:
required: true
- type: textarea
id: proposal
attributes:
label: Proposed Solution
placeholder: 'Describe how the feature should work.'
validations:
required: false
- type: input
id: implementation
attributes:
label: Implementation Version
description: Specify in which version the enhancement should be released.
placeholder: 'v0.1'
validations:
required: true
+39
View File
@@ -0,0 +1,39 @@
name: ⚙️ Improvement
description: Suggest an improvement to existing functionality, code quality, or performance
title: '⚙️ [Improvement]: '
body:
- type: textarea
id: context
attributes:
label: Current Situation / Context
description: Describe the current behavior or implementation that could be improved.
placeholder: 'Currently, the system loads all users at once, which slows down response time.'
validations:
required: false
- type: textarea
id: proposal
attributes:
label: Proposed Improvement
description: Describe your proposed change or improvement in detail.
placeholder: 'Implement pagination for user loading to reduce memory usage and response time.'
validations:
required: false
- type: textarea
id: benefits
attributes:
label: Expected Benefits
description: Explain how this improvement will help (e.g., better performance, cleaner code, easier maintenance).
placeholder: 'Faster load times, improved scalability, and reduced database load.'
validations:
required: false
- type: input
id: implementation
attributes:
label: Implementation Version
description: Specify in which version the improvement should be released.
placeholder: 'v0.1'
validations:
required: true
+11
View File
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: 'npm' # See documentation for possible values
directory: '/' # Location of package manifests
schedule:
interval: 'daily'
+27 -27
View File
@@ -1,39 +1,39 @@
name: Build Rollout
name: Release and Deploy Build
on:
workflow_dispatch:
workflow_dispatch:
permissions:
id-token: write
contents: read
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: use NodeJS v22.16.0
uses: actions/setup-node@v4
with:
node-version: '22.16.0'
registry-url: 'https://registry.npmjs.org'
always-auth: true
- name: use NodeJS v22.12.0
uses: actions/setup-node@v4
with:
node-version: '22.12.0'
registry-url: 'https://registry.npmjs.org'
always-auth: true
- name: Create .npmrc
run: echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create .npmrc
run: echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install Dependencies
run: npm install
- name: Install Dependencies
run: npm install
- name: run Rollout Build
run: npm run rolloutBuild
- name: run Rollout Build
run: npm run build
- name: Publish Library
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Library
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+16 -15
View File
@@ -1,23 +1,24 @@
name: Build Validation
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: use NodeJS v22.16.0
uses: actions/setup-node@v4
with:
node-version: '22.16.0'
- name: use NodeJS v22.16.0
uses: actions/setup-node@v4
with:
node-version: '22.16.0'
- name: Install Dependencies
run: npm install
- name: Install Dependencies
run: npm install
- name: run Rollout Build
run: npm run rolloutBuild
- name: run Rollout Build
run: npm run build
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
npm run format:check || exit 1
npm run lint || exit 1
+24 -5
View File
@@ -1,10 +1,29 @@
.idea
.git
.github
.git
.idea
.vscode
dist
node_modules
.husky
src
set-version.js
README.md
SECURITY.md
CODEOWNERS
.gitignore
.npmignore
node_modules
src
README.md
.prettierignore
.prettierrc
.gitattributes
tsconfig.json
tsconfig.eslint.json
tsup.config.ts
eslint.config.js
eslint.config.typeaware.cjs
package-lock.json
+5
View File
@@ -0,0 +1,5 @@
node_modules
dist
.git
.idea
.vscode
+13
View File
@@ -0,0 +1,13 @@
{
"printWidth": 120,
"tabWidth": 4,
"useTabs": false,
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"arrowParens": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteProps": "as-needed",
"endOfLine": "crlf"
}
+1
View File
@@ -0,0 +1 @@
FrauJulian
+82 -40
View File
@@ -4,10 +4,23 @@
![GitHub package.json version](https://img.shields.io/github/package-json/v/FrauJulian/discord-audio-stream)
![GitHub Repo stars](https://img.shields.io/github/stars/FrauJulian/discord-audio-stream?style=social)
**This module is designed to work with [discord.js/voice](https://www.npmjs.com/package/@discordjs/voice) v0.18. This
**This module is designed to work with [discord.js/voice](https://www.npmjs.com/package/@discordjs/voice) v0.19. This
package doesn't support older
versions!**
> **Designed for 24/7 audio playing on discord.**
> Discord has many unwanted rate limits, especially in the audio area. This package does all the work and ensures that
> your music never stops playing due to ffmpeg or Discord, with as little effort as possible.
> **Recommended best Practise:**
> Create a global Map<GuildId, AudioManager> (Map<KEY, OBJ>) list. When the feature is used on a guild, add a new
> instance of AudioManager to the Map. When starting the connection or audio, overwrite the respective configuration with
> the override methods provided. To finally start, use the respective method. For each call and each change, retrieve the
> AudioManager object from the list and perform your actions. When the feature get stopped, first execute StopConnection
> and then Dispose to save as much power as possible. Garbage collection does the rest.
> **For large systems:** For large systems, it is recommended to queue each start with the
> packet [p-queue](https://www.npmjs.com/package/p-queue), to give ffmpeg enough time..
## 👋 Support
Please create an [issue](https://github.com/FrauJulian/DiscordAudioStreamNPM/issues) on github or write [
@@ -15,73 +28,102 @@ Please create an [issue](https://github.com/FrauJulian/DiscordAudioStreamNPM/iss
## 📝 Usage
### Install package
### Installation
**Node.js 22.12.0 or newer is required.**
```bash
npm install discord-audio-stream opusscript @discordjs/voice ffmpeg-static sodium-native
npm install discord-audio-stream
yarn add discord-audio-stream
pnpm add discord-audio-stream
bun add discord-audio-stream
```
### Create Instance
#### Required Dependencies
```js
let audioManager = new AudioManager();
- > You only need to install `libsodium-wrappers` if your system does not support `aes-256-gcm` (verify by running
> `require('node:crypto').getCiphers().includes('aes-256-gcm')`).
- `@snazzah/davey`
- `opusscript`
- `prism-media`
- **FFmpeg** (one of those)
- [`FFmpeg`](https://ffmpeg.org/) (installed and added to environment)
- `ffmpeg-static`
### AudioManager Instance
#### Options
**Declaration:**
```
AudioManager(ffmpegMode: string, renewInMs, number, connectionData: VoiceConnectionDataModel, audioData: VoiceAudioDataModel): IDisposable, IAudioManager
```
or (with parameters)
- `ffmpegMode`: 'Native' or 'Standalone'
- Native: [`FFmpeg`](https://ffmpeg.org/) installed on your system
- Standalone: FFmpeg-static as NodeJs library
- `renewInMs`: renewal time > default is 1,5h (5400000ms)
- `connectionData`: Options for voice connection. (type of **VoiceConnectionDataModel**)
- `audioData`: Options for audio player. (type of **VoiceAudioDataModel**)
#### Example
```js
let audioManager = new AudioManager({
let audioManager = new AudioManager(
'Native',
5400000,
{
VoiceChannelId: 0, //voice channel id where to play music
GuildId: 0, //guild id
VoiceAdapter: 0 //guild VoiceAdapter
VoiceAdapter: 0, //guild VoiceAdapter
},
{
ResourceType: "", //resource type like link or file
Resource: "" //auto play link or file name
});
ResourceType: '', //resource type like link or file
Resource: '', //auto play link or file name
},
);
```
### Properties of the AudioManager
### Fields and Methods of AudioManager
#### Properties
#### Fields
| Callable with | Type | Description |
|-------------------|------------------------------|-------------------------------------------------|
| `VoiceConnection` | **VoiceConnection** | VoiceConnection instance from discord.js/voice. |
| `AudioPlayer` | **AudioPlayer** | AudioPlayer instance from discord.js/voice. |
| `AudioResource` | **AudioResource** | AudioResource instance from discord.js/voice. |
| `ConnectionData` | **VoiceConnectionDataModel** | Global variable for connection data. |
| `AudioData` | **AudioDataModel** | Global variable for audio data. |
| Name | Type | Security | Description |
| --------- | -------- | --------- | ------------------------------------- |
| `Active` | **bool** | protected | To check if the connection is active. |
| `Playing` | **bool** | protected | To check if it is playing audio. |
#### Methods
| Callable with | Parameters | Return type | Description |
|--------------------------------|--------------------------------------------------------------------------------------------------------|-------------|--------------------------------------------------------------------|
| `OverrideOptions` | `connectionData` (type of **VoiceConnectionDataModel**), `audioData` (type of **VoiceAudioDataModel**) | void | Method to override global variables, connectionData and audioData. |
| `CreateConnection` | `isRenew` (type of boolean, default value is false) | void | Method to join the voice connection. |
| `PlayAudioOnConnection` | | void | Method to play audio on the existing voice connection. |
| `PauseAudio` | | void | Method to pause the audio. |
| `ResumeAudio` | | void | Method to resume the audio. |
| `StopAudioOnConnection` | | void | Method to stop the audio without destroying voice connection. |
| `CreateConnectionAndPlayAudio` | | void | Method to join the voice connection and play audio. |
| `DestroyConnection` | | void | Method to destroy the voice connection. |
| `SetVolume` | `volume` (type of number, 0 - 100 percent) | void | Method to set the audio volume. | Method to set the volume of the audio. |
| `SetMaxListeners` | `maxListeners` (type of number) | void | Method to set the max listeners of the audio stream. |
| Name | Parameters | Return type | Description |
| ----------------------------- | ------------------------------------------------------- | ------------- | ---------------------------------------- |
| `OverrideVoiceConnectionData` | `connectionData` (type of **VoiceConnectionDataModel**) | void | To override intern connectionData field. |
| `OverrideVoiceAudioDataModel` | `audioData` (type of **VoiceAudioDataModel**) | void | To override intern audioData field. |
| `CreateAndPlay` | | Promise<void> | Join channel and start playing audio. |
| `CreateConnection` | | void | Let it connect to voice channel. |
| `PlayAudio` | | Promise<void> | To start playing audio. |
| `PauseAudio` | | void | Pause the audio, if it is playing |
| `ResumeAudio` | | void | Resume the audio, if it is paused. |
| `SetVolume` | `volume` (type of number, 0 - 100 percent) | void | To set the audio volume. |
| `StopConnection` | | Promise<void> | Method to disconnect the voice channel. |
| `Dispose` | | void | Dispose all data in object. |
##### Types History
## 📝 Types
- [**VoiceConnection** by discord.js/voice](https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts#L166)
- [**AudioPlayer** by discord.js/voice](https://github.com/discordjs/discord.js/blob/main/packages/voice/src/audio/AudioPlayer.ts#L155)
- [**AudioResource** by discord.js/voice](https://github.com/discordjs/discord.js/blob/main/packages/voice/src/audio/AudioResource.ts#L44)
- [**VoiceConnectionDataModel**](https://github.com/FrauJulian/Discord-Audio-Stream/blob/main/src/Models/VoiceConnectionDataModel.d.ts#L3) (custom type)
- [**VoiceAudioDataModel**](https://github.com/FrauJulian/Discord-Audio-Stream/blob/main/src/Models/VoiceAudioDataModel.d.ts#L1) (custom type)
- [**DiscordGatewayAdapterCreator** by discord.js/voice](https://github.com/discordjs/discord.js/blob/main/packages/voice/src/util/adapter.ts#L50)
- [**VoiceConnectionDataModel** by discord-audio-stream](https://github.com/FrauJulian/Discord-Audio-Stream/blob/master/src/types.d.ts#L3)
- [**VoiceAudioDataModel** by discord-audio-stream](https://github.com/FrauJulian/Discord-Audio-Stream/blob/master/src/types.d.ts#L21)
- [**IDisposable** by discord-audio-stream](https://github.com/FrauJulian/Discord-Audio-Stream/blob/master/src/types.d.ts#L38)
- [**IAudioManager** by discord-audio-stream](https://github.com/FrauJulian/Discord-Audio-Stream/blob/master/src/types.d.ts#L45)
## 📋 Credits:
## 📋 Contributors:
~ [**FrauJulian**](https://fraujulian.xyz/).
~ [**FrauJulian - Julian Lechner**](https://fraujulian.xyz/) - CODEOWNER
## 🤝 Enjoy the package?
Give it a star ⭐ on [github](https://github.com/FrauJulian/discord-audio-stream)!
### Greetings from Austria! ⛰️
+18
View File
@@ -0,0 +1,18 @@
# Security Policy
## Supported Versions
Use this section to tell people about which versions of your project are
currently being supported with security updates.
| Version | Supported |
| ------- | ------------------ |
| 0.1.x | :white_check_mark: |
## Reporting a Vulnerability
Use this section to tell people how to report a vulnerability.
Tell them where to go, how often they can expect to get an update on a
reported vulnerability, what to expect if the vulnerability is accepted or
declined, etc.
+91
View File
@@ -0,0 +1,91 @@
/** @type {import('eslint').Linter.FlatConfig[]} */
const config = [
{
ignores: ['dist/', 'node_modules/'],
},
{
files: ['**/*.{ts,tsx,js,cjs,mjs}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parser: require('@typescript-eslint/parser'),
parserOptions: {
ecmaFeatures: {},
},
},
plugins: {
'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
import: require('eslint-plugin-import'),
promise: require('eslint-plugin-promise'),
'unused-imports': require('eslint-plugin-unused-imports'),
n: require('eslint-plugin-n'),
},
rules: {
/* Base */
'no-debugger': 'warn',
/* TypeScript */
'@typescript-eslint/consistent-type-imports': ['warn', { prefer: 'type-imports' }],
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'warn',
'unused-imports/no-unused-vars': [
'warn',
{ vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-explicit-any': 'off',
/* Imports */
'import/first': 'error',
'import/no-duplicates': 'error',
'import/newline-after-import': 'warn',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'**/*.config.{js,cjs,mjs,ts}',
'**/scripts/**',
'**/*.test.{ts,js}',
'**/Testing.{ts,js}',
'**/.eslintrc.{js,cjs}',
],
},
],
/* Node */
'n/no-missing-import': 'off',
'n/no-unsupported-features/es-syntax': 'off',
/* Promis */
'promise/catch-or-return': 'warn',
'promise/always-return': 'off',
/* „Fire-and-forget“-Promises `void` */
'no-void': ['warn', { allowAsStatement: true }],
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
node: true,
},
},
},
{
files: ['**/*.{js,cjs}'],
languageOptions: {
sourceType: 'script',
},
rules: {
'n/global-require': 'off',
},
},
];
module.exports = config;
+25
View File
@@ -0,0 +1,25 @@
/** @type {import('eslint').Linter.FlatConfig[]} */
const base = require('./eslint.config.cjs');
const typeAwareLayer = {
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: require('@typescript-eslint/parser'),
parserOptions: {
project: ['./tsconfig.eslint.json'],
tsconfigRootDir: __dirname,
},
},
plugins: {
'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
},
rules: {
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-misused-promises': ['warn', { checksVoidReturn: false }],
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
},
};
module.exports = [...base, typeAwareLayer];
+7949 -1253
View File
File diff suppressed because it is too large Load Diff
+47 -29
View File
@@ -1,8 +1,8 @@
{
"name": "discord-audio-stream",
"version": "0.6.12",
"version": "0.7.DDDhhmm",
"license": "LGPL-2.1-only",
"description": "NodeJS library to make stream any audio on discord easier.",
"description": "Discord library to make stream any audio easier.",
"exports": {
".": {
"require": {
@@ -25,52 +25,70 @@
"lib": "src"
},
"scripts": {
"updateDependencies": "npx npm-check-updates --upgrade && npm install && echo SUCCEED UPDATE",
"cleanSolution": "del-cli dist && echo SUCCEED CLEAN",
"updateVersion": "npm version patch --no-git-tag-version && echo SUCCEED UPDATE VERSION",
"buildPackage": "tsup && echo SUCCEED BUILD && npm run updateVersion",
"rolloutBuild": "npm run updateDependencies && npm run cleanSolution && tsup"
"update:dependencies": "npx npm-check-updates --upgrade",
"update:version": "node set-version.js",
"lint": "eslint . --ext .ts,.tsx,.js,.cjs,.mjs",
"lint:fix": "eslint . --ext .ts,.tsx,.js,.cjs,.mjs --fix",
"lint:types": "eslint . --config eslint.config.typeaware.cjs --ext .ts,.tsx",
"format": "prettier --write .",
"format:check": "prettier --check .",
"build": "del-cli dist && npm run update:version && tsup",
"prepare": "husky"
},
"repository": "https://github.com/FrauJulian/Discord-Audio-Stream",
"bugs": "https://github.com/FrauJulian/Discord-Audio-Stream/issues",
"funding": "https://ko-fi.com/FrauJulian",
"keywords": [
"discordjs",
"discord.js",
"discord",
"audio",
"discordjs/voice",
"music",
"voice",
"stream"
"audio",
"24/7"
],
"contributors": [
{
"name": "Lechner Julian",
"nickname": "FrauJulian",
"email": "office@lechner-systems.at",
"website": "https://lechner-systems.at/"
}
"FrauJulian - Lechner Julian <fraujulian@lechner.top>"
],
"lint-staged": {
"*.{ts,tsx,js,cjs,mjs}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,yml,yaml}": [
"prettier --write"
]
},
"dependencies": {
"@noble/ciphers": "^1.3.0",
"@stablelib/xchacha20poly1305": "^2.0.1",
"sodium-native": "^5.0.6"
"@typescript-eslint/eslint-plugin": "^8.50.0",
"@typescript-eslint/parser": "^8.50.0"
},
"devDependencies": {
"@types/ejs": "^3.1.5",
"@types/node": "^24.1.0",
"del-cli": "^6.0.0",
"npm-check-updates": "^18.0.2",
"tsup": "^8.5.0",
"typescript": "^5.8.3"
"@types/node": "^25.0.2",
"del-cli": "^7.0.0",
"eslint": "^9.39.2",
"eslint-config-prettier": "^10.1.8",
"eslint-import-resolver-typescript": "^4.4.4",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-n": "^17.23.1",
"eslint-plugin-promise": "^7.2.1",
"eslint-plugin-unused-imports": "^4.3.0",
"husky": "^9.1.7",
"npm-check-updates": "^19.2.0",
"prettier": "^3.7.4",
"ts-jest": "^29.4.6",
"tsup": "^8.5.1",
"typescript": "^5.9.3"
},
"peerDependencies": {
"@discordjs/voice": "^0.18.0",
"@discordjs/voice": "^0.19.0",
"@snazzah/davey": "^0.1.8",
"libsodium-wrappers": "^0.7.15",
"opusscript": "^0.1.1",
"ffmpeg-static": "^5.2.0"
"opusscript": "^0.0.8",
"prism-media": "^1.3.5"
},
"engines": {
"node": ">=18"
"node": ">=22.12.0"
},
"private": false,
"publishConfig": {
+21
View File
@@ -0,0 +1,21 @@
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8').toString());
const [major, minor] = pkg.version.split('.');
const prefix = `${major}.${minor}.`;
const now = new Date();
const start = new Date(now.getFullYear(), 0, 0);
const diff = now - start;
const dayOfYear = Math.floor(diff / (1000 * 60 * 60 * 24));
const hh = String(now.getHours()).padStart(2, '0');
const mm = String(now.getMinutes()).padStart(2, '0');
const newVersion = `${prefix}${String(dayOfYear).padStart(3, '0')}${hh}${mm}`;
pkg.version = newVersion;
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
console.log('Version set to: ', newVersion);
+197
View File
@@ -0,0 +1,197 @@
import type { AudioPlayer, AudioResource, VoiceConnection } from '@discordjs/voice';
import {
createAudioPlayer,
createAudioResource,
entersState,
joinVoiceChannel,
NoSubscriberBehavior,
StreamType,
VoiceConnectionStatus,
} from '@discordjs/voice';
import { join } from 'node:path';
import type { IAudioManager, IDisposable, VoiceAudioDataModel, VoiceConnectionDataModel } from './types';
import { spawn } from 'node:child_process';
import type { Readable } from 'node:stream';
export default class AudioManager implements IAudioManager, IDisposable {
private voiceConnection?: VoiceConnection | null;
private audioPlayer?: AudioPlayer | null;
private audioResource?: AudioResource | null;
protected Active?: boolean | null;
protected Playing?: boolean | null;
private timeout?: NodeJS.Timeout | null;
private ffmpegProcess?: ReturnType<typeof spawn> | null;
private pcmStream?: Readable | null;
constructor(
private readonly ffmpegMode: 'Native' | 'Standalone',
private renewMs: number | null = null,
private connectionData: VoiceConnectionDataModel | null = null,
private audioData: VoiceAudioDataModel | null = null,
) {
this.renewMs = renewMs ? renewMs : 5400000;
}
public OverrideVoiceConnectionData(connectionData: VoiceConnectionDataModel): void {
this.connectionData = connectionData;
}
public OverrideVoiceAudioDataModel(audioData: VoiceAudioDataModel): void {
this.audioData = audioData;
}
public CreateConnection(): void {
this.voiceConnection = joinVoiceChannel({
channelId: this.connectionData!.VoiceChannelId,
guildId: this.connectionData!.GuildId,
adapterCreator: this.connectionData!.VoiceAdapter,
});
this.timeout = setTimeout(async (): Promise<void> => {
await this.StopConnection();
await this.CreateAndPlay();
}, this.renewMs!);
}
public async PlayAudio(): Promise<void> {
if (!this.audioData || !this.voiceConnection) return;
await entersState(this.voiceConnection!, VoiceConnectionStatus.Ready, 20_000);
if (this.ffmpegProcess) {
this.ffmpegProcess.kill('SIGKILL');
this.ffmpegProcess = null;
}
let source: string;
if (this.audioData!.ResourceType === 'File') {
source = join(__dirname, this.audioData!.Resource);
} else if (this.audioData!.ResourceType === 'Link') {
source = this.audioData!.Resource;
} else {
throw new TypeError('Invalid resource type.');
}
this.ffmpegProcess = spawn(
this.ffmpegMode === 'Native' ? 'ffmpeg' : require('ffmpeg-static'),
[
'-loglevel',
'error',
'-i',
source,
'-analyzeduration',
'0',
'-f',
's16le',
'-ar',
'48000',
'-ac',
'2',
'pipe:1',
],
{
stdio: ['ignore', 'pipe', 'pipe'],
},
);
this.pcmStream = this.ffmpegProcess!.stdout as Readable;
this.audioResource = createAudioResource(this.pcmStream, {
inputType: StreamType.Raw,
inlineVolume: true,
});
this.audioPlayer = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});
this.voiceConnection!.subscribe(this.audioPlayer);
this.audioPlayer.play(this.audioResource);
this.Playing = true;
}
public PauseAudio(): void {
if (this.Playing) {
this.audioPlayer!.pause();
this.Playing = false;
} else {
throw new ReferenceError('Audio is not playing.');
}
}
public ResumeAudio(): void {
if (!this.Playing) {
this.audioPlayer!.unpause();
this.Playing = true;
} else {
throw new ReferenceError('Audio is playing.');
}
}
public async CreateAndPlay(): Promise<void> {
this.CreateConnection();
await this.PlayAudio();
}
public async StopConnection(): Promise<void> {
this.voiceConnection?.disconnect();
this.voiceConnection?.destroy();
this.voiceConnection = null;
this.Active = false;
this.Playing = false;
}
public SetVolume(volumeInPercent: number): void {
if (volumeInPercent < 0 || volumeInPercent > 100) throw new Error('Volume must be between 0 and 100.');
this.audioResource!.volume!.setVolume(volumeInPercent / 100);
}
public Dispose(): void {
try {
if (this.timeout) {
clearTimeout(this.timeout);
}
if (this.audioPlayer) {
this.audioPlayer.stop(true);
}
if (this.audioPlayer) {
this.audioPlayer!.stop();
if (this.audioResource && this.audioResource.playStream) {
this.audioResource!.playStream.destroy();
}
}
if (this.voiceConnection) {
this.voiceConnection!.destroy();
}
if (this.ffmpegProcess) {
this.ffmpegProcess.kill('SIGKILL');
this.ffmpegProcess = null;
}
this.pcmStream?.destroy();
this.pcmStream = null;
this.audioPlayer = null;
this.audioResource = null;
this.voiceConnection = null;
this.timeout = null;
this.Active = null;
this.Playing = null;
this.connectionData = null;
this.audioData = null;
this.renewMs = null;
} catch {}
}
}
-137
View File
@@ -1,137 +0,0 @@
import {
AudioPlayer,
AudioResource,
createAudioPlayer,
createAudioResource,
joinVoiceChannel,
VoiceConnection
} from "@discordjs/voice";
import {join} from "node:path";
import {VoiceConnectionDataModel} from "./types/VoiceConnectionDataModel";
import {VoiceAudioDataModel} from "./types/VoiceAudioDataModel";
export default class AudioManager {
public VoiceConnection: VoiceConnection | null = null;
public AudioPlayer: AudioPlayer | null = null;
public AudioResource: AudioResource | null = null;
protected IsActive: boolean = false;
protected IsAudioPlaying: boolean = false;
protected ConnectionData: VoiceConnectionDataModel | null;
protected AudioData: VoiceAudioDataModel | null;
constructor(connectionData: VoiceConnectionDataModel | null = null, audioData: VoiceAudioDataModel | null = null) {
this.ConnectionData = connectionData;
this.AudioData = audioData;
}
public OverrideOptions(connectionData: VoiceConnectionDataModel | null = null, audioData: VoiceAudioDataModel | null = null): void {
this.ConnectionData = connectionData;
this.AudioData = audioData;
}
public CreateConnection(isRenew: boolean = false): void {
this.CheckIfNull(this.ConnectionData);
if (!isRenew) {
if (this.IsActive) {
this.DestroyConnection(false);
} else {
this.IsActive = true;
}
}
this.VoiceConnection = joinVoiceChannel({
channelId: this.ConnectionData!.VoiceChannelId.toString(),
guildId: this.ConnectionData!.GuildId.toString(),
adapterCreator: this.ConnectionData!.VoiceAdapter
});
setTimeout((): void => {
this.RenewConnectionAndAudio();
}, 5400000);
}
public PlayAudioOnConnection(): void {
this.CheckIfNull(this.AudioData);
if (this.AudioData!.ResourceType === "File") {
this.AudioResource = createAudioResource(join(__dirname, this.AudioData!.Resource), {inlineVolume: true});
} else if (this.AudioData!.ResourceType === "Link") {
this.AudioResource = createAudioResource(this.AudioData!.Resource, {inlineVolume: true});
} else {
throw new Error("Invalid resource type.");
}
this.AudioPlayer = createAudioPlayer();
this.AudioPlayer.play(this.AudioResource);
this.VoiceConnection!.subscribe(this.AudioPlayer!);
this.IsAudioPlaying = true;
}
public StopAudioOnConnection(): void {
if (this.IsAudioPlaying) {
this.DestroyConnection(false)
this.CreateConnection();
} else {
throw new Error("Audio is not playing.");
}
}
public PauseAudio(): void {
this.CheckIfNull(this.AudioPlayer);
this.AudioPlayer!.pause();
}
public ResumeAudio(): void {
this.CheckIfNull(this.AudioPlayer);
this.AudioPlayer!.unpause();
}
public CreateConnectionAndPlayAudio(): void {
this.CreateConnection();
this.PlayAudioOnConnection();
}
public DestroyConnection(resetValidationParameters: boolean = true): void {
this.CheckIfNull(this.VoiceConnection);
this.VoiceConnection!.destroy();
if (resetValidationParameters) {
this.IsActive = false;
this.IsAudioPlaying = false;
}
}
public SetMaxListeners(maxListeners: number): void {
this.CheckIfNull(this.VoiceConnection);
this.VoiceConnection!.setMaxListeners(maxListeners);
}
public SetVolume(volumeInPercent: number): void {
if (volumeInPercent < 0 || volumeInPercent > 100) throw new Error("Volume must be between 0 and 100.");
this.AudioResource!.volume!.setVolume(volumeInPercent / 100);
}
private RenewConnectionAndAudio(): void {
this.DestroyConnection(false);
if (this.IsActive) {
this.CreateConnection(true);
if (this.IsAudioPlaying) {
this.PlayAudioOnConnection();
}
}
}
private CheckIfNull<T>(value: T | null): boolean {
if (value === null) {
throw new Error(`${value} cannot be null in this case.`);
}
return true;
}
}
+2 -3
View File
@@ -1,3 +1,2 @@
export {default as AudioManager} from './audioManager';
export type {VoiceConnectionDataModel} from './types/VoiceConnectionDataModel';
export type {VoiceAudioDataModel} from './types/VoiceAudioDataModel';
export { default as AudioManager } from './audio-manager';
export type { VoiceAudioDataModel, VoiceConnectionDataModel } from './types';
+55
View File
@@ -0,0 +1,55 @@
import type { DiscordGatewayAdapterCreator } from '@discordjs/voice';
export type VoiceConnectionDataModel = {
/**
* The ID of the voice channel to connect to.
*/
VoiceChannelId: string;
/**
* The Id of the guild (server) to connect to.
*/
GuildId: string;
/**
* The adapter creator for the voice connection.
* Can be archived by the guild instance via the voiceAdapterCreator property.
*/
VoiceAdapter: DiscordGatewayAdapterCreator;
};
export type VoiceAudioDataModel = {
/**
* The unique identifier for the audio resource.
*/
ResourceType: 'Link' | 'File';
/**
* The URL or file path of the audio resource.
* any is to be assumed to require(filepath)
*/
Resource: string | any;
};
/**
* An interface which is implemented in audio manager
* for a proper Dispose functionality.
*/
export type IDisposable = {
Dispose(): void;
};
/**
* An interface to handle instances later on.
*/
export type IAudioManager = {
OverrideVoiceConnectionData(connectionData: VoiceConnectionDataModel): void;
OverrideVoiceAudioDataModel(audioData: VoiceAudioDataModel): void;
CreateAndPlay(): Promise<void>;
CreateConnection(): void;
PlayAudio(): Promise<void>;
PauseAudio(): void;
ResumeAudio(): void;
StopConnection(): Promise<void>;
SetVolume(volumeInPercent: number): void;
};
-12
View File
@@ -1,12 +0,0 @@
export type VoiceAudioDataModel = {
/**
* The unique identifier for the audio resource.
*/
ResourceType: "Link" | "File";
/**
* The URL or file path of the audio resource.
* any is to be assumed to require(filepath)
*/
Resource: string | any;
}
-19
View File
@@ -1,19 +0,0 @@
import type {DiscordGatewayAdapterCreator} from "@discordjs/voice";
export type VoiceConnectionDataModel = {
/**
* The ID of the voice channel to connect to.
*/
VoiceChannelId: string;
/**
* The Id of the guild (server) to connect to.
*/
GuildId: string;
/**
* The adapter creator for the voice connection.
* Can be archived by the guild instance via the voiceAdapterCreator property.
*/
VoiceAdapter: DiscordGatewayAdapterCreator;
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"]
}
+35 -26
View File
@@ -1,28 +1,37 @@
{
"compilerOptions": {
"strict": true,
"allowJs": false,
"noImplicitAny": true,
"esModuleInterop": true,
"strictNullChecks": true,
"target": "ES2022",
"moduleResolution": "Node",
"module": "CommonJS",
"declaration": true,
"isolatedModules": true,
"noEmit": true,
"outDir": "dist",
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"types": [],
"rootDir": "./",
"outDir": "./dist",
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
},
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"useUnknownInCatchVariables": true,
"skipLibCheck": true,
"noEmitOnError": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
+3 -3
View File
@@ -1,8 +1,8 @@
import {defineConfig} from "tsup";
import { defineConfig } from 'tsup';
export default defineConfig({
format: ["cjs", "esm"],
entry: ["./src/index.ts"],
format: ['cjs', 'esm'],
entry: ['./src/index.ts'],
dts: true,
shims: true,
skipNodeModulesBundle: true,