audio-channel-queue 1.7.0 → 1.9.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 +4 -3
- package/dist/errors.js +27 -17
- package/dist/events.js +21 -14
- package/dist/index.d.ts +6 -5
- package/dist/index.js +16 -1
- package/dist/info.js +8 -7
- package/dist/pause.d.ts +83 -0
- package/dist/pause.js +258 -3
- package/dist/types.d.ts +53 -4
- package/dist/types.js +25 -0
- package/dist/utils.js +4 -3
- package/dist/volume.d.ts +28 -3
- package/dist/volume.js +77 -15
- package/package.json +8 -3
- package/src/core.ts +59 -42
- package/src/errors.ts +504 -480
- package/src/events.ts +36 -27
- package/src/index.ts +60 -39
- package/src/info.ts +23 -22
- package/src/pause.ts +328 -23
- package/src/types.ts +57 -3
- package/src/utils.ts +7 -7
- package/src/volume.ts +92 -30
package/dist/core.js
CHANGED
|
@@ -143,7 +143,7 @@ const playAudioQueue = (channelNumber) => __awaiter(void 0, void 0, void 0, func
|
|
|
143
143
|
hasStarted = true;
|
|
144
144
|
(0, events_1.emitAudioStart)(channelNumber, {
|
|
145
145
|
channelNumber,
|
|
146
|
-
duration: currentAudio.duration * 1000,
|
|
146
|
+
duration: currentAudio.duration * 1000,
|
|
147
147
|
fileName: (0, utils_1.extractFileName)(currentAudio.src),
|
|
148
148
|
src: currentAudio.src
|
|
149
149
|
}, info_1.audioChannels);
|
|
@@ -200,7 +200,7 @@ const playAudioQueue = (channelNumber) => __awaiter(void 0, void 0, void 0, func
|
|
|
200
200
|
currentAudio.addEventListener('play', handlePlay);
|
|
201
201
|
currentAudio.addEventListener('ended', handleEnded);
|
|
202
202
|
// Check if metadata is already loaded (in case it loads before we add the listener)
|
|
203
|
-
if (currentAudio.readyState >= 1) {
|
|
203
|
+
if (currentAudio.readyState >= 1) {
|
|
204
204
|
metadataLoaded = true;
|
|
205
205
|
}
|
|
206
206
|
// Enhanced play with error handling
|
|
@@ -238,6 +238,7 @@ const stopCurrentAudioInChannel = (...args_1) => __awaiter(void 0, [...args_1],
|
|
|
238
238
|
channel.isPaused = false; // Reset pause state
|
|
239
239
|
(0, events_1.emitQueueChange)(channelNumber, info_1.audioChannels);
|
|
240
240
|
// Start next audio without waiting for it to complete
|
|
241
|
+
// eslint-disable-next-line no-console
|
|
241
242
|
(0, exports.playAudioQueue)(channelNumber).catch(console.error);
|
|
242
243
|
}
|
|
243
244
|
});
|
|
@@ -268,7 +269,7 @@ const stopAllAudioInChannel = (...args_1) => __awaiter(void 0, [...args_1], void
|
|
|
268
269
|
(0, events_1.cleanupProgressTracking)(currentAudio, channelNumber, info_1.audioChannels);
|
|
269
270
|
}
|
|
270
271
|
// Clean up all progress tracking for this channel
|
|
271
|
-
channel.queue.forEach(audio => (0, events_1.cleanupProgressTracking)(audio, channelNumber, info_1.audioChannels));
|
|
272
|
+
channel.queue.forEach((audio) => (0, events_1.cleanupProgressTracking)(audio, channelNumber, info_1.audioChannels));
|
|
272
273
|
channel.queue = [];
|
|
273
274
|
channel.isPaused = false; // Reset pause state
|
|
274
275
|
(0, events_1.emitQueueChange)(channelNumber, info_1.audioChannels);
|
package/dist/errors.js
CHANGED
|
@@ -39,19 +39,19 @@ exports.createProtectedAudioElement = exports.handleAudioError = exports.setupAu
|
|
|
39
39
|
const info_1 = require("./info");
|
|
40
40
|
const utils_1 = require("./utils");
|
|
41
41
|
let globalRetryConfig = {
|
|
42
|
-
enabled: true,
|
|
43
|
-
maxRetries: 3,
|
|
44
42
|
baseDelay: 1000,
|
|
43
|
+
enabled: true,
|
|
45
44
|
exponentialBackoff: true,
|
|
46
|
-
|
|
47
|
-
skipOnFailure: false
|
|
45
|
+
maxRetries: 3,
|
|
46
|
+
skipOnFailure: false,
|
|
47
|
+
timeoutMs: 10000
|
|
48
48
|
};
|
|
49
49
|
let globalErrorRecovery = {
|
|
50
50
|
autoRetry: true,
|
|
51
|
-
|
|
51
|
+
fallbackToNextTrack: true,
|
|
52
52
|
logErrorsToAnalytics: false,
|
|
53
53
|
preserveQueueOnError: true,
|
|
54
|
-
|
|
54
|
+
showUserFeedback: false
|
|
55
55
|
};
|
|
56
56
|
const retryAttempts = new WeakMap();
|
|
57
57
|
const loadTimeouts = new WeakMap();
|
|
@@ -191,11 +191,12 @@ exports.getErrorRecovery = getErrorRecovery;
|
|
|
191
191
|
* ```
|
|
192
192
|
*/
|
|
193
193
|
const retryFailedAudio = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (channelNumber = 0) {
|
|
194
|
+
var _a;
|
|
194
195
|
const channel = info_1.audioChannels[channelNumber];
|
|
195
196
|
if (!channel || channel.queue.length === 0)
|
|
196
197
|
return false;
|
|
197
198
|
const currentAudio = channel.queue[0];
|
|
198
|
-
const currentAttempts = retryAttempts.get(currentAudio)
|
|
199
|
+
const currentAttempts = (_a = retryAttempts.get(currentAudio)) !== null && _a !== void 0 ? _a : 0;
|
|
199
200
|
if (currentAttempts >= globalRetryConfig.maxRetries) {
|
|
200
201
|
return false;
|
|
201
202
|
}
|
|
@@ -208,6 +209,8 @@ const retryFailedAudio = (...args_1) => __awaiter(void 0, [...args_1], void 0, f
|
|
|
208
209
|
return true;
|
|
209
210
|
}
|
|
210
211
|
catch (error) {
|
|
212
|
+
// eslint-disable-next-line no-console
|
|
213
|
+
console.error(`Error in retryFailedAudio: ${error}`);
|
|
211
214
|
// Increment retry counter
|
|
212
215
|
retryAttempts.set(currentAudio, currentAttempts + 1);
|
|
213
216
|
return false;
|
|
@@ -227,13 +230,15 @@ const emitAudioError = (channelNumber, errorInfo, audioChannels) => {
|
|
|
227
230
|
return;
|
|
228
231
|
// Log to analytics if enabled
|
|
229
232
|
if (globalErrorRecovery.logErrorsToAnalytics) {
|
|
233
|
+
// eslint-disable-next-line no-console
|
|
230
234
|
console.warn('Audio Error Analytics:', errorInfo);
|
|
231
235
|
}
|
|
232
|
-
channel.audioErrorCallbacks.forEach(callback => {
|
|
236
|
+
channel.audioErrorCallbacks.forEach((callback) => {
|
|
233
237
|
try {
|
|
234
238
|
callback(errorInfo);
|
|
235
239
|
}
|
|
236
240
|
catch (error) {
|
|
241
|
+
// eslint-disable-next-line no-console
|
|
237
242
|
console.error('Error in audio error callback:', error);
|
|
238
243
|
}
|
|
239
244
|
});
|
|
@@ -252,7 +257,8 @@ const categorizeError = (error, audio) => {
|
|
|
252
257
|
return 'network';
|
|
253
258
|
}
|
|
254
259
|
// Check for unsupported format first (more specific than decode)
|
|
255
|
-
if (errorMessage.includes('not supported') ||
|
|
260
|
+
if (errorMessage.includes('not supported') ||
|
|
261
|
+
errorMessage.includes('unsupported') ||
|
|
256
262
|
errorMessage.includes('format not supported')) {
|
|
257
263
|
return 'unsupported';
|
|
258
264
|
}
|
|
@@ -312,7 +318,7 @@ const setupAudioErrorHandling = (audio, channelNumber, originalUrl, onError) =>
|
|
|
312
318
|
}
|
|
313
319
|
};
|
|
314
320
|
// Handle various error events
|
|
315
|
-
const handleError = (
|
|
321
|
+
const handleError = (_event) => {
|
|
316
322
|
var _a;
|
|
317
323
|
if (typeof setTimeout !== 'undefined') {
|
|
318
324
|
const timeoutId = loadTimeouts.get(audio);
|
|
@@ -363,25 +369,28 @@ exports.setupAudioErrorHandling = setupAudioErrorHandling;
|
|
|
363
369
|
* @internal
|
|
364
370
|
*/
|
|
365
371
|
const handleAudioError = (audio, channelNumber, originalUrl, error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
372
|
+
var _a, _b;
|
|
366
373
|
const channel = info_1.audioChannels[channelNumber];
|
|
367
374
|
if (!channel)
|
|
368
375
|
return;
|
|
369
|
-
const currentAttempts = retryAttempts.get(audio)
|
|
370
|
-
const retryConfig = channel.retryConfig
|
|
376
|
+
const currentAttempts = (_a = retryAttempts.get(audio)) !== null && _a !== void 0 ? _a : 0;
|
|
377
|
+
const retryConfig = (_b = channel.retryConfig) !== null && _b !== void 0 ? _b : globalRetryConfig;
|
|
371
378
|
const errorInfo = {
|
|
372
379
|
channelNumber,
|
|
373
|
-
src: originalUrl,
|
|
374
|
-
fileName: (0, utils_1.extractFileName)(originalUrl),
|
|
375
380
|
error,
|
|
376
381
|
errorType: (0, exports.categorizeError)(error, audio),
|
|
377
|
-
|
|
382
|
+
fileName: (0, utils_1.extractFileName)(originalUrl),
|
|
383
|
+
remainingInQueue: channel.queue.length - 1,
|
|
378
384
|
retryAttempt: currentAttempts,
|
|
379
|
-
|
|
385
|
+
src: originalUrl,
|
|
386
|
+
timestamp: Date.now()
|
|
380
387
|
};
|
|
381
388
|
// Emit error event
|
|
382
389
|
(0, exports.emitAudioError)(channelNumber, errorInfo, info_1.audioChannels);
|
|
383
390
|
// Attempt retry if enabled and within limits
|
|
384
|
-
if (retryConfig.enabled &&
|
|
391
|
+
if (retryConfig.enabled &&
|
|
392
|
+
currentAttempts < retryConfig.maxRetries &&
|
|
393
|
+
globalErrorRecovery.autoRetry) {
|
|
385
394
|
const delay = retryConfig.exponentialBackoff
|
|
386
395
|
? retryConfig.baseDelay * Math.pow(2, currentAttempts)
|
|
387
396
|
: retryConfig.baseDelay;
|
|
@@ -412,6 +421,7 @@ const handleAudioError = (audio, channelNumber, originalUrl, error) => __awaiter
|
|
|
412
421
|
channel.queue.shift();
|
|
413
422
|
// Import and use playAudioQueue to continue with next track
|
|
414
423
|
const { playAudioQueue } = yield Promise.resolve().then(() => __importStar(require('./core')));
|
|
424
|
+
// eslint-disable-next-line no-console
|
|
415
425
|
playAudioQueue(channelNumber).catch(console.error);
|
|
416
426
|
}
|
|
417
427
|
else if (!globalErrorRecovery.preserveQueueOnError) {
|
package/dist/events.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.cleanupProgressTracking = exports.setupProgressTracking = exports.emitAudioResume = exports.emitAudioPause = exports.emitAudioComplete = exports.emitAudioStart = exports.emitQueueChange = void 0;
|
|
7
|
+
const types_1 = require("./types");
|
|
7
8
|
const utils_1 = require("./utils");
|
|
8
9
|
/**
|
|
9
10
|
* Emits a queue change event to all registered listeners for a specific channel
|
|
@@ -16,16 +17,17 @@ const utils_1 = require("./utils");
|
|
|
16
17
|
*/
|
|
17
18
|
const emitQueueChange = (channelNumber, audioChannels) => {
|
|
18
19
|
const channel = audioChannels[channelNumber];
|
|
19
|
-
if (!channel ||
|
|
20
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.queueChangeCallbacks))
|
|
20
21
|
return;
|
|
21
22
|
const snapshot = (0, utils_1.createQueueSnapshot)(channelNumber, audioChannels);
|
|
22
23
|
if (!snapshot)
|
|
23
24
|
return;
|
|
24
|
-
channel.queueChangeCallbacks.forEach(callback => {
|
|
25
|
+
channel.queueChangeCallbacks.forEach((callback) => {
|
|
25
26
|
try {
|
|
26
27
|
callback(snapshot);
|
|
27
28
|
}
|
|
28
29
|
catch (error) {
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
29
31
|
console.error('Error in queue change callback:', error);
|
|
30
32
|
}
|
|
31
33
|
});
|
|
@@ -43,13 +45,14 @@ exports.emitQueueChange = emitQueueChange;
|
|
|
43
45
|
*/
|
|
44
46
|
const emitAudioStart = (channelNumber, audioInfo, audioChannels) => {
|
|
45
47
|
const channel = audioChannels[channelNumber];
|
|
46
|
-
if (!channel ||
|
|
48
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.audioStartCallbacks))
|
|
47
49
|
return;
|
|
48
|
-
channel.audioStartCallbacks.forEach(callback => {
|
|
50
|
+
channel.audioStartCallbacks.forEach((callback) => {
|
|
49
51
|
try {
|
|
50
52
|
callback(audioInfo);
|
|
51
53
|
}
|
|
52
54
|
catch (error) {
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
53
56
|
console.error('Error in audio start callback:', error);
|
|
54
57
|
}
|
|
55
58
|
});
|
|
@@ -67,13 +70,14 @@ exports.emitAudioStart = emitAudioStart;
|
|
|
67
70
|
*/
|
|
68
71
|
const emitAudioComplete = (channelNumber, audioInfo, audioChannels) => {
|
|
69
72
|
const channel = audioChannels[channelNumber];
|
|
70
|
-
if (!channel ||
|
|
73
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.audioCompleteCallbacks))
|
|
71
74
|
return;
|
|
72
|
-
channel.audioCompleteCallbacks.forEach(callback => {
|
|
75
|
+
channel.audioCompleteCallbacks.forEach((callback) => {
|
|
73
76
|
try {
|
|
74
77
|
callback(audioInfo);
|
|
75
78
|
}
|
|
76
79
|
catch (error) {
|
|
80
|
+
// eslint-disable-next-line no-console
|
|
77
81
|
console.error('Error in audio complete callback:', error);
|
|
78
82
|
}
|
|
79
83
|
});
|
|
@@ -91,13 +95,14 @@ exports.emitAudioComplete = emitAudioComplete;
|
|
|
91
95
|
*/
|
|
92
96
|
const emitAudioPause = (channelNumber, audioInfo, audioChannels) => {
|
|
93
97
|
const channel = audioChannels[channelNumber];
|
|
94
|
-
if (!channel ||
|
|
98
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.audioPauseCallbacks))
|
|
95
99
|
return;
|
|
96
|
-
channel.audioPauseCallbacks.forEach(callback => {
|
|
100
|
+
channel.audioPauseCallbacks.forEach((callback) => {
|
|
97
101
|
try {
|
|
98
102
|
callback(channelNumber, audioInfo);
|
|
99
103
|
}
|
|
100
104
|
catch (error) {
|
|
105
|
+
// eslint-disable-next-line no-console
|
|
101
106
|
console.error('Error in audio pause callback:', error);
|
|
102
107
|
}
|
|
103
108
|
});
|
|
@@ -115,13 +120,14 @@ exports.emitAudioPause = emitAudioPause;
|
|
|
115
120
|
*/
|
|
116
121
|
const emitAudioResume = (channelNumber, audioInfo, audioChannels) => {
|
|
117
122
|
const channel = audioChannels[channelNumber];
|
|
118
|
-
if (!channel ||
|
|
123
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.audioResumeCallbacks))
|
|
119
124
|
return;
|
|
120
|
-
channel.audioResumeCallbacks.forEach(callback => {
|
|
125
|
+
channel.audioResumeCallbacks.forEach((callback) => {
|
|
121
126
|
try {
|
|
122
127
|
callback(channelNumber, audioInfo);
|
|
123
128
|
}
|
|
124
129
|
catch (error) {
|
|
130
|
+
// eslint-disable-next-line no-console
|
|
125
131
|
console.error('Error in audio resume callback:', error);
|
|
126
132
|
}
|
|
127
133
|
});
|
|
@@ -151,10 +157,10 @@ const setupProgressTracking = (audio, channelNumber, audioChannels) => {
|
|
|
151
157
|
if (progressListeners.has(audio))
|
|
152
158
|
return;
|
|
153
159
|
const updateProgress = () => {
|
|
154
|
-
var _a, _b;
|
|
160
|
+
var _a, _b, _c, _d;
|
|
155
161
|
// Get callbacks for this specific audio element AND the channel-wide callbacks
|
|
156
|
-
const audioCallbacks = ((_a = channel.progressCallbacks) === null || _a === void 0 ? void 0 : _a.get(audio))
|
|
157
|
-
const channelCallbacks = ((
|
|
162
|
+
const audioCallbacks = (_b = (_a = channel.progressCallbacks) === null || _a === void 0 ? void 0 : _a.get(audio)) !== null && _b !== void 0 ? _b : new Set();
|
|
163
|
+
const channelCallbacks = (_d = (_c = channel.progressCallbacks) === null || _c === void 0 ? void 0 : _c.get(types_1.GLOBAL_PROGRESS_KEY)) !== null && _d !== void 0 ? _d : new Set();
|
|
158
164
|
// Combine both sets of callbacks
|
|
159
165
|
const allCallbacks = new Set([...audioCallbacks, ...channelCallbacks]);
|
|
160
166
|
if (allCallbacks.size === 0)
|
|
@@ -166,6 +172,7 @@ const setupProgressTracking = (audio, channelNumber, audioChannels) => {
|
|
|
166
172
|
callback(info);
|
|
167
173
|
}
|
|
168
174
|
catch (error) {
|
|
175
|
+
// eslint-disable-next-line no-console
|
|
169
176
|
console.error('Error in progress callback:', error);
|
|
170
177
|
}
|
|
171
178
|
});
|
|
@@ -193,7 +200,7 @@ exports.setupProgressTracking = setupProgressTracking;
|
|
|
193
200
|
*/
|
|
194
201
|
const cleanupProgressTracking = (audio, channelNumber, audioChannels) => {
|
|
195
202
|
const channel = audioChannels[channelNumber];
|
|
196
|
-
if (!channel ||
|
|
203
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.progressCallbacks))
|
|
197
204
|
return;
|
|
198
205
|
// Remove event listeners
|
|
199
206
|
const updateProgress = progressListeners.get(audio);
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* volume management with ducking, progress tracking, and comprehensive event system
|
|
5
5
|
*/
|
|
6
6
|
export { queueAudio, queueAudioPriority, stopCurrentAudioInChannel, stopAllAudioInChannel, stopAllAudio, playAudioQueue } from './core';
|
|
7
|
-
export { getErrorRecovery, getRetryConfig, offAudioError, onAudioError, retryFailedAudio, setErrorRecovery, setRetryConfig
|
|
8
|
-
export { getAllChannelsPauseState, isChannelPaused, pauseAllChannels, pauseChannel, resumeAllChannels, resumeChannel, togglePauseAllChannels, togglePauseChannel, } from './pause';
|
|
9
|
-
export { clearVolumeDucking, getAllChannelsVolume, getChannelVolume, setAllChannelsVolume, setChannelVolume, setVolumeDucking, } from './volume';
|
|
10
|
-
export { getAllChannelsInfo, getCurrentAudioInfo, getQueueSnapshot, offAudioPause, offAudioProgress, offAudioResume, offQueueChange, onAudioComplete, onAudioPause, onAudioProgress, onAudioResume, onAudioStart, onQueueChange
|
|
7
|
+
export { getErrorRecovery, getRetryConfig, offAudioError, onAudioError, retryFailedAudio, setErrorRecovery, setRetryConfig } from './errors';
|
|
8
|
+
export { getAllChannelsPauseState, isChannelPaused, pauseAllChannels, pauseAllWithFade, pauseChannel, pauseWithFade, resumeAllChannels, resumeAllWithFade, resumeChannel, resumeWithFade, togglePauseAllChannels, togglePauseAllWithFade, togglePauseChannel, togglePauseWithFade } from './pause';
|
|
9
|
+
export { clearVolumeDucking, fadeVolume, getAllChannelsVolume, getChannelVolume, getFadeConfig, setAllChannelsVolume, setChannelVolume, setVolumeDucking, transitionVolume } from './volume';
|
|
10
|
+
export { getAllChannelsInfo, getCurrentAudioInfo, getQueueSnapshot, offAudioPause, offAudioProgress, offAudioResume, offQueueChange, onAudioComplete, onAudioPause, onAudioProgress, onAudioResume, onAudioStart, onQueueChange } from './info';
|
|
11
11
|
export { audioChannels } from './info';
|
|
12
12
|
export { cleanWebpackFilename, createQueueSnapshot, extractFileName, getAudioInfoFromElement } from './utils';
|
|
13
|
-
export type { AudioCompleteCallback, AudioCompleteInfo, AudioErrorCallback, AudioErrorInfo, AudioInfo, AudioPauseCallback, AudioQueueOptions, AudioResumeCallback, AudioStartCallback, AudioStartInfo, ErrorRecoveryOptions, ExtendedAudioQueueChannel, ProgressCallback, QueueChangeCallback, QueueItem, QueueSnapshot, RetryConfig, VolumeConfig } from './types';
|
|
13
|
+
export type { AudioCompleteCallback, AudioCompleteInfo, AudioErrorCallback, AudioErrorInfo, AudioInfo, AudioPauseCallback, AudioQueueOptions, AudioResumeCallback, AudioStartCallback, AudioStartInfo, ChannelFadeState, ErrorRecoveryOptions, ExtendedAudioQueueChannel, FadeConfig, ProgressCallback, QueueChangeCallback, QueueItem, QueueSnapshot, RetryConfig, VolumeConfig } from './types';
|
|
14
|
+
export { EasingType, FadeType, GLOBAL_PROGRESS_KEY } from './types';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* volume management with ducking, progress tracking, and comprehensive event system
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
8
|
+
exports.audioChannels = exports.onQueueChange = exports.onAudioStart = exports.onAudioResume = exports.onAudioProgress = exports.onAudioPause = exports.onAudioComplete = exports.offQueueChange = exports.offAudioResume = exports.offAudioProgress = exports.offAudioPause = exports.getQueueSnapshot = exports.getCurrentAudioInfo = exports.getAllChannelsInfo = exports.transitionVolume = exports.setVolumeDucking = exports.setChannelVolume = exports.setAllChannelsVolume = exports.getFadeConfig = exports.getChannelVolume = exports.getAllChannelsVolume = exports.fadeVolume = exports.clearVolumeDucking = exports.togglePauseWithFade = exports.togglePauseChannel = exports.togglePauseAllWithFade = exports.togglePauseAllChannels = exports.resumeWithFade = exports.resumeChannel = exports.resumeAllWithFade = exports.resumeAllChannels = exports.pauseWithFade = exports.pauseChannel = exports.pauseAllWithFade = exports.pauseAllChannels = exports.isChannelPaused = exports.getAllChannelsPauseState = exports.setRetryConfig = exports.setErrorRecovery = exports.retryFailedAudio = exports.onAudioError = exports.offAudioError = exports.getRetryConfig = exports.getErrorRecovery = exports.playAudioQueue = exports.stopAllAudio = exports.stopAllAudioInChannel = exports.stopCurrentAudioInChannel = exports.queueAudioPriority = exports.queueAudio = void 0;
|
|
9
|
+
exports.GLOBAL_PROGRESS_KEY = exports.FadeType = exports.EasingType = exports.getAudioInfoFromElement = exports.extractFileName = exports.createQueueSnapshot = exports.cleanWebpackFilename = void 0;
|
|
9
10
|
// Core queue management functions
|
|
10
11
|
var core_1 = require("./core");
|
|
11
12
|
Object.defineProperty(exports, "queueAudio", { enumerable: true, get: function () { return core_1.queueAudio; } });
|
|
@@ -28,19 +29,28 @@ var pause_1 = require("./pause");
|
|
|
28
29
|
Object.defineProperty(exports, "getAllChannelsPauseState", { enumerable: true, get: function () { return pause_1.getAllChannelsPauseState; } });
|
|
29
30
|
Object.defineProperty(exports, "isChannelPaused", { enumerable: true, get: function () { return pause_1.isChannelPaused; } });
|
|
30
31
|
Object.defineProperty(exports, "pauseAllChannels", { enumerable: true, get: function () { return pause_1.pauseAllChannels; } });
|
|
32
|
+
Object.defineProperty(exports, "pauseAllWithFade", { enumerable: true, get: function () { return pause_1.pauseAllWithFade; } });
|
|
31
33
|
Object.defineProperty(exports, "pauseChannel", { enumerable: true, get: function () { return pause_1.pauseChannel; } });
|
|
34
|
+
Object.defineProperty(exports, "pauseWithFade", { enumerable: true, get: function () { return pause_1.pauseWithFade; } });
|
|
32
35
|
Object.defineProperty(exports, "resumeAllChannels", { enumerable: true, get: function () { return pause_1.resumeAllChannels; } });
|
|
36
|
+
Object.defineProperty(exports, "resumeAllWithFade", { enumerable: true, get: function () { return pause_1.resumeAllWithFade; } });
|
|
33
37
|
Object.defineProperty(exports, "resumeChannel", { enumerable: true, get: function () { return pause_1.resumeChannel; } });
|
|
38
|
+
Object.defineProperty(exports, "resumeWithFade", { enumerable: true, get: function () { return pause_1.resumeWithFade; } });
|
|
34
39
|
Object.defineProperty(exports, "togglePauseAllChannels", { enumerable: true, get: function () { return pause_1.togglePauseAllChannels; } });
|
|
40
|
+
Object.defineProperty(exports, "togglePauseAllWithFade", { enumerable: true, get: function () { return pause_1.togglePauseAllWithFade; } });
|
|
35
41
|
Object.defineProperty(exports, "togglePauseChannel", { enumerable: true, get: function () { return pause_1.togglePauseChannel; } });
|
|
42
|
+
Object.defineProperty(exports, "togglePauseWithFade", { enumerable: true, get: function () { return pause_1.togglePauseWithFade; } });
|
|
36
43
|
// Volume control and ducking functions
|
|
37
44
|
var volume_1 = require("./volume");
|
|
38
45
|
Object.defineProperty(exports, "clearVolumeDucking", { enumerable: true, get: function () { return volume_1.clearVolumeDucking; } });
|
|
46
|
+
Object.defineProperty(exports, "fadeVolume", { enumerable: true, get: function () { return volume_1.fadeVolume; } });
|
|
39
47
|
Object.defineProperty(exports, "getAllChannelsVolume", { enumerable: true, get: function () { return volume_1.getAllChannelsVolume; } });
|
|
40
48
|
Object.defineProperty(exports, "getChannelVolume", { enumerable: true, get: function () { return volume_1.getChannelVolume; } });
|
|
49
|
+
Object.defineProperty(exports, "getFadeConfig", { enumerable: true, get: function () { return volume_1.getFadeConfig; } });
|
|
41
50
|
Object.defineProperty(exports, "setAllChannelsVolume", { enumerable: true, get: function () { return volume_1.setAllChannelsVolume; } });
|
|
42
51
|
Object.defineProperty(exports, "setChannelVolume", { enumerable: true, get: function () { return volume_1.setChannelVolume; } });
|
|
43
52
|
Object.defineProperty(exports, "setVolumeDucking", { enumerable: true, get: function () { return volume_1.setVolumeDucking; } });
|
|
53
|
+
Object.defineProperty(exports, "transitionVolume", { enumerable: true, get: function () { return volume_1.transitionVolume; } });
|
|
44
54
|
// Audio information and progress tracking functions
|
|
45
55
|
var info_1 = require("./info");
|
|
46
56
|
Object.defineProperty(exports, "getAllChannelsInfo", { enumerable: true, get: function () { return info_1.getAllChannelsInfo; } });
|
|
@@ -65,3 +75,8 @@ Object.defineProperty(exports, "cleanWebpackFilename", { enumerable: true, get:
|
|
|
65
75
|
Object.defineProperty(exports, "createQueueSnapshot", { enumerable: true, get: function () { return utils_1.createQueueSnapshot; } });
|
|
66
76
|
Object.defineProperty(exports, "extractFileName", { enumerable: true, get: function () { return utils_1.extractFileName; } });
|
|
67
77
|
Object.defineProperty(exports, "getAudioInfoFromElement", { enumerable: true, get: function () { return utils_1.getAudioInfoFromElement; } });
|
|
78
|
+
// Enums and constants
|
|
79
|
+
var types_1 = require("./types");
|
|
80
|
+
Object.defineProperty(exports, "EasingType", { enumerable: true, get: function () { return types_1.EasingType; } });
|
|
81
|
+
Object.defineProperty(exports, "FadeType", { enumerable: true, get: function () { return types_1.FadeType; } });
|
|
82
|
+
Object.defineProperty(exports, "GLOBAL_PROGRESS_KEY", { enumerable: true, get: function () { return types_1.GLOBAL_PROGRESS_KEY; } });
|
package/dist/info.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.offAudioResume = exports.offAudioPause = exports.onAudioResume = exports.onAudioPause = exports.onAudioComplete = exports.onAudioStart = exports.offQueueChange = exports.onQueueChange = exports.offAudioProgress = exports.onAudioProgress = exports.getQueueSnapshot = exports.getAllChannelsInfo = exports.getCurrentAudioInfo = exports.audioChannels = void 0;
|
|
7
|
+
const types_1 = require("./types");
|
|
7
8
|
const utils_1 = require("./utils");
|
|
8
9
|
const events_1 = require("./events");
|
|
9
10
|
/**
|
|
@@ -113,10 +114,10 @@ const onAudioProgress = (channelNumber, callback) => {
|
|
|
113
114
|
(0, events_1.setupProgressTracking)(currentAudio, channelNumber, exports.audioChannels);
|
|
114
115
|
}
|
|
115
116
|
// Store callback for future audio elements in this channel
|
|
116
|
-
if (!channel.progressCallbacks.has(
|
|
117
|
-
channel.progressCallbacks.set(
|
|
117
|
+
if (!channel.progressCallbacks.has(types_1.GLOBAL_PROGRESS_KEY)) {
|
|
118
|
+
channel.progressCallbacks.set(types_1.GLOBAL_PROGRESS_KEY, new Set());
|
|
118
119
|
}
|
|
119
|
-
channel.progressCallbacks.get(
|
|
120
|
+
channel.progressCallbacks.get(types_1.GLOBAL_PROGRESS_KEY).add(callback);
|
|
120
121
|
};
|
|
121
122
|
exports.onAudioProgress = onAudioProgress;
|
|
122
123
|
/**
|
|
@@ -129,7 +130,7 @@ exports.onAudioProgress = onAudioProgress;
|
|
|
129
130
|
*/
|
|
130
131
|
const offAudioProgress = (channelNumber) => {
|
|
131
132
|
const channel = exports.audioChannels[channelNumber];
|
|
132
|
-
if (!channel ||
|
|
133
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.progressCallbacks))
|
|
133
134
|
return;
|
|
134
135
|
// Clean up event listeners for current audio if exists
|
|
135
136
|
if (channel.queue.length > 0) {
|
|
@@ -184,7 +185,7 @@ exports.onQueueChange = onQueueChange;
|
|
|
184
185
|
*/
|
|
185
186
|
const offQueueChange = (channelNumber) => {
|
|
186
187
|
const channel = exports.audioChannels[channelNumber];
|
|
187
|
-
if (!channel ||
|
|
188
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.queueChangeCallbacks))
|
|
188
189
|
return;
|
|
189
190
|
channel.queueChangeCallbacks.clear();
|
|
190
191
|
};
|
|
@@ -337,7 +338,7 @@ exports.onAudioResume = onAudioResume;
|
|
|
337
338
|
*/
|
|
338
339
|
const offAudioPause = (channelNumber) => {
|
|
339
340
|
const channel = exports.audioChannels[channelNumber];
|
|
340
|
-
if (!channel ||
|
|
341
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.audioPauseCallbacks))
|
|
341
342
|
return;
|
|
342
343
|
channel.audioPauseCallbacks.clear();
|
|
343
344
|
};
|
|
@@ -352,7 +353,7 @@ exports.offAudioPause = offAudioPause;
|
|
|
352
353
|
*/
|
|
353
354
|
const offAudioResume = (channelNumber) => {
|
|
354
355
|
const channel = exports.audioChannels[channelNumber];
|
|
355
|
-
if (!channel ||
|
|
356
|
+
if (!(channel === null || channel === void 0 ? void 0 : channel.audioResumeCallbacks))
|
|
356
357
|
return;
|
|
357
358
|
channel.audioResumeCallbacks.clear();
|
|
358
359
|
};
|
package/dist/pause.d.ts
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
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
|
+
* @param duration - Optional custom fade duration in milliseconds (uses fadeType default if not provided)
|
|
10
|
+
* @returns Promise that resolves when the pause and fade are complete
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* await pauseWithFade(FadeType.Gentle, 0); // Pause with gentle fade out over 800ms
|
|
14
|
+
* await pauseWithFade(FadeType.Dramatic, 1, 1500); // Pause with dramatic fade out over 1.5s
|
|
15
|
+
* await pauseWithFade(FadeType.Linear, 2, 500); // Linear pause with custom 500ms fade
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const pauseWithFade: (fadeType?: FadeType, channelNumber?: number, duration?: number) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Resumes the currently paused audio in a specific channel with smooth volume fade
|
|
21
|
+
* Uses the complementary fade curve automatically based on the pause fade type, or allows override
|
|
22
|
+
* @param fadeType - Optional fade type to override the stored fade type from pause
|
|
23
|
+
* @param channelNumber - The channel number to resume (defaults to 0)
|
|
24
|
+
* @param duration - Optional custom fade duration in milliseconds (uses stored or fadeType default if not provided)
|
|
25
|
+
* @returns Promise that resolves when the resume and fade are complete
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* await resumeWithFade(); // Resume with automatically paired fade curve from pause
|
|
29
|
+
* await resumeWithFade(FadeType.Dramatic, 0); // Override with dramatic fade
|
|
30
|
+
* await resumeWithFade(FadeType.Linear, 0, 1000); // Override with linear fade over 1 second
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const resumeWithFade: (fadeType?: FadeType, channelNumber?: number, duration?: number) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Toggles pause/resume state for a specific channel with integrated fade
|
|
36
|
+
* @param fadeType - Type of fade transition to apply when pausing
|
|
37
|
+
* @param channelNumber - The channel number to toggle (defaults to 0)
|
|
38
|
+
* @param duration - Optional custom fade duration in milliseconds (uses fadeType default if not provided)
|
|
39
|
+
* @returns Promise that resolves when the toggle and fade are complete
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* await togglePauseWithFade(FadeType.Gentle, 0); // Toggle with gentle fade
|
|
43
|
+
* await togglePauseWithFade(FadeType.Dramatic, 0, 500); // Toggle with custom 500ms fade
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const togglePauseWithFade: (fadeType?: FadeType, channelNumber?: number, duration?: number) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Pauses all currently playing audio across all channels with smooth volume fade
|
|
49
|
+
* @param fadeType - Type of fade transition to apply to all channels
|
|
50
|
+
* @param duration - Optional custom fade duration in milliseconds (uses fadeType default if not provided)
|
|
51
|
+
* @returns Promise that resolves when all channels are paused and faded
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* await pauseAllWithFade(FadeType.Dramatic); // Pause everything with dramatic fade
|
|
55
|
+
* await pauseAllWithFade(FadeType.Gentle, 1200); // Pause all channels with custom 1.2s fade
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const pauseAllWithFade: (fadeType?: FadeType, duration?: number) => Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Resumes all currently paused audio across all channels with smooth volume fade
|
|
61
|
+
* Uses automatically paired fade curves based on each channel's pause fade type, or allows override
|
|
62
|
+
* @param fadeType - Optional fade type to override stored fade types for all channels
|
|
63
|
+
* @param duration - Optional custom fade duration in milliseconds (uses stored or fadeType default if not provided)
|
|
64
|
+
* @returns Promise that resolves when all channels are resumed and faded
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* await resumeAllWithFade(); // Resume everything with paired fade curves
|
|
68
|
+
* await resumeAllWithFade(FadeType.Gentle, 800); // Override all channels with gentle fade over 800ms
|
|
69
|
+
* await resumeAllWithFade(undefined, 600); // Use stored fade types with custom 600ms duration
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const resumeAllWithFade: (fadeType?: FadeType, duration?: number) => Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Toggles pause/resume state for all channels with integrated fade
|
|
75
|
+
* If any channels are playing, all will be paused with fade
|
|
76
|
+
* If all channels are paused, all will be resumed with fade
|
|
77
|
+
* @param fadeType - Type of fade transition to apply when pausing
|
|
78
|
+
* @param duration - Optional custom fade duration in milliseconds (uses fadeType default if not provided)
|
|
79
|
+
* @returns Promise that resolves when all toggles and fades are complete
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* await togglePauseAllWithFade(FadeType.Gentle); // Global toggle with gentle fade
|
|
83
|
+
* await togglePauseAllWithFade(FadeType.Dramatic, 600); // Global toggle with custom 600ms fade
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare const togglePauseAllWithFade: (fadeType?: FadeType, duration?: number) => Promise<void>;
|
|
4
87
|
/**
|
|
5
88
|
* Pauses the currently playing audio in a specific channel
|
|
6
89
|
* @param channelNumber - The channel number to pause (defaults to 0)
|