fixed memory leak; removed unit tests;

This commit is contained in:
Lechner Julian - FrauJulian
2025-08-02 17:55:25 +02:00
parent 94328ef054
commit 4d3351d81e
6 changed files with 7381 additions and 7691 deletions
+25 -1
View File
@@ -18,9 +18,32 @@ Please create an [issue](https://github.com/FrauJulian/DiscordAudioStreamNPM/iss
### Install package
```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
```
**Encryption Libraries (npm install):**
> You only need to install one of these libraries if your system does not support `aes-256-gcm` (verify by running `require('node:crypto').getCiphers().includes('aes-256-gcm')`).
- `sodium-native`
- `sodium`
- `@stablelib/xchacha20poly1305`
- `@noble/ciphers`
- `libsodium-wrappers`
**Opus Libraries (npm install):**
- `@discordjs/opus`
- `opusscript`
**FFmpeg:**
- [`FFmpeg`](https://ffmpeg.org/) (installed and added to environment)
- `ffmpeg-static`
### Create Instance
```js
@@ -65,6 +88,7 @@ let audioManager = new AudioManager({
| `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. |
| `Dispose` | | void | Dispose all data in object. |
| `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. |
-122
View File
@@ -1,122 +0,0 @@
// Jest unit tests for the AudioManager class focusing on functionality and performance
import AudioManager from './src/audioManager'
import { performance } from 'node:perf_hooks'
// Mocking @discordjs/voice
jest.mock('@discordjs/voice', () => {
return {
joinVoiceChannel: jest.fn(() => ({
subscribe: jest.fn(),
destroy: jest.fn(),
setMaxListeners: jest.fn()
})),
createAudioPlayer: jest.fn(() => ({
play: jest.fn(),
pause: jest.fn(),
unpause: jest.fn()
})),
createAudioResource: jest.fn(() => ({
volume: { setVolume: jest.fn() }
}))
}
})
type VoiceConnectionDataModel = {
VoiceChannelId: string
GuildId: string
VoiceAdapter: any
}
type VoiceAudioDataModel = {
ResourceType: 'Link' | 'File'
Resource: string | any
}
const connectionData: VoiceConnectionDataModel = {
VoiceChannelId: '1',
GuildId: '1',
VoiceAdapter: jest.fn()
}
const audioDataFile: VoiceAudioDataModel = {
ResourceType: 'File',
Resource: 'sound.mp3'
}
const audioDataLink: VoiceAudioDataModel = {
ResourceType: 'Link',
Resource: 'https://example.com/sound.mp3'
}
describe('AudioManager', () => {
beforeEach(() => jest.clearAllMocks())
test('CreateConnection initializes voice connection', () => {
const manager = new AudioManager(connectionData, audioDataFile)
const start = performance.now()
manager.CreateConnection()
const duration = performance.now() - start
expect(require('@discordjs/voice').joinVoiceChannel).toHaveBeenCalled()
expect(duration).toBeLessThan(50)
})
test('PlayAudioOnConnection loads file resource', () => {
const manager = new AudioManager(connectionData, audioDataFile)
manager.CreateConnection()
manager.PlayAudioOnConnection()
const voice = require('@discordjs/voice')
expect(voice.createAudioResource).toHaveBeenCalled()
expect(voice.createAudioPlayer).toHaveBeenCalled()
expect(manager['IsAudioPlaying']).toBe(true)
})
test('PlayAudioOnConnection loads link resource', () => {
const manager = new AudioManager(connectionData, audioDataLink)
manager.CreateConnection()
manager.PlayAudioOnConnection()
const voice = require('@discordjs/voice')
expect(voice.createAudioResource).toHaveBeenCalled()
})
test('StopAudioOnConnection resets connection', () => {
const manager = new AudioManager(connectionData, audioDataFile)
manager.CreateConnection()
manager.PlayAudioOnConnection()
manager.StopAudioOnConnection()
const voice = require('@discordjs/voice')
expect(voice.joinVoiceChannel).toHaveBeenCalledTimes(2)
})
test('Pause and Resume audio', () => {
const manager = new AudioManager(connectionData, audioDataFile)
manager.CreateConnection()
manager.PlayAudioOnConnection()
manager.PauseAudio()
manager.ResumeAudio()
const voice = require('@discordjs/voice')
const player = voice.createAudioPlayer.mock.results[0].value
expect(player.pause).toHaveBeenCalled()
expect(player.unpause).toHaveBeenCalled()
})
test('SetVolume validates range', () => {
const manager = new AudioManager(connectionData, audioDataFile)
manager.CreateConnection()
manager.PlayAudioOnConnection()
manager.SetVolume(50)
const res = require('@discordjs/voice').createAudioResource.mock.results[0].value
expect(res.volume.setVolume).toHaveBeenCalledWith(0.5)
expect(() => manager.SetVolume(101)).toThrow()
})
test('DestroyConnection clears flags', () => {
const manager = new AudioManager(connectionData, audioDataFile)
manager.CreateConnection()
manager.DestroyConnection()
const voice = require('@discordjs/voice')
const connection = voice.joinVoiceChannel.mock.results[0].value
expect(connection.destroy).toHaveBeenCalled()
expect(manager['IsActive']).toBe(false)
})
})
-8
View File
@@ -1,8 +0,0 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/Unittests.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
+26 -246
View File
@@ -9,9 +9,7 @@
"version": "0.6.12",
"license": "LGPL-2.1-only",
"dependencies": {
"@noble/ciphers": "^1.3.0",
"@stablelib/xchacha20poly1305": "^2.0.1",
"sodium-native": "^5.0.6"
"@discordjs/voice": "^0.18.0"
},
"devDependencies": {
"@types/ejs": "^3.1.5",
@@ -22,19 +20,13 @@
"npm-check-updates": "^18.0.2",
"ts-jest": "^29.4.0",
"tsup": "^8.5.0",
"typescript": "^5.8.3"
"typescript": "^5.9.2"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://ko-fi.com/FrauJulian"
},
"peerDependencies": {
"@discordjs/voice": "^0.18.0",
"ffmpeg-static": "^5.2.0",
"libsodium-wrappers": "^0.7.15",
"opusscript": "^0.1.1"
}
},
"node_modules/@ampproject/remapping": {
@@ -572,6 +564,7 @@
"resolved": "https://registry.npmjs.org/@derhuerst/http-basic/-/http-basic-8.2.4.tgz",
"integrity": "sha512-F9rL9k9Xjf5blCz8HsJRO4diy111cayL2vkY2XE4r4t3n0yPXVYy3KD3nJ1qbrSn9743UWSXH4IwuCa/HWlGFw==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"caseless": "^0.12.0",
@@ -626,7 +619,6 @@
"resolved": "https://registry.npmjs.org/@discordjs/voice/-/voice-0.18.0.tgz",
"integrity": "sha512-BvX6+VJE5/vhD9azV9vrZEt9hL1G+GlOdsQaVl5iv9n87fkXjf3cSwllhR3GdaUC8m6dqT8umXIWtn3yCu4afg==",
"license": "Apache-2.0",
"peer": true,
"dependencies": {
"@types/ws": "^8.5.12",
"discord-api-types": "^0.37.103",
@@ -654,7 +646,6 @@
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.5.tgz",
"integrity": "sha512-IQdl0Q01m4LrkN1EGIE9lphov5Hy7WWlH6ulf5QdGePLlPas9p2mhgddTEHrlaXYjjFToM1/rWuwF37VF4taaA==",
"license": "Apache-2.0",
"peer": true,
"peerDependencies": {
"@discordjs/opus": ">=0.8.0 <1.0.0",
"ffmpeg-static": "^5.0.2 || ^4.2.7 || ^3.0.0 || ^2.4.0",
@@ -1624,18 +1615,6 @@
"@tybys/wasm-util": "^0.10.0"
}
},
"node_modules/@noble/ciphers": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-1.3.0.tgz",
"integrity": "sha512-2I0gnIVPtfnMw9ee9h1dJG7tp81+8Ob3OJb3Mv37rx5L40/b0i7djjCVvGOVqc9AEIQyvyu1i6ypKdFw8R8gQw==",
"license": "MIT",
"engines": {
"node": "^14.21.3 || >=16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@@ -2018,97 +1997,6 @@
"@sinonjs/commons": "^3.0.1"
}
},
"node_modules/@stablelib/aead": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@stablelib/aead/-/aead-2.0.0.tgz",
"integrity": "sha512-U/RMANRxbT/ahIpYsPSiFwDFNjADHdnCFfmo09MO1ai2XmerPAOPtMl0qmX7XVvygnACC6ijKDyHBoT2rGyElg==",
"license": "MIT"
},
"node_modules/@stablelib/binary": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/binary/-/binary-2.0.1.tgz",
"integrity": "sha512-U9iAO8lXgEDONsA0zPPSgcf3HUBNAqHiJmSHgZz62OvC3Hi2Bhc5kTnQ3S1/L+sthDTHtCMhcEiklmIly6uQ3w==",
"license": "MIT",
"dependencies": {
"@stablelib/int": "^2.0.1"
}
},
"node_modules/@stablelib/chacha": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/chacha/-/chacha-2.0.1.tgz",
"integrity": "sha512-lS1FqtNqofxe2vLkRsLli2m3x/XanUyAYRphLhdHumKeIsLbjbCXdCq3Pf/eWiO7G3QlSG5ViqnoVjktzfLWMg==",
"license": "MIT",
"dependencies": {
"@stablelib/binary": "^2.0.1",
"@stablelib/wipe": "^2.0.1"
}
},
"node_modules/@stablelib/chacha20poly1305": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/chacha20poly1305/-/chacha20poly1305-2.0.1.tgz",
"integrity": "sha512-kOoBsXbDPVRlelzXl+5WViycgM19lD7lF3Bc3KWI+DzId0Stc2HlxAfSc+Xpn3RgqSCl1ZNTXr33LegqBhBBaw==",
"license": "MIT",
"dependencies": {
"@stablelib/aead": "^2.0.0",
"@stablelib/binary": "^2.0.1",
"@stablelib/chacha": "^2.0.1",
"@stablelib/constant-time": "^2.0.1",
"@stablelib/poly1305": "^2.0.1",
"@stablelib/wipe": "^2.0.1"
}
},
"node_modules/@stablelib/constant-time": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/constant-time/-/constant-time-2.0.1.tgz",
"integrity": "sha512-0NWPogffRm+UWBH0+iM5otZmNrVe5OHFIvyoNIVankMAYOQzMwcdVALOVPrB5Ho0dST+Oc3H8/hPh65Z8R/uew==",
"license": "MIT"
},
"node_modules/@stablelib/int": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/int/-/int-2.0.1.tgz",
"integrity": "sha512-Ht63fQp3wz/F8U4AlXEPb7hfJOIILs8Lq55jgtD7KueWtyjhVuzcsGLSTAWtZs3XJDZYdF1WcSKn+kBtbzupww==",
"license": "MIT"
},
"node_modules/@stablelib/poly1305": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/poly1305/-/poly1305-2.0.1.tgz",
"integrity": "sha512-D8xfZcL/5zeVARJ9I2fZOUCnZvsJx8G4JDQvD+ecsnaCildPtqZDwqqjtOc4cfHAdScrMjOzUVsssjXUTBw3YQ==",
"license": "MIT",
"dependencies": {
"@stablelib/constant-time": "^2.0.1",
"@stablelib/wipe": "^2.0.1"
}
},
"node_modules/@stablelib/wipe": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/wipe/-/wipe-2.0.1.tgz",
"integrity": "sha512-1eU2K9EgOcV4qc9jcP6G72xxZxEm5PfeI5H55l08W95b4oRJaqhmlWRc4xZAm6IVSKhVNxMi66V67hCzzuMTAg==",
"license": "MIT"
},
"node_modules/@stablelib/xchacha20": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/xchacha20/-/xchacha20-2.0.1.tgz",
"integrity": "sha512-k55pNv7gIM4mUPU00+nJYTxKiUVNwAtsgrridC0aIU5cVbw9u6qP99x8ENu5eiwOEhZUNg+p3tTOLooCeAOJQA==",
"license": "MIT",
"dependencies": {
"@stablelib/binary": "^2.0.1",
"@stablelib/chacha": "^2.0.1",
"@stablelib/wipe": "^2.0.1"
}
},
"node_modules/@stablelib/xchacha20poly1305": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@stablelib/xchacha20poly1305/-/xchacha20poly1305-2.0.1.tgz",
"integrity": "sha512-OUZnnPsd4y5ConoMtADkxiz308vcYrpFT7hzTgXLo5UMyu7aPAP0FaOM+aJAnV+GHBoWp+2ncDOhvtho3VDp7g==",
"license": "MIT",
"dependencies": {
"@stablelib/aead": "^2.0.0",
"@stablelib/chacha20poly1305": "^2.0.1",
"@stablelib/constant-time": "^2.0.1",
"@stablelib/wipe": "^2.0.1",
"@stablelib/xchacha20": "^2.0.1"
}
},
"node_modules/@tybys/wasm-util": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.0.tgz",
@@ -2238,7 +2126,6 @@
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
"license": "MIT",
"peer": true,
"dependencies": {
"@types/node": "*"
}
@@ -2562,6 +2449,7 @@
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
"integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"debug": "4"
@@ -2802,74 +2690,6 @@
"devOptional": true,
"license": "MIT"
},
"node_modules/bare-addon-resolve": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/bare-addon-resolve/-/bare-addon-resolve-1.9.4.tgz",
"integrity": "sha512-unn6Vy/Yke6F99vg/7tcrvM2KUvIhTNniaSqDbam4AWkd4NhvDVSrQiRYVlNzUV2P7SPobkCK7JFVxrJk9btCg==",
"license": "Apache-2.0",
"dependencies": {
"bare-module-resolve": "^1.10.0",
"bare-semver": "^1.0.0"
},
"peerDependencies": {
"bare-url": "*"
},
"peerDependenciesMeta": {
"bare-url": {
"optional": true
}
}
},
"node_modules/bare-module-resolve": {
"version": "1.10.2",
"resolved": "https://registry.npmjs.org/bare-module-resolve/-/bare-module-resolve-1.10.2.tgz",
"integrity": "sha512-C9COe/GhWfVXKytW3DElTkiBU+Gb2OXeaVkdGdRB/lp26TVLESHkTGS876iceAGdvtPgohfp9nX8vXHGvN3++Q==",
"license": "Apache-2.0",
"dependencies": {
"bare-semver": "^1.0.0"
},
"peerDependencies": {
"bare-url": "*"
},
"peerDependenciesMeta": {
"bare-url": {
"optional": true
}
}
},
"node_modules/bare-os": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.6.1.tgz",
"integrity": "sha512-uaIjxokhFidJP+bmmvKSgiMzj2sV5GPHaZVAIktcxcpCyBFFWO+YlikVAdhmUo2vYFvFhOXIAlldqV29L8126g==",
"license": "Apache-2.0",
"engines": {
"bare": ">=1.14.0"
}
},
"node_modules/bare-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.0.0.tgz",
"integrity": "sha512-tyfW2cQcB5NN8Saijrhqn0Zh7AnFNsnczRcuWODH0eYAXBsJ5gVxAUuNr7tsHSC6IZ77cA0SitzT+s47kot8Mw==",
"license": "Apache-2.0",
"dependencies": {
"bare-os": "^3.0.1"
}
},
"node_modules/bare-semver": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/bare-semver/-/bare-semver-1.0.1.tgz",
"integrity": "sha512-UtggzHLiTrmFOC/ogQ+Hy7VfoKoIwrP1UFcYtTxoCUdLtsIErT8+SWtOC2DH/snT9h+xDrcBEPcwKei1mzemgg==",
"license": "Apache-2.0"
},
"node_modules/bare-url": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.1.5.tgz",
"integrity": "sha512-lNImB5KLN+ggw+SYDYvqf/yCizXIyq8U/nWBlx7m4pc4TKS24SB/1WWskzGacon5cVVAC6qUzCYzI/aMYCf4Ng==",
"license": "Apache-2.0",
"dependencies": {
"bare-path": "^3.0.0"
}
},
"node_modules/brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
@@ -2953,6 +2773,7 @@
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"devOptional": true,
"license": "MIT"
},
"node_modules/bundle-require": {
@@ -3027,6 +2848,7 @@
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
"integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==",
"license": "Apache-2.0",
"optional": true,
"peer": true
},
"node_modules/chalk": {
@@ -3290,6 +3112,7 @@
"node >= 6.0"
],
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"buffer-from": "^1.0.0",
@@ -3349,6 +3172,7 @@
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
"integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==",
"devOptional": true,
"license": "MIT",
"dependencies": {
"ms": "^2.1.3"
@@ -3462,8 +3286,7 @@
"version": "0.37.119",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.119.tgz",
"integrity": "sha512-WasbGFXEB+VQWXlo6IpW3oUv73Yuau1Ig4AZF/m13tXcTKnMpc/mHjpztIlz4+BM9FG9BHQkEXiPto3bKduQUg==",
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/eastasianwidth": {
"version": "0.2.0",
@@ -3520,6 +3343,7 @@
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz",
"integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==",
"license": "MIT",
"optional": true,
"peer": true,
"engines": {
"node": ">=6"
@@ -3734,6 +3558,7 @@
"integrity": "sha512-WrM7kLW+do9HLr+H6tk7LzQ7kPqbAgLjdzNE32+u3Ff11gXt9Kkkd2nusGFrlWMIe+XaA97t+I8JS7sZIrvRgA==",
"hasInstallScript": true,
"license": "GPL-3.0-or-later",
"optional": true,
"peer": true,
"dependencies": {
"@derhuerst/http-basic": "^8.2.0",
@@ -4089,6 +3914,7 @@
"resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.2.tgz",
"integrity": "sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"@types/node": "^10.0.3"
@@ -4099,6 +3925,7 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==",
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/https-proxy-agent": {
@@ -4106,6 +3933,7 @@
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
"integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"agent-base": "6",
@@ -4181,6 +4009,7 @@
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"devOptional": true,
"license": "ISC"
},
"node_modules/is-arrayish": {
@@ -5139,23 +4968,6 @@
"node": ">=6"
}
},
"node_modules/libsodium": {
"version": "0.7.15",
"resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.15.tgz",
"integrity": "sha512-sZwRknt/tUpE2AwzHq3jEyUU5uvIZHtSssktXq7owd++3CSgn8RGrv6UZJJBpP7+iBghBqe7Z06/2M31rI2NKw==",
"license": "ISC",
"peer": true
},
"node_modules/libsodium-wrappers": {
"version": "0.7.15",
"resolved": "https://registry.npmjs.org/libsodium-wrappers/-/libsodium-wrappers-0.7.15.tgz",
"integrity": "sha512-E4anqJQwcfiC6+Yrl01C1m8p99wEhLmJSs0VQqST66SbQXXBoaJY0pF4BNjRYa/sOQAxx6lXAaAFIlx+15tXJQ==",
"license": "ISC",
"peer": true,
"dependencies": {
"libsodium": "^0.7.15"
}
},
"node_modules/lilconfig": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz",
@@ -5438,6 +5250,7 @@
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"devOptional": true,
"license": "MIT"
},
"node_modules/mz": {
@@ -5656,13 +5469,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/opusscript": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.1.1.tgz",
"integrity": "sha512-mL0fZZOUnXdZ78woRXp18lApwpp0lF5tozJOD1Wut0dgrA9WuQTgSels/CSmFleaAZrJi/nci5KOVtbuxeWoQA==",
"license": "MIT",
"peer": true
},
"node_modules/p-limit": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz",
@@ -5742,6 +5548,7 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz",
"integrity": "sha512-60zvsJReQPX5/QP0Kzfd/VrpjScIQ7SHBW6bFCYfEP+fp0Eppr1SHhIO5nd1PjZtvclzSzES9D/p5nFJurwfWg==",
"optional": true,
"peer": true
},
"node_modules/parse-json": {
@@ -5968,6 +5775,7 @@
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
"license": "MIT",
"optional": true,
"peer": true,
"engines": {
"node": ">=0.4.0"
@@ -6033,6 +5841,7 @@
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
"integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"inherits": "^2.0.3",
@@ -6057,19 +5866,6 @@
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/require-addon": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/require-addon/-/require-addon-1.1.0.tgz",
"integrity": "sha512-KbXAD5q2+v1GJnkzd8zzbOxchTkStSyJZ9QwoCq3QwEXAaIlG3wDYRZGzVD357jmwaGY7hr5VaoEAL0BkF0Kvg==",
"license": "Apache-2.0",
"dependencies": {
"bare-addon-resolve": "^1.3.0",
"bare-url": "^2.1.0"
},
"engines": {
"bare": ">=1.10.0"
}
},
"node_modules/require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
@@ -6264,6 +6060,7 @@
}
],
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/semver": {
@@ -6336,19 +6133,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/sodium-native": {
"version": "5.0.6",
"resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-5.0.6.tgz",
"integrity": "sha512-lKSVfjJ867gb3LrnOZ0nuVxZ19//k/YhhYKVWQg4fklZ85YKtDHTxmEuWuk/s62IoiDbKC/DV50pcSd9tgaVew==",
"license": "MIT",
"dependencies": {
"require-addon": "^1.1.0",
"which-runtime": "^1.2.1"
},
"engines": {
"bare": ">=1.16.0"
}
},
"node_modules/source-map": {
"version": "0.8.0-beta.0",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz",
@@ -6408,6 +6192,7 @@
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"safe-buffer": "~5.2.0"
@@ -6977,12 +6762,13 @@
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==",
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/typescript": {
"version": "5.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
"version": "5.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz",
"integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==",
"dev": true,
"license": "Apache-2.0",
"bin": {
@@ -7090,6 +6876,7 @@
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/v8-to-istanbul": {
@@ -7152,12 +6939,6 @@
"node": ">= 8"
}
},
"node_modules/which-runtime": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/which-runtime/-/which-runtime-1.2.1.tgz",
"integrity": "sha512-8feIHccQFH/whiA1fD1b4c5+Q7T4ry1g1oHYc2mHnFh81tTQFsCvy3zhS2geUapkFAVBddUT/AM1a3rbqJweFg==",
"license": "Apache-2.0"
},
"node_modules/wide-align": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz",
@@ -7342,7 +7123,6 @@
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.1.tgz",
"integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=10.0.0"
},
+3 -19
View File
@@ -30,7 +30,6 @@
"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",
"unit-tests": "npx jest --config jest.config.js --verbose --detectOpenHandles"
},
"repository": "https://github.com/FrauJulian/Discord-Audio-Stream",
"bugs": "https://github.com/FrauJulian/Discord-Audio-Stream/issues",
@@ -44,34 +43,19 @@
"stream"
],
"contributors": [
{
"name": "Lechner Julian",
"nickname": "FrauJulian",
"email": "office@lechner-systems.at",
"website": "https://lechner-systems.at/"
}
"Lechner Julian - FrauJulian <office@lechner-systems.at>"
],
"dependencies": {
"@noble/ciphers": "^1.3.0",
"@stablelib/xchacha20poly1305": "^2.0.1",
"sodium-native": "^5.0.6"
"@discordjs/voice": "^0.18.0"
},
"devDependencies": {
"@types/ejs": "^3.1.5",
"@types/jest": "^30.0.0",
"@types/node": "^24.1.0",
"del-cli": "^6.0.0",
"jest": "^30.0.5",
"npm-check-updates": "^18.0.2",
"ts-jest": "^29.4.0",
"tsup": "^8.5.0",
"typescript": "^5.8.3"
},
"peerDependencies": {
"@discordjs/voice": "^0.18.0",
"ffmpeg-static": "^5.2.0",
"libsodium-wrappers": "^0.7.15",
"opusscript": "^0.1.1"
"typescript": "^5.9.2"
},
"engines": {
"node": ">=18"
+46 -14
View File
@@ -11,22 +11,27 @@ 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;
public VoiceConnection?: VoiceConnection = undefined;
public AudioPlayer?: AudioPlayer = undefined;
public AudioResource?: AudioResource = undefined;
protected IsActive: boolean = false;
protected IsAudioPlaying: boolean = false;
protected IsActive?: boolean = undefined;
protected IsAudioPlaying?: boolean = undefined;
protected ConnectionData: VoiceConnectionDataModel | null;
protected AudioData: VoiceAudioDataModel | null;
protected ConnectionData?: VoiceConnectionDataModel;
protected AudioData?: VoiceAudioDataModel;
constructor(connectionData: VoiceConnectionDataModel | null = null, audioData: VoiceAudioDataModel | null = null) {
private TimeoutHandle?: NodeJS.Timeout;
private RenewInMs?: number;
constructor(connectionData?: VoiceConnectionDataModel, audioData?: VoiceAudioDataModel, renewInMs = 5400000) {
this.RenewInMs = renewInMs;
this.ConnectionData = connectionData;
this.AudioData = audioData;
}
public OverrideOptions(connectionData: VoiceConnectionDataModel | null = null, audioData: VoiceAudioDataModel | null = null): void {
public OverrideOptions(connectionData?: VoiceConnectionDataModel, audioData?: VoiceAudioDataModel, renewInMs = 5400000): void {
this.RenewInMs = renewInMs;
this.ConnectionData = connectionData;
this.AudioData = audioData;
}
@@ -48,9 +53,9 @@ export default class AudioManager {
adapterCreator: this.ConnectionData!.VoiceAdapter
});
setTimeout((): void => {
this.TimeoutHandle = setTimeout((): void => {
this.RenewConnectionAndAudio();
}, 5400000);
}, this.RenewInMs);
}
public PlayAudioOnConnection(): void {
@@ -82,13 +87,21 @@ export default class AudioManager {
}
public PauseAudio(): void {
this.CheckIfNull(this.AudioPlayer);
if (this.IsAudioPlaying) {
this.AudioPlayer!.pause();
this.IsAudioPlaying = false;
} else {
throw new TypeError("Audio is not playing.");
}
}
public ResumeAudio(): void {
this.CheckIfNull(this.AudioPlayer);
if (!this.IsAudioPlaying) {
this.AudioPlayer!.unpause();
this.IsAudioPlaying = true;
} else {
throw new TypeError("Audio is playing.");
}
}
public CreateConnectionAndPlayAudio(): void {
@@ -107,15 +120,34 @@ export default class AudioManager {
}
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.CheckIfNull(this.VoiceConnection);
this.AudioResource!.volume!.setVolume(volumeInPercent / 100);
}
public Dispose(): void {
if (this.IsActive != undefined) {
this.DestroyConnection();
this.ConnectionData = undefined;
this.VoiceConnection = undefined;
}
if (this.IsAudioPlaying != undefined) {
this.AudioData = undefined;
this.AudioResource = undefined;
this.AudioPlayer = undefined;
}
if (this.TimeoutHandle) {
clearTimeout(this.TimeoutHandle);
this.TimeoutHandle = undefined;
}
}
private RenewConnectionAndAudio(): void {
this.DestroyConnection(false);
if (this.IsActive) {