audio-channel-queue 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +53 -34
- package/dist/errors.d.ts +137 -0
- package/dist/errors.js +461 -0
- package/dist/index.d.ts +10 -25
- package/dist/index.js +36 -32
- package/dist/info.d.ts +2 -1
- package/dist/info.js +8 -1
- package/dist/pause.d.ts +71 -0
- package/dist/pause.js +205 -2
- package/dist/types.d.ts +93 -20
- package/dist/types.js +20 -0
- package/dist/volume.d.ts +28 -3
- package/dist/volume.js +52 -9
- package/package.json +1 -1
- package/src/core.ts +55 -35
- package/src/errors.ts +480 -0
- package/src/index.ts +87 -83
- package/src/info.ts +8 -1
- package/src/pause.ts +411 -189
- package/src/types.ts +99 -18
- package/src/volume.ts +375 -327
package/dist/info.js
CHANGED
|
@@ -7,7 +7,8 @@ exports.offAudioResume = exports.offAudioPause = exports.onAudioResume = exports
|
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const events_1 = require("./events");
|
|
9
9
|
/**
|
|
10
|
-
* Global array
|
|
10
|
+
* Global array to store audio channels with their queues and callback management
|
|
11
|
+
* Each channel maintains its own audio queue and event callback sets
|
|
11
12
|
*/
|
|
12
13
|
exports.audioChannels = [];
|
|
13
14
|
/**
|
|
@@ -86,6 +87,7 @@ const onAudioProgress = (channelNumber, callback) => {
|
|
|
86
87
|
if (!exports.audioChannels[channelNumber]) {
|
|
87
88
|
exports.audioChannels[channelNumber] = {
|
|
88
89
|
audioCompleteCallbacks: new Set(),
|
|
90
|
+
audioErrorCallbacks: new Set(),
|
|
89
91
|
audioPauseCallbacks: new Set(),
|
|
90
92
|
audioResumeCallbacks: new Set(),
|
|
91
93
|
audioStartCallbacks: new Set(),
|
|
@@ -154,6 +156,7 @@ const onQueueChange = (channelNumber, callback) => {
|
|
|
154
156
|
if (!exports.audioChannels[channelNumber]) {
|
|
155
157
|
exports.audioChannels[channelNumber] = {
|
|
156
158
|
audioCompleteCallbacks: new Set(),
|
|
159
|
+
audioErrorCallbacks: new Set(),
|
|
157
160
|
audioPauseCallbacks: new Set(),
|
|
158
161
|
audioResumeCallbacks: new Set(),
|
|
159
162
|
audioStartCallbacks: new Set(),
|
|
@@ -202,6 +205,7 @@ const onAudioStart = (channelNumber, callback) => {
|
|
|
202
205
|
if (!exports.audioChannels[channelNumber]) {
|
|
203
206
|
exports.audioChannels[channelNumber] = {
|
|
204
207
|
audioCompleteCallbacks: new Set(),
|
|
208
|
+
audioErrorCallbacks: new Set(),
|
|
205
209
|
audioPauseCallbacks: new Set(),
|
|
206
210
|
audioResumeCallbacks: new Set(),
|
|
207
211
|
audioStartCallbacks: new Set(),
|
|
@@ -237,6 +241,7 @@ const onAudioComplete = (channelNumber, callback) => {
|
|
|
237
241
|
if (!exports.audioChannels[channelNumber]) {
|
|
238
242
|
exports.audioChannels[channelNumber] = {
|
|
239
243
|
audioCompleteCallbacks: new Set(),
|
|
244
|
+
audioErrorCallbacks: new Set(),
|
|
240
245
|
audioPauseCallbacks: new Set(),
|
|
241
246
|
audioResumeCallbacks: new Set(),
|
|
242
247
|
audioStartCallbacks: new Set(),
|
|
@@ -270,6 +275,7 @@ const onAudioPause = (channelNumber, callback) => {
|
|
|
270
275
|
if (!exports.audioChannels[channelNumber]) {
|
|
271
276
|
exports.audioChannels[channelNumber] = {
|
|
272
277
|
audioCompleteCallbacks: new Set(),
|
|
278
|
+
audioErrorCallbacks: new Set(),
|
|
273
279
|
audioPauseCallbacks: new Set(),
|
|
274
280
|
audioResumeCallbacks: new Set(),
|
|
275
281
|
audioStartCallbacks: new Set(),
|
|
@@ -303,6 +309,7 @@ const onAudioResume = (channelNumber, callback) => {
|
|
|
303
309
|
if (!exports.audioChannels[channelNumber]) {
|
|
304
310
|
exports.audioChannels[channelNumber] = {
|
|
305
311
|
audioCompleteCallbacks: new Set(),
|
|
312
|
+
audioErrorCallbacks: new Set(),
|
|
306
313
|
audioPauseCallbacks: new Set(),
|
|
307
314
|
audioResumeCallbacks: new Set(),
|
|
308
315
|
audioStartCallbacks: new Set(),
|
package/dist/pause.d.ts
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Pause and resume management functions for the audio-channel-queue package
|
|
3
3
|
*/
|
|
4
|
+
import { FadeType } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Pauses the currently playing audio in a specific channel with smooth volume fade
|
|
7
|
+
* @param fadeType - Type of fade transition to apply
|
|
8
|
+
* @param channelNumber - The channel number to pause (defaults to 0)
|
|
9
|
+
* @returns Promise that resolves when the pause and fade are complete
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* await pauseWithFade(FadeType.Gentle, 0); // Pause with gentle fade out over 800ms
|
|
13
|
+
* await pauseWithFade(FadeType.Dramatic, 1); // Pause with dramatic fade out over 800ms
|
|
14
|
+
* await pauseWithFade(FadeType.Linear, 2); // Linear pause with 800ms fade
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const pauseWithFade: (fadeType?: FadeType, channelNumber?: number) => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Resumes the currently paused audio in a specific channel with smooth volume fade
|
|
20
|
+
* Uses the complementary fade curve automatically based on the pause fade type, or allows override
|
|
21
|
+
* @param fadeType - Optional fade type to override the stored fade type from pause
|
|
22
|
+
* @param channelNumber - The channel number to resume (defaults to 0)
|
|
23
|
+
* @returns Promise that resolves when the resume and fade are complete
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* await resumeWithFade(); // Resume with automatically paired fade curve from pause
|
|
27
|
+
* await resumeWithFade(FadeType.Dramatic, 0); // Override with dramatic fade
|
|
28
|
+
* await resumeWithFade(FadeType.Linear); // Override with linear fade on default channel
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const resumeWithFade: (fadeType?: FadeType, channelNumber?: number) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Toggles pause/resume state for a specific channel with integrated fade
|
|
34
|
+
* @param fadeType - Type of fade transition to apply when pausing
|
|
35
|
+
* @param channelNumber - The channel number to toggle (defaults to 0)
|
|
36
|
+
* @returns Promise that resolves when the toggle and fade are complete
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* await togglePauseWithFade(FadeType.Gentle, 0); // Toggle with gentle fade
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const togglePauseWithFade: (fadeType?: FadeType, channelNumber?: number) => Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Pauses all currently playing audio across all channels with smooth volume fade
|
|
45
|
+
* @param fadeType - Type of fade transition to apply to all channels
|
|
46
|
+
* @returns Promise that resolves when all channels are paused and faded
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* await pauseAllWithFade('dramatic'); // Pause everything with dramatic fade
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const pauseAllWithFade: (fadeType?: FadeType) => Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Resumes all currently paused audio across all channels with smooth volume fade
|
|
55
|
+
* Uses automatically paired fade curves based on each channel's pause fade type
|
|
56
|
+
* @returns Promise that resolves when all channels are resumed and faded
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* await resumeAllWithFade(); // Resume everything with paired fade curves
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const resumeAllWithFade: () => Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Toggles pause/resume state for all channels with integrated fade
|
|
65
|
+
* If any channels are playing, all will be paused with fade
|
|
66
|
+
* If all channels are paused, all will be resumed with fade
|
|
67
|
+
* @param fadeType - Type of fade transition to apply when pausing
|
|
68
|
+
* @returns Promise that resolves when all toggles and fades are complete
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* await togglePauseAllWithFade('gentle'); // Global toggle with gentle fade
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const togglePauseAllWithFade: (fadeType?: FadeType) => Promise<void>;
|
|
4
75
|
/**
|
|
5
76
|
* Pauses the currently playing audio in a specific channel
|
|
6
77
|
* @param channelNumber - The channel number to pause (defaults to 0)
|
package/dist/pause.js
CHANGED
|
@@ -12,10 +12,213 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.togglePauseAllChannels = exports.getAllChannelsPauseState = exports.isChannelPaused = exports.resumeAllChannels = exports.pauseAllChannels = exports.togglePauseChannel = exports.resumeChannel = exports.pauseChannel = void 0;
|
|
15
|
+
exports.togglePauseAllChannels = exports.getAllChannelsPauseState = exports.isChannelPaused = exports.resumeAllChannels = exports.pauseAllChannels = exports.togglePauseChannel = exports.resumeChannel = exports.pauseChannel = exports.togglePauseAllWithFade = exports.resumeAllWithFade = exports.pauseAllWithFade = exports.togglePauseWithFade = exports.resumeWithFade = exports.pauseWithFade = void 0;
|
|
16
|
+
const types_1 = require("./types");
|
|
16
17
|
const info_1 = require("./info");
|
|
17
18
|
const utils_1 = require("./utils");
|
|
18
19
|
const events_1 = require("./events");
|
|
20
|
+
const volume_1 = require("./volume");
|
|
21
|
+
/**
|
|
22
|
+
* Predefined fade configurations for different transition types
|
|
23
|
+
*/
|
|
24
|
+
const FADE_CONFIGS = {
|
|
25
|
+
[types_1.FadeType.Linear]: { duration: 800, pauseCurve: types_1.EasingType.Linear, resumeCurve: types_1.EasingType.Linear },
|
|
26
|
+
[types_1.FadeType.Gentle]: { duration: 800, pauseCurve: types_1.EasingType.EaseOut, resumeCurve: types_1.EasingType.EaseIn },
|
|
27
|
+
[types_1.FadeType.Dramatic]: { duration: 800, pauseCurve: types_1.EasingType.EaseIn, resumeCurve: types_1.EasingType.EaseOut }
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Gets the current volume for a channel, accounting for synchronous state
|
|
31
|
+
* @param channelNumber - The channel number
|
|
32
|
+
* @returns Current volume level (0-1)
|
|
33
|
+
*/
|
|
34
|
+
const getChannelVolumeSync = (channelNumber) => {
|
|
35
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
36
|
+
return (channel === null || channel === void 0 ? void 0 : channel.volume) || 1.0;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Sets the channel volume synchronously in internal state
|
|
40
|
+
* @param channelNumber - The channel number
|
|
41
|
+
* @param volume - Volume level (0-1)
|
|
42
|
+
*/
|
|
43
|
+
const setChannelVolumeSync = (channelNumber, volume) => {
|
|
44
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
45
|
+
if (channel) {
|
|
46
|
+
channel.volume = volume;
|
|
47
|
+
if (channel.queue.length > 0) {
|
|
48
|
+
channel.queue[0].volume = volume;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Pauses the currently playing audio in a specific channel with smooth volume fade
|
|
54
|
+
* @param fadeType - Type of fade transition to apply
|
|
55
|
+
* @param channelNumber - The channel number to pause (defaults to 0)
|
|
56
|
+
* @returns Promise that resolves when the pause and fade are complete
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* await pauseWithFade(FadeType.Gentle, 0); // Pause with gentle fade out over 800ms
|
|
60
|
+
* await pauseWithFade(FadeType.Dramatic, 1); // Pause with dramatic fade out over 800ms
|
|
61
|
+
* await pauseWithFade(FadeType.Linear, 2); // Linear pause with 800ms fade
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
const pauseWithFade = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (fadeType = types_1.FadeType.Gentle, channelNumber = 0) {
|
|
65
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
66
|
+
if (!channel || channel.queue.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
const currentAudio = channel.queue[0];
|
|
69
|
+
// Don't pause if already paused or ended
|
|
70
|
+
if (currentAudio.paused || currentAudio.ended)
|
|
71
|
+
return;
|
|
72
|
+
const config = FADE_CONFIGS[fadeType];
|
|
73
|
+
const originalVolume = getChannelVolumeSync(channelNumber);
|
|
74
|
+
// Store fade state for resumeWithFade to use
|
|
75
|
+
channel.fadeState = {
|
|
76
|
+
originalVolume,
|
|
77
|
+
fadeType,
|
|
78
|
+
isPaused: true
|
|
79
|
+
};
|
|
80
|
+
if (config.duration === 0) {
|
|
81
|
+
// Instant pause
|
|
82
|
+
yield (0, exports.pauseChannel)(channelNumber);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Fade to 0 with pause curve, then pause
|
|
86
|
+
yield (0, volume_1.transitionVolume)(channelNumber, 0, config.duration, config.pauseCurve);
|
|
87
|
+
yield (0, exports.pauseChannel)(channelNumber);
|
|
88
|
+
// Reset volume to original for resume (synchronously to avoid state issues)
|
|
89
|
+
setChannelVolumeSync(channelNumber, originalVolume);
|
|
90
|
+
});
|
|
91
|
+
exports.pauseWithFade = pauseWithFade;
|
|
92
|
+
/**
|
|
93
|
+
* Resumes the currently paused audio in a specific channel with smooth volume fade
|
|
94
|
+
* Uses the complementary fade curve automatically based on the pause fade type, or allows override
|
|
95
|
+
* @param fadeType - Optional fade type to override the stored fade type from pause
|
|
96
|
+
* @param channelNumber - The channel number to resume (defaults to 0)
|
|
97
|
+
* @returns Promise that resolves when the resume and fade are complete
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* await resumeWithFade(); // Resume with automatically paired fade curve from pause
|
|
101
|
+
* await resumeWithFade(FadeType.Dramatic, 0); // Override with dramatic fade
|
|
102
|
+
* await resumeWithFade(FadeType.Linear); // Override with linear fade on default channel
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
const resumeWithFade = (fadeType_1, ...args_1) => __awaiter(void 0, [fadeType_1, ...args_1], void 0, function* (fadeType, channelNumber = 0) {
|
|
106
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
107
|
+
if (!channel || channel.queue.length === 0)
|
|
108
|
+
return;
|
|
109
|
+
const fadeState = channel.fadeState;
|
|
110
|
+
if (!fadeState || !fadeState.isPaused) {
|
|
111
|
+
// Fall back to regular resume if no fade state
|
|
112
|
+
yield (0, exports.resumeChannel)(channelNumber);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Use provided fadeType or fall back to stored fadeType from pause
|
|
116
|
+
const effectiveFadeType = fadeType || fadeState.fadeType;
|
|
117
|
+
const config = FADE_CONFIGS[effectiveFadeType];
|
|
118
|
+
if (config.duration === 0) {
|
|
119
|
+
// Instant resume
|
|
120
|
+
yield (0, exports.resumeChannel)(channelNumber);
|
|
121
|
+
fadeState.isPaused = false;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Set volume to 0, resume, then fade to original with resume curve
|
|
125
|
+
setChannelVolumeSync(channelNumber, 0);
|
|
126
|
+
yield (0, exports.resumeChannel)(channelNumber);
|
|
127
|
+
yield (0, volume_1.transitionVolume)(channelNumber, fadeState.originalVolume, config.duration, config.resumeCurve);
|
|
128
|
+
fadeState.isPaused = false;
|
|
129
|
+
});
|
|
130
|
+
exports.resumeWithFade = resumeWithFade;
|
|
131
|
+
/**
|
|
132
|
+
* Toggles pause/resume state for a specific channel with integrated fade
|
|
133
|
+
* @param fadeType - Type of fade transition to apply when pausing
|
|
134
|
+
* @param channelNumber - The channel number to toggle (defaults to 0)
|
|
135
|
+
* @returns Promise that resolves when the toggle and fade are complete
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* await togglePauseWithFade(FadeType.Gentle, 0); // Toggle with gentle fade
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
const togglePauseWithFade = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (fadeType = types_1.FadeType.Gentle, channelNumber = 0) {
|
|
142
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
143
|
+
if (!channel || channel.queue.length === 0)
|
|
144
|
+
return;
|
|
145
|
+
const currentAudio = channel.queue[0];
|
|
146
|
+
if (currentAudio.paused) {
|
|
147
|
+
yield (0, exports.resumeWithFade)(undefined, channelNumber);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
yield (0, exports.pauseWithFade)(fadeType, channelNumber);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
exports.togglePauseWithFade = togglePauseWithFade;
|
|
154
|
+
/**
|
|
155
|
+
* Pauses all currently playing audio across all channels with smooth volume fade
|
|
156
|
+
* @param fadeType - Type of fade transition to apply to all channels
|
|
157
|
+
* @returns Promise that resolves when all channels are paused and faded
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* await pauseAllWithFade('dramatic'); // Pause everything with dramatic fade
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
const pauseAllWithFade = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (fadeType = types_1.FadeType.Gentle) {
|
|
164
|
+
const pausePromises = [];
|
|
165
|
+
info_1.audioChannels.forEach((_channel, index) => {
|
|
166
|
+
pausePromises.push((0, exports.pauseWithFade)(fadeType, index));
|
|
167
|
+
});
|
|
168
|
+
yield Promise.all(pausePromises);
|
|
169
|
+
});
|
|
170
|
+
exports.pauseAllWithFade = pauseAllWithFade;
|
|
171
|
+
/**
|
|
172
|
+
* Resumes all currently paused audio across all channels with smooth volume fade
|
|
173
|
+
* Uses automatically paired fade curves based on each channel's pause fade type
|
|
174
|
+
* @returns Promise that resolves when all channels are resumed and faded
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* await resumeAllWithFade(); // Resume everything with paired fade curves
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
const resumeAllWithFade = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
+
const resumePromises = [];
|
|
182
|
+
info_1.audioChannels.forEach((_channel, index) => {
|
|
183
|
+
resumePromises.push((0, exports.resumeWithFade)(undefined, index));
|
|
184
|
+
});
|
|
185
|
+
yield Promise.all(resumePromises);
|
|
186
|
+
});
|
|
187
|
+
exports.resumeAllWithFade = resumeAllWithFade;
|
|
188
|
+
/**
|
|
189
|
+
* Toggles pause/resume state for all channels with integrated fade
|
|
190
|
+
* If any channels are playing, all will be paused with fade
|
|
191
|
+
* If all channels are paused, all will be resumed with fade
|
|
192
|
+
* @param fadeType - Type of fade transition to apply when pausing
|
|
193
|
+
* @returns Promise that resolves when all toggles and fades are complete
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* await togglePauseAllWithFade('gentle'); // Global toggle with gentle fade
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
const togglePauseAllWithFade = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (fadeType = types_1.FadeType.Gentle) {
|
|
200
|
+
let hasPlayingChannel = false;
|
|
201
|
+
// Check if any channel is currently playing
|
|
202
|
+
for (let i = 0; i < info_1.audioChannels.length; i++) {
|
|
203
|
+
const channel = info_1.audioChannels[i];
|
|
204
|
+
if (channel && channel.queue.length > 0) {
|
|
205
|
+
const currentAudio = channel.queue[0];
|
|
206
|
+
if (!currentAudio.paused && !currentAudio.ended) {
|
|
207
|
+
hasPlayingChannel = true;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// If any channel is playing, pause all with fade
|
|
213
|
+
// If no channels are playing, resume all with fade
|
|
214
|
+
if (hasPlayingChannel) {
|
|
215
|
+
yield (0, exports.pauseAllWithFade)(fadeType);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
yield (0, exports.resumeAllWithFade)();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
exports.togglePauseAllWithFade = togglePauseAllWithFade;
|
|
19
222
|
/**
|
|
20
223
|
* Pauses the currently playing audio in a specific channel
|
|
21
224
|
* @param channelNumber - The channel number to pause (defaults to 0)
|
|
@@ -55,7 +258,7 @@ const resumeChannel = (...args_1) => __awaiter(void 0, [...args_1], void 0, func
|
|
|
55
258
|
const channel = info_1.audioChannels[channelNumber];
|
|
56
259
|
if (channel && channel.queue.length > 0) {
|
|
57
260
|
const currentAudio = channel.queue[0];
|
|
58
|
-
// Only resume if both the channel is marked as paused AND the audio element is actually paused
|
|
261
|
+
// Only resume if both the channel is marked as paused AND the audio element is actually paused AND not ended
|
|
59
262
|
if (channel.isPaused && currentAudio.paused && !currentAudio.ended) {
|
|
60
263
|
yield currentAudio.play();
|
|
61
264
|
channel.isPaused = false;
|
package/dist/types.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface VolumeConfig {
|
|
|
26
26
|
/** Duration in milliseconds for volume restore transition (defaults to 500ms) */
|
|
27
27
|
restoreTransitionDuration?: number;
|
|
28
28
|
/** Easing function for volume transitions (defaults to 'ease-out') */
|
|
29
|
-
transitionEasing?:
|
|
29
|
+
transitionEasing?: EasingType;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Audio file configuration for queueing
|
|
@@ -159,25 +159,98 @@ export type AudioPauseCallback = (channelNumber: number, audioInfo: AudioInfo) =
|
|
|
159
159
|
*/
|
|
160
160
|
export type AudioResumeCallback = (channelNumber: number, audioInfo: AudioInfo) => void;
|
|
161
161
|
/**
|
|
162
|
-
*
|
|
163
|
-
*/
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
162
|
+
* Information about an audio error that occurred
|
|
163
|
+
*/
|
|
164
|
+
export interface AudioErrorInfo {
|
|
165
|
+
channelNumber: number;
|
|
166
|
+
src: string;
|
|
167
|
+
fileName: string;
|
|
168
|
+
error: Error;
|
|
169
|
+
errorType: 'network' | 'decode' | 'unsupported' | 'permission' | 'abort' | 'timeout' | 'unknown';
|
|
170
|
+
timestamp: number;
|
|
171
|
+
retryAttempt?: number;
|
|
172
|
+
remainingInQueue: number;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Configuration for automatic retry behavior when audio fails to load or play
|
|
176
|
+
*/
|
|
177
|
+
export interface RetryConfig {
|
|
178
|
+
enabled: boolean;
|
|
179
|
+
maxRetries: number;
|
|
180
|
+
baseDelay: number;
|
|
181
|
+
exponentialBackoff: boolean;
|
|
182
|
+
timeoutMs: number;
|
|
183
|
+
fallbackUrls?: string[];
|
|
184
|
+
skipOnFailure: boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Configuration options for error recovery mechanisms
|
|
188
|
+
*/
|
|
189
|
+
export interface ErrorRecoveryOptions {
|
|
190
|
+
autoRetry: boolean;
|
|
191
|
+
showUserFeedback: boolean;
|
|
192
|
+
logErrorsToAnalytics: boolean;
|
|
193
|
+
preserveQueueOnError: boolean;
|
|
194
|
+
fallbackToNextTrack: boolean;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Callback function type for audio error events
|
|
198
|
+
*/
|
|
199
|
+
export type AudioErrorCallback = (errorInfo: AudioErrorInfo) => void;
|
|
200
|
+
/**
|
|
201
|
+
* Extended audio queue channel with error handling capabilities
|
|
202
|
+
*/
|
|
203
|
+
export interface ExtendedAudioQueueChannel {
|
|
204
|
+
audioCompleteCallbacks: Set<AudioCompleteCallback>;
|
|
205
|
+
audioErrorCallbacks: Set<AudioErrorCallback>;
|
|
206
|
+
audioPauseCallbacks: Set<AudioPauseCallback>;
|
|
207
|
+
audioResumeCallbacks: Set<AudioResumeCallback>;
|
|
208
|
+
audioStartCallbacks: Set<AudioStartCallback>;
|
|
209
|
+
fadeState?: ChannelFadeState;
|
|
174
210
|
isPaused?: boolean;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
/** Current volume level for this channel (0-1) */
|
|
211
|
+
progressCallbacks: Map<HTMLAudioElement | null, Set<ProgressCallback>>;
|
|
212
|
+
queue: HTMLAudioElement[];
|
|
213
|
+
queueChangeCallbacks: Set<QueueChangeCallback>;
|
|
214
|
+
retryConfig?: RetryConfig;
|
|
180
215
|
volume?: number;
|
|
181
|
-
/** Volume ducking configuration for this channel */
|
|
182
216
|
volumeConfig?: VolumeConfig;
|
|
183
|
-
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Easing function types for volume transitions
|
|
220
|
+
*/
|
|
221
|
+
export declare enum EasingType {
|
|
222
|
+
Linear = "linear",
|
|
223
|
+
EaseIn = "ease-in",
|
|
224
|
+
EaseOut = "ease-out",
|
|
225
|
+
EaseInOut = "ease-in-out"
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Fade type for pause/resume operations with integrated volume transitions
|
|
229
|
+
*/
|
|
230
|
+
export declare enum FadeType {
|
|
231
|
+
Linear = "linear",
|
|
232
|
+
Gentle = "gentle",
|
|
233
|
+
Dramatic = "dramatic"
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Configuration for fade transitions
|
|
237
|
+
*/
|
|
238
|
+
export interface FadeConfig {
|
|
239
|
+
/** Duration in milliseconds for the fade transition */
|
|
240
|
+
duration: number;
|
|
241
|
+
/** Easing curve to use when pausing (fading out) */
|
|
242
|
+
pauseCurve: EasingType;
|
|
243
|
+
/** Easing curve to use when resuming (fading in) */
|
|
244
|
+
resumeCurve: EasingType;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Internal fade state tracking for pause/resume with fade functionality
|
|
248
|
+
*/
|
|
249
|
+
export interface ChannelFadeState {
|
|
250
|
+
/** The original volume level before fading began */
|
|
251
|
+
originalVolume: number;
|
|
252
|
+
/** The type of fade being used */
|
|
253
|
+
fadeType: FadeType;
|
|
254
|
+
/** Whether the channel is currently paused due to fade */
|
|
255
|
+
isPaused: boolean;
|
|
256
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -3,3 +3,23 @@
|
|
|
3
3
|
* @fileoverview Type definitions for the audio-channel-queue package
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FadeType = exports.EasingType = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Easing function types for volume transitions
|
|
9
|
+
*/
|
|
10
|
+
var EasingType;
|
|
11
|
+
(function (EasingType) {
|
|
12
|
+
EasingType["Linear"] = "linear";
|
|
13
|
+
EasingType["EaseIn"] = "ease-in";
|
|
14
|
+
EasingType["EaseOut"] = "ease-out";
|
|
15
|
+
EasingType["EaseInOut"] = "ease-in-out";
|
|
16
|
+
})(EasingType || (exports.EasingType = EasingType = {}));
|
|
17
|
+
/**
|
|
18
|
+
* Fade type for pause/resume operations with integrated volume transitions
|
|
19
|
+
*/
|
|
20
|
+
var FadeType;
|
|
21
|
+
(function (FadeType) {
|
|
22
|
+
FadeType["Linear"] = "linear";
|
|
23
|
+
FadeType["Gentle"] = "gentle";
|
|
24
|
+
FadeType["Dramatic"] = "dramatic";
|
|
25
|
+
})(FadeType || (exports.FadeType = FadeType = {}));
|
package/dist/volume.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Volume management functions for the audio-channel-queue package
|
|
3
3
|
*/
|
|
4
|
-
import { VolumeConfig } from './types';
|
|
4
|
+
import { VolumeConfig, FadeType, FadeConfig, EasingType } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Gets the fade configuration for a specific fade type
|
|
7
|
+
* @param fadeType - The fade type to get configuration for
|
|
8
|
+
* @returns Fade configuration object
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const config = getFadeConfig('gentle');
|
|
12
|
+
* console.log(`Gentle fade duration: ${config.duration}ms`);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const getFadeConfig: (fadeType: FadeType) => FadeConfig;
|
|
5
16
|
/**
|
|
6
17
|
* Smoothly transitions volume for a specific channel over time
|
|
7
18
|
* @param channelNumber - The channel number to transition
|
|
@@ -14,7 +25,7 @@ import { VolumeConfig } from './types';
|
|
|
14
25
|
* await transitionVolume(0, 0.2, 500, 'ease-out'); // Duck to 20% over 500ms
|
|
15
26
|
* ```
|
|
16
27
|
*/
|
|
17
|
-
export declare const transitionVolume: (channelNumber: number, targetVolume: number, duration?: number, easing?:
|
|
28
|
+
export declare const transitionVolume: (channelNumber: number, targetVolume: number, duration?: number, easing?: EasingType) => Promise<void>;
|
|
18
29
|
/**
|
|
19
30
|
* Sets the volume for a specific channel with optional smooth transition
|
|
20
31
|
* @param channelNumber - The channel number to set volume for
|
|
@@ -27,7 +38,7 @@ export declare const transitionVolume: (channelNumber: number, targetVolume: num
|
|
|
27
38
|
* setChannelVolume(0, 0.5, 300, 'ease-out'); // Smooth transition over 300ms
|
|
28
39
|
* ```
|
|
29
40
|
*/
|
|
30
|
-
export declare const setChannelVolume: (channelNumber: number, volume: number, transitionDuration?: number, easing?:
|
|
41
|
+
export declare const setChannelVolume: (channelNumber: number, volume: number, transitionDuration?: number, easing?: EasingType) => Promise<void>;
|
|
31
42
|
/**
|
|
32
43
|
* Gets the current volume for a specific channel
|
|
33
44
|
* @param channelNumber - The channel number to get volume for (defaults to 0)
|
|
@@ -90,6 +101,20 @@ export declare const clearVolumeDucking: () => void;
|
|
|
90
101
|
* @internal
|
|
91
102
|
*/
|
|
92
103
|
export declare const applyVolumeDucking: (activeChannelNumber: number) => Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Fades the volume for a specific channel over time (alias for transitionVolume with improved naming)
|
|
106
|
+
* @param channelNumber - The channel number to fade
|
|
107
|
+
* @param targetVolume - Target volume level (0-1)
|
|
108
|
+
* @param duration - Fade duration in milliseconds (defaults to 250)
|
|
109
|
+
* @param easing - Easing function type (defaults to 'ease-out')
|
|
110
|
+
* @returns Promise that resolves when fade completes
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* await fadeVolume(0, 0, 800, 'ease-in'); // Fade out over 800ms
|
|
114
|
+
* await fadeVolume(0, 1, 600, 'ease-out'); // Fade in over 600ms
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare const fadeVolume: (channelNumber: number, targetVolume: number, duration?: number, easing?: EasingType) => Promise<void>;
|
|
93
118
|
/**
|
|
94
119
|
* Restores normal volume levels when priority channel stops with smooth transitions
|
|
95
120
|
* @param stoppedChannelNumber - The channel that just stopped playing
|