audio-channel-queue 1.8.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 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, // Now guaranteed to have valid duration
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) { // HAVE_METADATA or higher
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
- timeoutMs: 10000,
47
- skipOnFailure: false
45
+ maxRetries: 3,
46
+ skipOnFailure: false,
47
+ timeoutMs: 10000
48
48
  };
49
49
  let globalErrorRecovery = {
50
50
  autoRetry: true,
51
- showUserFeedback: false,
51
+ fallbackToNextTrack: true,
52
52
  logErrorsToAnalytics: false,
53
53
  preserveQueueOnError: true,
54
- fallbackToNextTrack: true
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) || 0;
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') || errorMessage.includes('unsupported') ||
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 = (event) => {
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) || 0;
370
- const retryConfig = channel.retryConfig || globalRetryConfig;
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
- timestamp: Date.now(),
382
+ fileName: (0, utils_1.extractFileName)(originalUrl),
383
+ remainingInQueue: channel.queue.length - 1,
378
384
  retryAttempt: currentAttempts,
379
- remainingInQueue: channel.queue.length - 1
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 && currentAttempts < retryConfig.maxRetries && globalErrorRecovery.autoRetry) {
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 || !channel.queueChangeCallbacks)
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 || !channel.audioStartCallbacks)
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 || !channel.audioCompleteCallbacks)
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 || !channel.audioPauseCallbacks)
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 || !channel.audioResumeCallbacks)
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)) || new Set();
157
- const channelCallbacks = ((_b = channel.progressCallbacks) === null || _b === void 0 ? void 0 : _b.get(null)) || new Set();
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 || !channel.progressCallbacks)
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,11 +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, } 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';
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
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 } from './types';
14
+ export { EasingType, FadeType, GLOBAL_PROGRESS_KEY } from './types';
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
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.FadeType = exports.EasingType = exports.getAudioInfoFromElement = exports.extractFileName = exports.createQueueSnapshot = exports.cleanWebpackFilename = void 0;
9
+ exports.GLOBAL_PROGRESS_KEY = exports.FadeType = exports.EasingType = exports.getAudioInfoFromElement = exports.extractFileName = exports.createQueueSnapshot = exports.cleanWebpackFilename = void 0;
10
10
  // Core queue management functions
11
11
  var core_1 = require("./core");
12
12
  Object.defineProperty(exports, "queueAudio", { enumerable: true, get: function () { return core_1.queueAudio; } });
@@ -75,7 +75,8 @@ Object.defineProperty(exports, "cleanWebpackFilename", { enumerable: true, get:
75
75
  Object.defineProperty(exports, "createQueueSnapshot", { enumerable: true, get: function () { return utils_1.createQueueSnapshot; } });
76
76
  Object.defineProperty(exports, "extractFileName", { enumerable: true, get: function () { return utils_1.extractFileName; } });
77
77
  Object.defineProperty(exports, "getAudioInfoFromElement", { enumerable: true, get: function () { return utils_1.getAudioInfoFromElement; } });
78
- // Enums
78
+ // Enums and constants
79
79
  var types_1 = require("./types");
80
80
  Object.defineProperty(exports, "EasingType", { enumerable: true, get: function () { return types_1.EasingType; } });
81
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(null)) {
117
- channel.progressCallbacks.set(null, new 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(null).add(callback);
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 || !channel.progressCallbacks)
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 || !channel.queueChangeCallbacks)
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 || !channel.audioPauseCallbacks)
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 || !channel.audioResumeCallbacks)
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
@@ -6,72 +6,84 @@ import { FadeType } from './types';
6
6
  * Pauses the currently playing audio in a specific channel with smooth volume fade
7
7
  * @param fadeType - Type of fade transition to apply
8
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)
9
10
  * @returns Promise that resolves when the pause and fade are complete
10
11
  * @example
11
12
  * ```typescript
12
13
  * 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
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
15
16
  * ```
16
17
  */
