Compare commits

...
9 Commits
Author SHA1 Message Date
fraujulianandClaude Fable 5.2 ecd37584a0 ci: harden release workflow
CI / format (push) Successful in 28s
CI / lint (push) Successful in 35s
CI / typecheck (push) Successful in 35s
CI / test-and-build (push) Successful in 37s
Pin actions to commit SHAs, restrict releases to main, serialize runs
and run the full check before publishing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-13 15:20:10 +01:00
fraujulianandClaude Fable 5.2 5485b83a79 chore(deps): update dependencies and patch audit findings
CI / format (push) Successful in 29s
CI / lint (push) Successful in 30s
CI / typecheck (push) Successful in 34s
CI / test-and-build (push) Successful in 35s
Update tsup to 9, @discordjs/opus to 0.11 and minor/patch releases.
Override vulnerable glob and minimatch ranges to patched majors.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-13 10:15:00 +01:00
fraujulian fdaa30af1a ci: parallelize Gitea validation jobs
CI / format (push) Successful in 1m45s
CI / lint (push) Successful in 1m44s
CI / typecheck (push) Successful in 58s
CI / test-and-build (push) Successful in 1m25s
2026-10-02 13:17:12 +02:00
fraujulian 94bb33308a ci: label release workflow as CD 2026-10-02 13:16:20 +02:00
fraujulian a5b17dfd2a chore(deps): update dependencies
Build Validation / build (push) Successful in 37s
2026-10-02 12:44:00 +02:00
fraujulian f84a115e32 test(audio): cover URL protocols and reconnects
Build Validation / build (push) Successful in 47s
2026-09-28 13:39:29 +02:00
fraujulian ac20d12b13 feat(voice): retry unrecoverable disconnects
Build Validation / build (push) Successful in 48s
2026-09-28 13:38:14 +02:00
fraujulian 2b90b2775f chore(runtime): support Node.js 22.12 and newer
Build Validation / build (push) Successful in 47s
2026-09-28 13:37:31 +02:00
fraujulian 00875123f5 fix(security): restrict audio URLs to HTTP(S)
Build Validation / build (push) Successful in 1m37s
2026-09-28 13:36:44 +02:00
8 changed files with 1985 additions and 1983 deletions

No files matched your search

