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/src/types.ts CHANGED
@@ -29,7 +29,7 @@ export interface VolumeConfig {
29
29
  /** Duration in milliseconds for volume restore transition (defaults to 500ms) */
30
30
  restoreTransitionDuration?: number;
31
31
  /** Easing function for volume transitions (defaults to 'ease-out') */
32
- transitionEasing?: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
32
+ transitionEasing?: EasingType;
33
33
  }
34
34
 
35
35
  /**
@@ -175,25 +175,106 @@ export type AudioPauseCallback = (channelNumber: number, audioInfo: AudioInfo) =
175
175
  export type AudioResumeCallback = (channelNumber: number, audioInfo: AudioInfo) => void;
176
176
 
177
177
  /**
178
- * Extended audio queue channel with event callback management and additional features
178
+ * Information about an audio error that occurred
179
179
  */
180
- export type ExtendedAudioQueueChannel = AudioQueueChannel & {
181
- /** Set of callbacks for audio completion events */
182
- audioCompleteCallbacks?: Set<AudioCompleteCallback>;
183
- /** Set of callbacks for audio pause events */
184
- audioPauseCallbacks?: Set<AudioPauseCallback>;
185
- /** Set of callbacks for audio resume events */
186
- audioResumeCallbacks?: Set<AudioResumeCallback>;
187
- /** Set of callbacks for audio start events */
188
- audioStartCallbacks?: Set<AudioStartCallback>;
189
- /** Whether the current audio in this channel is paused */
180
+ export interface AudioErrorInfo {
181
+ channelNumber: number;
182
+ src: string;
183
+ fileName: string;
184
+ error: Error;
185
+ errorType: 'network' | 'decode' | 'unsupported' | 'permission' | 'abort' | 'timeout' | 'unknown';
186
+ timestamp: number;
187
+ retryAttempt?: number;
188
+ remainingInQueue: number;
189
+ }
190
+
191
+ /**
192
+ * Configuration for automatic retry behavior when audio fails to load or play
193
+ */
194
+ export interface RetryConfig {
195
+ enabled: boolean;
196
+ maxRetries: number;
197
+ baseDelay: number;
198
+ exponentialBackoff: boolean;
199
+ timeoutMs: number;
200
+ fallbackUrls?: string[];
201
+ skipOnFailure: boolean;
202
+ }
203
+
204
+ /**
205
+ * Configuration options for error recovery mechanisms
206
+ */
207
+ export interface ErrorRecoveryOptions {
208
+ autoRetry: boolean;
209
+ showUserFeedback: boolean;
210
+ logErrorsToAnalytics: boolean;
211
+ preserveQueueOnError: boolean;
212
+ fallbackToNextTrack: boolean;
213
+ }
214
+
215
+ /**
216
+ * Callback function type for audio error events
217
+ */
218
+ export type AudioErrorCallback = (errorInfo: AudioErrorInfo) => void;
219
+
220
+ /**
221
+ * Extended audio queue channel with error handling capabilities
222
+ */
223
+ export interface ExtendedAudioQueueChannel {
224
+ audioCompleteCallbacks: Set<AudioCompleteCallback>;
225
+ audioErrorCallbacks: Set<AudioErrorCallback>;
226
+ audioPauseCallbacks: Set<AudioPauseCallback>;
227
+ audioResumeCallbacks: Set<AudioResumeCallback>;
228
+ audioStartCallbacks: Set<AudioStartCallback>;
229
+ fadeState?: ChannelFadeState;
190
230
  isPaused?: boolean;
191
- /** Map of audio elements to their progress callback sets */
192
- progressCallbacks?: Map<HTMLAudioElement, Set<ProgressCallback>>;
193
- /** Set of callbacks for queue change events */
194
- queueChangeCallbacks?: Set<QueueChangeCallback>;
195
- /** Current volume level for this channel (0-1) */
231
+ progressCallbacks: Map<HTMLAudioElement | null, Set<ProgressCallback>>;
232
+ queue: HTMLAudioElement[];
233
+ queueChangeCallbacks: Set<QueueChangeCallback>;
234
+ retryConfig?: RetryConfig;
196
235
  volume?: number;
197
- /** Volume ducking configuration for this channel */
198
236
  volumeConfig?: VolumeConfig;
237
+ }
238
+
239
+ /**
240
+ * Easing function types for volume transitions
241
+ */
242
+ export enum EasingType {
243
+ Linear = 'linear',
244
+ EaseIn = 'ease-in',
245
+ EaseOut = 'ease-out',
246
+ EaseInOut = 'ease-in-out'
247
+ }
248
+
249
+ /**
250
+ * Fade type for pause/resume operations with integrated volume transitions
251
+ */
252
+ export enum FadeType {
253
+ Linear = 'linear',
254
+ Gentle = 'gentle',
255
+ Dramatic = 'dramatic'
256
+ }
257
+
258
+ /**
259
+ * Configuration for fade transitions
260
+ */
261
+ export interface FadeConfig {
262
+ /** Duration in milliseconds for the fade transition */
263
+ duration: number;
264
+ /** Easing curve to use when pausing (fading out) */
265
+ pauseCurve: EasingType;
266
+ /** Easing curve to use when resuming (fading in) */
267
+ resumeCurve: EasingType;
268
+ }
269
+
270
+ /**
271
+ * Internal fade state tracking for pause/resume with fade functionality
272
+ */
273
+ export interface ChannelFadeState {
274
+ /** The original volume level before fading began */
275
+ originalVolume: number;
276
+ /** The type of fade being used */
277
+ fadeType: FadeType;
278
+ /** Whether the channel is currently paused due to fade */
279
+ isPaused: boolean;
199
280
  }