17
- export declare const pauseWithFade: (fadeType?: FadeType, channelNumber?: number) => Promise<void>;
18
+ export declare const pauseWithFade: (fadeType?: FadeType, channelNumber?: number, duration?: number) => Promise<void>;
18
19
  /**
19
20
  * Resumes the currently paused audio in a specific channel with smooth volume fade
20
21
  * Uses the complementary fade curve automatically based on the pause fade type, or allows override
21
22
  * @param fadeType - Optional fade type to override the stored fade type from pause
22
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)
23
25
  * @returns Promise that resolves when the resume and fade are complete
24
26
  * @example
25
27
  * ```typescript
26
28
  * await resumeWithFade(); // Resume with automatically paired fade curve from pause
27
29
  * await resumeWithFade(FadeType.Dramatic, 0); // Override with dramatic fade
28
- * await resumeWithFade(FadeType.Linear); // Override with linear fade on default channel
30
+ * await resumeWithFade(FadeType.Linear, 0, 1000); // Override with linear fade over 1 second
29
31
  * ```
30
32
  */
31
- export declare const resumeWithFade: (fadeType?: FadeType, channelNumber?: number) => Promise<void>;
33
+ export declare const resumeWithFade: (fadeType?: FadeType, channelNumber?: number, duration?: number) => Promise<void>;
32
34
  /**
33
35
  * Toggles pause/resume state for a specific channel with integrated fade
34
36
  * @param fadeType - Type of fade transition to apply when pausing
35
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)
36
39
  * @returns Promise that resolves when the toggle and fade are complete
37
40
  * @example
38
41
  * ```typescript
39
42
  * await togglePauseWithFade(FadeType.Gentle, 0); // Toggle with gentle fade
43
+ * await togglePauseWithFade(FadeType.Dramatic, 0, 500); // Toggle with custom 500ms fade
40
44
  * ```
41
45
  */
42
- export declare const togglePauseWithFade: (fadeType?: FadeType, channelNumber?: number) => Promise<void>;
46
+ export declare const togglePauseWithFade: (fadeType?: FadeType, channelNumber?: number, duration?: number) => Promise<void>;
43
47
  /**
44
48
  * Pauses all currently playing audio across all channels with smooth volume fade
45
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)
46
51
  * @returns Promise that resolves when all channels are paused and faded
47
52
  * @example
48
53
  * ```typescript
49
- * await pauseAllWithFade('dramatic'); // Pause everything with dramatic fade
54
+ * await pauseAllWithFade(FadeType.Dramatic); // Pause everything with dramatic fade
55
+ * await pauseAllWithFade(FadeType.Gentle, 1200); // Pause all channels with custom 1.2s fade
50
56
  * ```
51
57
  */
52
- export declare const pauseAllWithFade: (fadeType?: FadeType) => Promise<void>;
58
+ export declare const pauseAllWithFade: (fadeType?: FadeType, duration?: number) => Promise<void>;
53
59
  /**
54
60
  * 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
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)
56
64
  * @returns Promise that resolves when all channels are resumed and faded
57
65
  * @example
58
66
  * ```typescript
59
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
60
70
  * ```
61
71
  */
62
- export declare const resumeAllWithFade: () => Promise<void>;
72
+ export declare const resumeAllWithFade: (fadeType?: FadeType, duration?: number) => Promise<void>;
63
73
  /**
64
74
  * Toggles pause/resume state for all channels with integrated fade
65
75
  * If any channels are playing, all will be paused with fade
66
76
  * If all channels are paused, all will be resumed with fade
67
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)
68
79
  * @returns Promise that resolves when all toggles and fades are complete
69
80
  * @example
70
81
  * ```typescript
71
- * await togglePauseAllWithFade('gentle'); // Global toggle with gentle fade
82
+ * await togglePauseAllWithFade(FadeType.Gentle); // Global toggle with gentle fade
83
+ * await togglePauseAllWithFade(FadeType.Dramatic, 600); // Global toggle with custom 600ms fade
72
84
  * ```
73
85
  */
74
- export declare const togglePauseAllWithFade: (fadeType?: FadeType) => Promise<void>;
86
+ export declare const togglePauseAllWithFade: (fadeType?: FadeType, duration?: number) => Promise<void>;
75
87
  /**
76
88
  * Pauses the currently playing audio in a specific channel
77
89
  * @param channelNumber - The channel number to pause (defaults to 0)