Merge pull request #17 from FrauJulian/fraujulian
Fixed AudioTimeout (hopefully); Refactored; Updated Dependencies;
This commit is contained in:
@@ -26,7 +26,8 @@ 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')`).
|
||||
> 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`
|
||||
@@ -78,27 +79,35 @@ let audioManager = new AudioManager({
|
||||
|
||||
#### 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. |
|
||||
| `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. |
|
||||
| Callable with | Parameters | Return type | Description |
|
||||
|--------------------------------|---------------------------------------------------------|-------------|---------------------------------------------------------------|
|
||||
| `OverrideVoiceConnectionData` | `connectionData` (type of **VoiceConnectionDataModel**) | void | Method to override global connectionData variable. |
|
||||
| `OverrideVoiceAudioDataModel` | `audioData` (type of **VoiceAudioDataModel**) | void | Method to override global audioData variable. |
|
||||
| `OverrideRenewInMs` | `renewInMs` (type of int, default value is 5400000) | void | Method to override global renewInMs variable. |
|
||||
| `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. |
|
||||
| `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. |
|
||||
|
||||
##### Types History
|
||||
|
||||
- [**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)
|
||||
- [**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)
|
||||
|
||||
## 📋 Credits:
|
||||
|
||||
|
||||
Generated
+422
-1301
File diff suppressed because it is too large
Load Diff
+7
-7
@@ -43,19 +43,19 @@
|
||||
"stream"
|
||||
],
|
||||
"contributors": [
|
||||
"Lechner Julian - FrauJulian <office@lechner-systems.at>"
|
||||
"FrauJulian - Lechner Julian <fraujulian@lechner.top>"
|
||||
],
|
||||
"dependencies": {
|
||||
"@discordjs/voice": "^0.18.0"
|
||||
"@discordjs/voice": "^0.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ejs": "^3.1.5",
|
||||
"@types/node": "^24.1.0",
|
||||
"del-cli": "^6.0.0",
|
||||
"npm-check-updates": "^18.0.2",
|
||||
"ts-jest": "^29.4.0",
|
||||
"@types/node": "^24.6.2",
|
||||
"del-cli": "^7.0.0",
|
||||
"npm-check-updates": "^19.0.0",
|
||||
"ts-jest": "^29.4.4",
|
||||
"tsup": "^8.5.0",
|
||||
"typescript": "^5.9.2"
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
|
||||
+37
-40
@@ -7,16 +7,15 @@ import {
|
||||
VoiceConnection
|
||||
} from "@discordjs/voice";
|
||||
import {join} from "node:path";
|
||||
import {VoiceConnectionDataModel} from "./types/VoiceConnectionDataModel";
|
||||
import {VoiceAudioDataModel} from "./types/VoiceAudioDataModel";
|
||||
import {VoiceAudioDataModel, VoiceConnectionDataModel} from "./typings";
|
||||
|
||||
export default class AudioManager {
|
||||
public VoiceConnection?: VoiceConnection = undefined;
|
||||
public AudioPlayer?: AudioPlayer = undefined;
|
||||
public AudioResource?: AudioResource = undefined;
|
||||
public VoiceConnection?: VoiceConnection;
|
||||
public AudioPlayer?: AudioPlayer;
|
||||
public AudioResource?: AudioResource;
|
||||
|
||||
protected IsActive?: boolean = undefined;
|
||||
protected IsAudioPlaying?: boolean = undefined;
|
||||
protected IsActive?: boolean;
|
||||
protected IsAudioPlaying?: boolean;
|
||||
|
||||
protected ConnectionData?: VoiceConnectionDataModel;
|
||||
protected AudioData?: VoiceAudioDataModel;
|
||||
@@ -30,9 +29,15 @@ export default class AudioManager {
|
||||
this.AudioData = audioData;
|
||||
}
|
||||
|
||||
public OverrideOptions(connectionData?: VoiceConnectionDataModel, audioData?: VoiceAudioDataModel, renewInMs = 5400000): void {
|
||||
public OverrideRenewInMs(renewInMs: number = 5400000): void {
|
||||
this.RenewInMs = renewInMs;
|
||||
}
|
||||
|
||||
public OverrideVoiceConnectionData(connectionData: VoiceConnectionDataModel): void {
|
||||
this.ConnectionData = connectionData;
|
||||
}
|
||||
|
||||
public OverrideVoiceAudioDataModel(audioData: VoiceAudioDataModel): void {
|
||||
this.AudioData = audioData;
|
||||
}
|
||||
|
||||
@@ -54,7 +59,14 @@ export default class AudioManager {
|
||||
});
|
||||
|
||||
this.TimeoutHandle = setTimeout((): void => {
|
||||
this.RenewConnectionAndAudio();
|
||||
this.DestroyConnection(false);
|
||||
if (this.IsActive) {
|
||||
this.CreateConnection(true);
|
||||
|
||||
if (this.IsAudioPlaying) {
|
||||
this.PlayAudioOnConnection();
|
||||
}
|
||||
}
|
||||
}, this.RenewInMs);
|
||||
}
|
||||
|
||||
@@ -83,7 +95,6 @@ export default class AudioManager {
|
||||
} else {
|
||||
throw new Error("Audio is not playing.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PauseAudio(): void {
|
||||
@@ -110,7 +121,7 @@ export default class AudioManager {
|
||||
}
|
||||
|
||||
public DestroyConnection(resetValidationParameters: boolean = true): void {
|
||||
this.CheckIfNull(this.VoiceConnection);
|
||||
if (this.CheckIfNull(this.VoiceConnection)) return;
|
||||
this.VoiceConnection!.destroy();
|
||||
|
||||
if (resetValidationParameters) {
|
||||
@@ -120,43 +131,29 @@ export default class AudioManager {
|
||||
}
|
||||
|
||||
public SetMaxListeners(maxListeners: number): void {
|
||||
if (this.CheckIfNull(this.VoiceConnection)) return;
|
||||
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);
|
||||
if (volumeInPercent < 0 || volumeInPercent > 100)
|
||||
throw new Error("Volume must be between 0 and 100.");
|
||||
|
||||
if (this.CheckIfNull(this.VoiceConnection)) return;
|
||||
|
||||
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) {
|
||||
this.CreateConnection(true);
|
||||
|
||||
if (this.IsAudioPlaying) {
|
||||
this.PlayAudioOnConnection();
|
||||
}
|
||||
}
|
||||
this.VoiceConnection = undefined;
|
||||
this.AudioPlayer = undefined;
|
||||
this.AudioResource = undefined;
|
||||
this.IsActive = undefined;
|
||||
this.IsAudioPlaying = undefined;
|
||||
this.ConnectionData = undefined;
|
||||
this.AudioData = undefined;
|
||||
this.TimeoutHandle = undefined;
|
||||
this.RenewInMs = undefined;
|
||||
}
|
||||
|
||||
private CheckIfNull<T>(value: T | null): boolean {
|
||||
|
||||
+1
-2
@@ -1,3 +1,2 @@
|
||||
export {default as AudioManager} from './audioManager';
|
||||
export type {VoiceConnectionDataModel} from './types/VoiceConnectionDataModel';
|
||||
export type {VoiceAudioDataModel} from './types/VoiceAudioDataModel';
|
||||
export type {VoiceConnectionDataModel, VoiceAudioDataModel} from './typings';
|
||||
|
||||
Vendored
-12
@@ -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;
|
||||
}
|
||||
@@ -17,3 +17,16 @@ export type VoiceConnectionDataModel = {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user