+15 -3
View File
@@ -1,4 +1,4 @@
name: Release and Deploy Build
name: CD
on:
workflow_dispatch:
@@ -6,19 +6,25 @@ on:
permissions:
contents: write
# Never run two releases at once: both would publish the same commit under different versions.
concurrency:
group: release
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
if: gitea.ref == 'refs/heads/main'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0
fetch-tags: true
- name: Use Node.js 24.17.0
uses: actions/setup-node@v6
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: '24.17.0'
registry-url: 'https://registry.npmjs.org'
@@ -27,6 +33,9 @@ jobs:
- name: Install Dependencies
run: npm ci
- name: Run Checks
run: npm run check
- name: Set Release Version
run: npm run version:place
env:
@@ -41,6 +50,9 @@ jobs:
- name: Run Build
run: npm run build
# npm trusted publishing (OIDC) does not support Gitea runners, so this uses npm's
# documented fallback: a granular access token scoped to this package, with
# bypass 2FA and a short expiry.
- name: Publish Library
run: npm publish --access public
env:
+58 -5
View File
@@ -1,4 +1,4 @@
name: Build Validation
name: CI
on:
workflow_dispatch:
@@ -6,10 +6,9 @@ on:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
@@ -23,8 +22,62 @@ jobs:
- name: Install Dependencies
run: npm ci
- name: Run Checks
run: npm run check
- name: Check Version
run: npm run version:check
- name: Check Formatting
run: npm run format:check
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Use Node.js 24.17.0
uses: actions/setup-node@v4
with:
node-version: '24.17.0'
- name: Install Dependencies
run: npm ci
- name: Run Lint
run: npm run lint
typecheck:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Use Node.js 24.17.0
uses: actions/setup-node@v4
with:
node-version: '24.17.0'
- name: Install Dependencies
run: npm ci
- name: Run Type Check
run: npm run typecheck
test-and-build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Use Node.js 24.17.0
uses: actions/setup-node@v4
with:
node-version: '24.17.0'
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: npm test -- --runInBand
- name: Run Build
run: npm run build
+8 -2
View File
@@ -18,7 +18,7 @@ Create an [issue](https://git.lechner-systems.at/FrauJulian/Discord-Audio-Stream
## Installation
Node.js `>=24.17.0` and `<25` is required.
Node.js `>=22.12.0` and `<25` is required.
```bash
npm install discord-audio-stream @discordjs/voice @discordjs/opus
@@ -114,6 +114,7 @@ type AudioManagerOptions = {
};
source?: { type: 'url'; url: string } | { type: 'file'; path: string };
renewIntervalMs?: number | false;
reconnectAttempts?: number;
connectTimeoutMs?: number;
onError?: (error: Error) => void;
volume?: {
@@ -124,15 +125,17 @@ type AudioManagerOptions = {
```
`connectTimeoutMs` and numeric `renewIntervalMs` values must be whole milliseconds from `1` through `2_147_483_647`.
`reconnectAttempts` must be a non-negative safe integer. URL sources must use `http:` or `https:`.
`volume.initialPercent` must be a finite number from `0` through `100` and requires `volume.enabled: true`.
### Defaults
| Option | Default |
| ------------------ | ---------- |
| ------------------- | ---------- |
| `ffmpeg.mode` | `'native'` |
| `connectTimeoutMs` | `20_000` |
| `renewIntervalMs` | `false` |
| `reconnectAttempts` | `0` |
| `volume.enabled` | `false` |
### Methods
@@ -188,6 +191,9 @@ Connection renewal is disabled by default because `@discordjs/voice` handles rec
`renewIntervalMs` only when an application has a measured need for periodic restarts. `stop()` and `dispose()` always
clear the renewal timer.
After an unrecoverable disconnect, playback stops by default. Set `reconnectAttempts` to retry joining the configured
voice channel and restarting the current source.
## Errors
The package exports these error classes:
+1814 -1959
View File
File diff suppressed because it is too large. Load diff
+15 -13
View File
@@ -67,29 +67,29 @@
]
},
"devDependencies": {
"@discordjs/opus": "^0.10.0",
"@discordjs/opus": "^0.11.0",
"@jest/globals": "^30.4.1",
"@types/ejs": "^3.1.5",
"@types/node": "^24.0.0",
"@typescript-eslint/eslint-plugin": "^8.67.0",
"@typescript-eslint/parser": "^8.67.0",
"@types/node": "^24.19.2",
"@typescript-eslint/eslint-plugin": "^8.72.2",
"@typescript-eslint/parser": "^8.72.2",
"@typescript/native": "npm:typescript@^7.0.2",
"eslint": "^9.39.5",
"eslint-config-prettier": "^10.1.8",
"eslint-import-resolver-typescript": "^4.4.5",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-n": "^18.3.0",
"eslint-plugin-n": "^18.5.0",
"eslint-plugin-promise": "^7.3.0",
"eslint-plugin-unused-imports": "^4.4.1",
"husky": "^9.1.7",
"jest": "^30.4.2",
"prettier": "^3.9.6",
"ts-jest": "^29.4.12",
"tsup": "^8.5.1",
"@typescript/native": "npm:typescript@^7.0.2",
"jest": "^30.5.2",
"prettier": "^3.10.1",
"ts-jest": "^29.4.15",
"tsup": "^9.0.0",
"typescript": "npm:@typescript/typescript6@^6.0.2"
},
"peerDependencies": {
"@discordjs/opus": "^0.10.0",
"@discordjs/opus": "^0.10.0 || ^0.11.0",
"@discordjs/voice": "^0.19.2",
"ffmpeg-static": "^5.3.0",
"opusscript": "^0.0.8"
@@ -109,10 +109,12 @@
"@discordjs/node-pre-gyp": {
"tar": "^7.5.22"
},
"esbuild": "^0.28.2"
"esbuild": "^0.28.2",
"glob@>=9 <14.0.2": "^14.0.6",
"minimatch@>=7 <11.0.1": "^11.0.8"
},
"engines": {
"node": ">=24.17.0 <25"
"node": ">=22.12.0 <25"
},
"private": false,
"publishConfig": {
+35 -1
View File
@@ -48,6 +48,7 @@ export default class AudioManager implements Disposable {
private connectAttempt: AbortController | undefined;
private renewTimer: NodeJS.Timeout | undefined;
private playbackState: PlaybackState = 'idle';
private reconnectGeneration = 0;
private connectionOptions: VoiceConnectionOptions | undefined;
private audioSource: AudioSource | undefined;
private readonly options: Required<Pick<AudioManagerOptions, 'connectTimeoutMs'>> &
@@ -61,6 +62,13 @@ export default class AudioManager implements Disposable {
assertValidTimerDelay(options.renewIntervalMs, 'renewIntervalMs');
}
if (
options.reconnectAttempts !== undefined &&
(!Number.isSafeInteger(options.reconnectAttempts) || options.reconnectAttempts < 0)
) {
throw new AudioManagerConfigError('reconnectAttempts must be a non-negative safe integer.');
}
if (options.volume?.initialPercent !== undefined) {
if (options.volume.enabled !== true) {
throw new AudioManagerConfigError('volume.initialPercent requires volume.enabled to be true.');
@@ -254,6 +262,7 @@ export default class AudioManager implements Disposable {
return;
}
this.reconnectGeneration += 1;
this.cancelConnectAttempt();
this.clearRenewTimer();
this.stopCurrentPlayback();
@@ -285,6 +294,7 @@ export default class AudioManager implements Disposable {
return;
}
this.reconnectGeneration += 1;
this.cancelConnectAttempt();
this.clearRenewTimer();
this.stopCurrentPlayback();
@@ -307,8 +317,13 @@ export default class AudioManager implements Disposable {
if (this.audioSource.type === 'url') {
try {
const url = new URL(this.audioSource.url);
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new Error('Unsupported audio source protocol.');
}
return {
input: new URL(this.audioSource.url).toString(),
input: url.toString(),
source: this.audioSource,
};
} catch (error) {
@@ -361,6 +376,9 @@ export default class AudioManager implements Disposable {
}
private async handleDisconnectedConnection(connection: VoiceConnection): Promise<void> {
const shouldReconnect = this.resource !== undefined && (this.options.reconnectAttempts ?? 0) > 0;
const reconnectGeneration = this.reconnectGeneration;
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, DISCONNECT_RECOVERY_TIMEOUT_MS),
@@ -371,6 +389,22 @@ export default class AudioManager implements Disposable {
return;
}
if (shouldReconnect) {
this.clearRenewTimer();
for (let attempt = 0; attempt < (this.options.reconnectAttempts ?? 0); attempt += 1) {
try {
await this.start();
return;
} catch (reconnectError) {
error = reconnectError;
}
if (this.reconnectGeneration !== reconnectGeneration || this.playbackState === 'disposed') {
return;
}
}
}
this.clearRenewTimer();
this.stopCurrentPlayback();
this.audioPlayer.stop(true);
+6
View File
@@ -150,6 +150,12 @@ export type AudioManagerOptions = {
*/
renewIntervalMs?: number | false;
/**
* Number of full reconnect and playback restart attempts after an unrecoverable disconnect.
* Disabled by default. Must be a non-negative safe integer.
*/
reconnectAttempts?: number;
/**
* Maximum milliseconds to wait for the Discord voice connection to become ready.
* Must be an integer from `1` through `2_147_483_647`.
+34
View File
@@ -235,6 +235,28 @@ describe('AudioManager', () => {
expect(manager.isConnected).toBe(false);
});
it('reconnects and restarts playback when configured', async () => {
const manager = new AudioManager({
connection: connectionOptions,
source: liveStreamSource,
renewIntervalMs: false,
reconnectAttempts: 1,
});
await manager.start();
jest.mocked(entersState)
.mockRejectedValueOnce(new Error('disconnect'))
.mockRejectedValueOnce(new Error('disconnect'));
jest.mocked(joinVoiceChannel).mockReturnValueOnce(mockSecondVoiceConnection);
mockConnection.state.status = VoiceConnectionStatus.Disconnected;
await listenerFor(connectionListeners, VoiceConnectionStatus.Disconnected)();
expect(joinVoiceChannel).toHaveBeenCalledTimes(2);
expect(startFfmpeg).toHaveBeenCalledTimes(2);
expect(manager.state).toBe('playing');
expect(manager.isConnected).toBe(true);
});
it('cleans up when connection startup fails', async () => {
jest.useFakeTimers();
@@ -599,6 +621,18 @@ describe('AudioManager', () => {
await expect(manager.play()).rejects.toThrow(AudioManagerConfigError);
});
it.each(['file:///etc/passwd', 'ftp://example.com/audio.mp3'])('rejects non-HTTP URL source %s', async (url) => {
const manager = new AudioManager({
connection: connectionOptions,
source: { type: 'url', url },
renewIntervalMs: false,
});
await manager.connect();
await expect(manager.play()).rejects.toThrow(AudioManagerConfigError);
expect(startFfmpeg).not.toHaveBeenCalled();
});
it('applies initial volume only when volume support is enabled', async () => {
const manager = new AudioManager({
connection: connectionOptions,