audioq 2.0.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/events.js ADDED
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Event handling and emission for the audioq package
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cleanupProgressTracking = exports.setupProgressTracking = exports.emitAudioResume = exports.emitAudioPause = exports.emitAudioComplete = exports.emitAudioStart = exports.emitQueueChange = void 0;
7
+ const types_1 = require("./types");
8
+ const utils_1 = require("./utils");
9
+ /**
10
+ * Emits a queue change event to all registered listeners for a specific channel
11
+ * @param channelNumber - The channel number that experienced a queue change
12
+ * @param audioChannels - Array of audio channels
13
+ * @example
14
+ * ```typescript
15
+ * emitQueueChange(0, audioChannels); // Notifies all queue change listeners
16
+ * ```
17
+ */
18
+ const emitQueueChange = (channelNumber, audioChannels) => {
19
+ const channel = audioChannels[channelNumber];
20
+ if (!(channel === null || channel === void 0 ? void 0 : channel.queueChangeCallbacks))
21
+ return;
22
+ const snapshot = (0, utils_1.createQueueSnapshot)(channelNumber, audioChannels);
23
+ if (!snapshot)
24
+ return;
25
+ channel.queueChangeCallbacks.forEach((callback) => {
26
+ try {
27
+ callback(snapshot);
28
+ }
29
+ catch (error) {
30
+ // eslint-disable-next-line no-console
31
+ console.error('Error in queue change callback:', error);
32
+ }
33
+ });
34
+ };
35
+ exports.emitQueueChange = emitQueueChange;
36
+ /**
37
+ * Emits an audio start event to all registered listeners for a specific channel
38
+ * @param channelNumber - The channel number where audio started
39
+ * @param audioInfo - Information about the audio that started
40
+ * @param audioChannels - Array of audio channels
41
+ * @example
42
+ * ```typescript
43
+ * emitAudioStart(0, { src: 'song.mp3', fileName: 'song.mp3', duration: 180000, channelNumber: 0 }, audioChannels);
44
+ * ```
45
+ */
46
+ const emitAudioStart = (channelNumber, audioInfo, audioChannels) => {
47
+ const channel = audioChannels[channelNumber];
48
+ if (!(channel === null || channel === void 0 ? void 0 : channel.audioStartCallbacks))
49
+ return;
50
+ channel.audioStartCallbacks.forEach((callback) => {
51
+ try {
52
+ callback(audioInfo);
53
+ }
54
+ catch (error) {
55
+ // eslint-disable-next-line no-console
56
+ console.error('Error in audio start callback:', error);
57
+ }
58
+ });
59
+ };
60
+ exports.emitAudioStart = emitAudioStart;
61
+ /**
62
+ * Emits an audio complete event to all registered listeners for a specific channel
63
+ * @param channelNumber - The channel number where audio completed
64
+ * @param audioInfo - Information about the audio that completed
65
+ * @param audioChannels - Array of audio channels
66
+ * @example
67
+ * ```typescript
68
+ * emitAudioComplete(0, { src: 'song.mp3', fileName: 'song.mp3', channelNumber: 0, remainingInQueue: 2 }, audioChannels);
69
+ * ```
70
+ */
71
+ const emitAudioComplete = (channelNumber, audioInfo, audioChannels) => {
72
+ const channel = audioChannels[channelNumber];
73
+ if (!(channel === null || channel === void 0 ? void 0 : channel.audioCompleteCallbacks))
74
+ return;
75
+ channel.audioCompleteCallbacks.forEach((callback) => {
76
+ try {
77
+ callback(audioInfo);
78
+ }
79
+ catch (error) {
80
+ // eslint-disable-next-line no-console
81
+ console.error('Error in audio complete callback:', error);
82
+ }
83
+ });
84
+ };
85
+ exports.emitAudioComplete = emitAudioComplete;
86
+ /**
87
+ * Emits an audio pause event to all registered listeners for a specific channel
88
+ * @param channelNumber - The channel number where audio was paused
89
+ * @param audioInfo - Information about the audio that was paused
90
+ * @param audioChannels - Array of audio channels
91
+ * @example
92
+ * ```typescript
93
+ * emitAudioPause(0, audioInfo, audioChannels);
94
+ * ```
95
+ */
96
+ const emitAudioPause = (channelNumber, audioInfo, audioChannels) => {
97
+ const channel = audioChannels[channelNumber];
98
+ if (!(channel === null || channel === void 0 ? void 0 : channel.audioPauseCallbacks))
99
+ return;
100
+ channel.audioPauseCallbacks.forEach((callback) => {
101
+ try {
102
+ callback(channelNumber, audioInfo);
103
+ }
104
+ catch (error) {
105
+ // eslint-disable-next-line no-console
106
+ console.error('Error in audio pause callback:', error);
107
+ }
108
+ });
109
+ };
110
+ exports.emitAudioPause = emitAudioPause;
111
+ /**
112
+ * Emits an audio resume event to all registered listeners for a specific channel
113
+ * @param channelNumber - The channel number where audio was resumed
114
+ * @param audioInfo - Information about the audio that was resumed
115
+ * @param audioChannels - Array of audio channels
116
+ * @example
117
+ * ```typescript
118
+ * emitAudioResume(0, audioInfo, audioChannels);
119
+ * ```
120
+ */
121
+ const emitAudioResume = (channelNumber, audioInfo, audioChannels) => {
122
+ const channel = audioChannels[channelNumber];
123
+ if (!(channel === null || channel === void 0 ? void 0 : channel.audioResumeCallbacks))
124
+ return;
125
+ channel.audioResumeCallbacks.forEach((callback) => {
126
+ try {
127
+ callback(channelNumber, audioInfo);
128
+ }
129
+ catch (error) {
130
+ // eslint-disable-next-line no-console
131
+ console.error('Error in audio resume callback:', error);
132
+ }
133
+ });
134
+ };
135
+ exports.emitAudioResume = emitAudioResume;
136
+ // Store listener functions for cleanup
137
+ const progressListeners = new WeakMap();
138
+ /**
139
+ * Sets up comprehensive progress tracking for an audio element
140
+ * @param audio - The HTML audio element to track
141
+ * @param channelNumber - The channel number this audio belongs to
142
+ * @param audioChannels - Array of audio channels
143
+ * @example
144
+ * ```typescript
145
+ * const audioElement = new Audio('song.mp3');
146
+ * setupProgressTracking(audioElement, 0, audioChannels);
147
+ * ```
148
+ */
149
+ const setupProgressTracking = (audio, channelNumber, audioChannels) => {
150
+ const channel = audioChannels[channelNumber];
151
+ if (!channel)
152
+ return;
153
+ if (!channel.progressCallbacks) {
154
+ channel.progressCallbacks = new Map();
155
+ }
156
+ // Don't set up tracking if already exists
157
+ if (progressListeners.has(audio))
158
+ return;
159
+ const updateProgress = () => {
160
+ var _a, _b, _c, _d;
161
+ // Get callbacks for this specific audio element AND the channel-wide callbacks
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();
164
+ // Combine both sets of callbacks
165
+ const allCallbacks = new Set([...audioCallbacks, ...channelCallbacks]);
166
+ if (allCallbacks.size === 0)
167
+ return;
168
+ const info = (0, utils_1.getAudioInfoFromElement)(audio, channelNumber, audioChannels);
169
+ if (info) {
170
+ allCallbacks.forEach((callback) => {
171
+ try {
172
+ callback(info);
173
+ }
174
+ catch (error) {
175
+ // eslint-disable-next-line no-console
176
+ console.error('Error in progress callback:', error);
177
+ }
178
+ });
179
+ }
180
+ };
181
+ // Store the listener function for cleanup
182
+ progressListeners.set(audio, updateProgress);
183
+ // Set up comprehensive event listeners for progress tracking
184
+ audio.addEventListener('timeupdate', updateProgress);
185
+ audio.addEventListener('loadedmetadata', updateProgress);
186
+ audio.addEventListener('play', updateProgress);
187
+ audio.addEventListener('pause', updateProgress);
188
+ audio.addEventListener('ended', updateProgress);
189
+ };
190
+ exports.setupProgressTracking = setupProgressTracking;
191
+ /**
192
+ * Cleans up progress tracking for an audio element to prevent memory leaks
193
+ * @param audio - The HTML audio element to clean up
194
+ * @param channelNumber - The channel number this audio belongs to
195
+ * @param audioChannels - Array of audio channels
196
+ * @example
197
+ * ```typescript
198
+ * cleanupProgressTracking(audioElement, 0, audioChannels);
199
+ * ```
200
+ */
201
+ const cleanupProgressTracking = (audio, channelNumber, audioChannels) => {
202
+ const channel = audioChannels[channelNumber];
203
+ if (!(channel === null || channel === void 0 ? void 0 : channel.progressCallbacks))
204
+ return;
205
+ // Remove event listeners
206
+ const updateProgress = progressListeners.get(audio);
207
+ if (updateProgress) {
208
+ audio.removeEventListener('timeupdate', updateProgress);
209
+ audio.removeEventListener('loadedmetadata', updateProgress);
210
+ audio.removeEventListener('play', updateProgress);
211
+ audio.removeEventListener('pause', updateProgress);
212
+ audio.removeEventListener('ended', updateProgress);
213
+ progressListeners.delete(audio);
214
+ }
215
+ channel.progressCallbacks.delete(audio);
216
+ };
217
+ exports.cleanupProgressTracking = cleanupProgressTracking;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @fileoverview Main entry point for the audioq package
3
+ * Exports all public functions and types for audio queue management, pause/resume controls,
4
+ * volume management with ducking, progress tracking, and comprehensive event system
5
+ */
6
+ export { queueAudio, queueAudioPriority, stopCurrentAudioInChannel, stopAllAudioInChannel, stopAllAudio, playAudioQueue, destroyChannel, destroyAllChannels, setQueueConfig, getQueueConfig, setChannelQueueLimit } from './core';
7
+ export { clearQueueAfterCurrent, getQueueItemInfo, getQueueLength, removeQueuedItem, reorderQueue, swapQueueItems } from './queue-manipulation';
8
+ export { getErrorRecovery, getRetryConfig, offAudioError, onAudioError, retryFailedAudio, setErrorRecovery, setRetryConfig } from './errors';
9
+ export { getAllChannelsPauseState, isChannelPaused, pauseAllChannels, pauseAllWithFade, pauseChannel, pauseWithFade, resumeAllChannels, resumeAllWithFade, resumeChannel, resumeWithFade, togglePauseAllChannels, togglePauseAllWithFade, togglePauseChannel, togglePauseWithFade } from './pause';
10
+ export { cancelAllVolumeTransitions, cancelVolumeTransition, clearVolumeDucking, getAllChannelsVolume, getChannelVolume, getFadeConfig, getGlobalVolume, setAllChannelsVolume, setChannelVolume, setGlobalVolume, setVolumeDucking, transitionVolume } from './volume';
11
+ export { cleanupWebAudioNodes, createWebAudioNodes, getAudioContext, getWebAudioConfig, getWebAudioSupport, getWebAudioVolume, isIOSDevice, isWebAudioSupported, resumeAudioContext, setWebAudioConfig, setWebAudioVolume, shouldUseWebAudio } from './web-audio';
12
+ export { getAllChannelsInfo, getCurrentAudioInfo, getQueueSnapshot, offAudioComplete, offAudioPause, offAudioProgress, offAudioResume, offAudioStart, offQueueChange, onAudioComplete, onAudioPause, onAudioProgress, onAudioResume, onAudioStart, onQueueChange } from './info';
13
+ export { audioChannels } from './info';
14
+ export { cleanWebpackFilename, createQueueSnapshot, extractFileName, getAudioInfoFromElement, sanitizeForDisplay, validateAudioUrl } from './utils';
15
+ export type { AudioCompleteCallback, AudioCompleteInfo, AudioErrorCallback, AudioErrorInfo, AudioInfo, AudioPauseCallback, AudioQueueOptions, AudioResumeCallback, AudioStartCallback, AudioStartInfo, ChannelFadeState, ErrorRecoveryOptions, ExtendedAudioQueueChannel, FadeConfig, ProgressCallback, QueueChangeCallback, QueueConfig, QueueItem, QueueManipulationResult, QueueSnapshot, RetryConfig, VolumeConfig, WebAudioConfig, WebAudioNodeSet, WebAudioSupport } from './types';
16
+ export { AudioErrorType, EasingType, FadeType, MAX_CHANNELS, TimerType, GLOBAL_PROGRESS_KEY } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Main entry point for the audioq package
4
+ * Exports all public functions and types for audio queue management, pause/resume controls,
5
+ * volume management with ducking, progress tracking, and comprehensive event system
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.transitionVolume = exports.setVolumeDucking = exports.setGlobalVolume = exports.setChannelVolume = exports.setAllChannelsVolume = exports.getGlobalVolume = exports.getFadeConfig = exports.getChannelVolume = exports.getAllChannelsVolume = exports.clearVolumeDucking = exports.cancelVolumeTransition = exports.cancelAllVolumeTransitions = 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.swapQueueItems = exports.reorderQueue = exports.removeQueuedItem = exports.getQueueLength = exports.getQueueItemInfo = exports.clearQueueAfterCurrent = exports.setChannelQueueLimit = exports.getQueueConfig = exports.setQueueConfig = exports.destroyAllChannels = exports.destroyChannel = exports.playAudioQueue = exports.stopAllAudio = exports.stopAllAudioInChannel = exports.stopCurrentAudioInChannel = exports.queueAudioPriority = exports.queueAudio = void 0;
9
+ exports.GLOBAL_PROGRESS_KEY = exports.TimerType = exports.MAX_CHANNELS = exports.FadeType = exports.EasingType = exports.AudioErrorType = exports.validateAudioUrl = exports.sanitizeForDisplay = exports.getAudioInfoFromElement = exports.extractFileName = exports.createQueueSnapshot = exports.cleanWebpackFilename = exports.audioChannels = exports.onQueueChange = exports.onAudioStart = exports.onAudioResume = exports.onAudioProgress = exports.onAudioPause = exports.onAudioComplete = exports.offQueueChange = exports.offAudioStart = exports.offAudioResume = exports.offAudioProgress = exports.offAudioPause = exports.offAudioComplete = exports.getQueueSnapshot = exports.getCurrentAudioInfo = exports.getAllChannelsInfo = exports.shouldUseWebAudio = exports.setWebAudioVolume = exports.setWebAudioConfig = exports.resumeAudioContext = exports.isWebAudioSupported = exports.isIOSDevice = exports.getWebAudioVolume = exports.getWebAudioSupport = exports.getWebAudioConfig = exports.getAudioContext = exports.createWebAudioNodes = exports.cleanupWebAudioNodes = void 0;
10
+ // Core queue management functions
11
+ var core_1 = require("./core");
12
+ Object.defineProperty(exports, "queueAudio", { enumerable: true, get: function () { return core_1.queueAudio; } });
13
+ Object.defineProperty(exports, "queueAudioPriority", { enumerable: true, get: function () { return core_1.queueAudioPriority; } });
14
+ Object.defineProperty(exports, "stopCurrentAudioInChannel", { enumerable: true, get: function () { return core_1.stopCurrentAudioInChannel; } });
15
+ Object.defineProperty(exports, "stopAllAudioInChannel", { enumerable: true, get: function () { return core_1.stopAllAudioInChannel; } });
16
+ Object.defineProperty(exports, "stopAllAudio", { enumerable: true, get: function () { return core_1.stopAllAudio; } });
17
+ Object.defineProperty(exports, "playAudioQueue", { enumerable: true, get: function () { return core_1.playAudioQueue; } });
18
+ Object.defineProperty(exports, "destroyChannel", { enumerable: true, get: function () { return core_1.destroyChannel; } });
19
+ Object.defineProperty(exports, "destroyAllChannels", { enumerable: true, get: function () { return core_1.destroyAllChannels; } });
20
+ Object.defineProperty(exports, "setQueueConfig", { enumerable: true, get: function () { return core_1.setQueueConfig; } });
21
+ Object.defineProperty(exports, "getQueueConfig", { enumerable: true, get: function () { return core_1.getQueueConfig; } });
22
+ Object.defineProperty(exports, "setChannelQueueLimit", { enumerable: true, get: function () { return core_1.setChannelQueueLimit; } });
23
+ // Queue manipulation functions
24
+ var queue_manipulation_1 = require("./queue-manipulation");
25
+ Object.defineProperty(exports, "clearQueueAfterCurrent", { enumerable: true, get: function () { return queue_manipulation_1.clearQueueAfterCurrent; } });
26
+ Object.defineProperty(exports, "getQueueItemInfo", { enumerable: true, get: function () { return queue_manipulation_1.getQueueItemInfo; } });
27
+ Object.defineProperty(exports, "getQueueLength", { enumerable: true, get: function () { return queue_manipulation_1.getQueueLength; } });
28
+ Object.defineProperty(exports, "removeQueuedItem", { enumerable: true, get: function () { return queue_manipulation_1.removeQueuedItem; } });
29
+ Object.defineProperty(exports, "reorderQueue", { enumerable: true, get: function () { return queue_manipulation_1.reorderQueue; } });
30
+ Object.defineProperty(exports, "swapQueueItems", { enumerable: true, get: function () { return queue_manipulation_1.swapQueueItems; } });
31
+ // Error handling and recovery functions
32
+ var errors_1 = require("./errors");
33
+ Object.defineProperty(exports, "getErrorRecovery", { enumerable: true, get: function () { return errors_1.getErrorRecovery; } });
34
+ Object.defineProperty(exports, "getRetryConfig", { enumerable: true, get: function () { return errors_1.getRetryConfig; } });
35
+ Object.defineProperty(exports, "offAudioError", { enumerable: true, get: function () { return errors_1.offAudioError; } });
36
+ Object.defineProperty(exports, "onAudioError", { enumerable: true, get: function () { return errors_1.onAudioError; } });
37
+ Object.defineProperty(exports, "retryFailedAudio", { enumerable: true, get: function () { return errors_1.retryFailedAudio; } });
38
+ Object.defineProperty(exports, "setErrorRecovery", { enumerable: true, get: function () { return errors_1.setErrorRecovery; } });
39
+ Object.defineProperty(exports, "setRetryConfig", { enumerable: true, get: function () { return errors_1.setRetryConfig; } });
40
+ // Pause and resume management functions
41
+ var pause_1 = require("./pause");
42
+ Object.defineProperty(exports, "getAllChannelsPauseState", { enumerable: true, get: function () { return pause_1.getAllChannelsPauseState; } });
43
+ Object.defineProperty(exports, "isChannelPaused", { enumerable: true, get: function () { return pause_1.isChannelPaused; } });
44
+ Object.defineProperty(exports, "pauseAllChannels", { enumerable: true, get: function () { return pause_1.pauseAllChannels; } });
45
+ Object.defineProperty(exports, "pauseAllWithFade", { enumerable: true, get: function () { return pause_1.pauseAllWithFade; } });
46
+ Object.defineProperty(exports, "pauseChannel", { enumerable: true, get: function () { return pause_1.pauseChannel; } });
47
+ Object.defineProperty(exports, "pauseWithFade", { enumerable: true, get: function () { return pause_1.pauseWithFade; } });
48
+ Object.defineProperty(exports, "resumeAllChannels", { enumerable: true, get: function () { return pause_1.resumeAllChannels; } });
49
+ Object.defineProperty(exports, "resumeAllWithFade", { enumerable: true, get: function () { return pause_1.resumeAllWithFade; } });
50
+ Object.defineProperty(exports, "resumeChannel", { enumerable: true, get: function () { return pause_1.resumeChannel; } });
51
+ Object.defineProperty(exports, "resumeWithFade", { enumerable: true, get: function () { return pause_1.resumeWithFade; } });
52
+ Object.defineProperty(exports, "togglePauseAllChannels", { enumerable: true, get: function () { return pause_1.togglePauseAllChannels; } });
53
+ Object.defineProperty(exports, "togglePauseAllWithFade", { enumerable: true, get: function () { return pause_1.togglePauseAllWithFade; } });
54
+ Object.defineProperty(exports, "togglePauseChannel", { enumerable: true, get: function () { return pause_1.togglePauseChannel; } });
55
+ Object.defineProperty(exports, "togglePauseWithFade", { enumerable: true, get: function () { return pause_1.togglePauseWithFade; } });
56
+ // Volume control and ducking functions
57
+ var volume_1 = require("./volume");
58
+ Object.defineProperty(exports, "cancelAllVolumeTransitions", { enumerable: true, get: function () { return volume_1.cancelAllVolumeTransitions; } });
59
+ Object.defineProperty(exports, "cancelVolumeTransition", { enumerable: true, get: function () { return volume_1.cancelVolumeTransition; } });
60
+ Object.defineProperty(exports, "clearVolumeDucking", { enumerable: true, get: function () { return volume_1.clearVolumeDucking; } });
61
+ Object.defineProperty(exports, "getAllChannelsVolume", { enumerable: true, get: function () { return volume_1.getAllChannelsVolume; } });
62
+ Object.defineProperty(exports, "getChannelVolume", { enumerable: true, get: function () { return volume_1.getChannelVolume; } });
63
+ Object.defineProperty(exports, "getFadeConfig", { enumerable: true, get: function () { return volume_1.getFadeConfig; } });
64
+ Object.defineProperty(exports, "getGlobalVolume", { enumerable: true, get: function () { return volume_1.getGlobalVolume; } });
65
+ Object.defineProperty(exports, "setAllChannelsVolume", { enumerable: true, get: function () { return volume_1.setAllChannelsVolume; } });
66
+ Object.defineProperty(exports, "setChannelVolume", { enumerable: true, get: function () { return volume_1.setChannelVolume; } });
67
+ Object.defineProperty(exports, "setGlobalVolume", { enumerable: true, get: function () { return volume_1.setGlobalVolume; } });
68
+ Object.defineProperty(exports, "setVolumeDucking", { enumerable: true, get: function () { return volume_1.setVolumeDucking; } });
69
+ Object.defineProperty(exports, "transitionVolume", { enumerable: true, get: function () { return volume_1.transitionVolume; } });
70
+ // Web Audio API support functions
71
+ var web_audio_1 = require("./web-audio");
72
+ Object.defineProperty(exports, "cleanupWebAudioNodes", { enumerable: true, get: function () { return web_audio_1.cleanupWebAudioNodes; } });
73
+ Object.defineProperty(exports, "createWebAudioNodes", { enumerable: true, get: function () { return web_audio_1.createWebAudioNodes; } });
74
+ Object.defineProperty(exports, "getAudioContext", { enumerable: true, get: function () { return web_audio_1.getAudioContext; } });
75
+ Object.defineProperty(exports, "getWebAudioConfig", { enumerable: true, get: function () { return web_audio_1.getWebAudioConfig; } });
76
+ Object.defineProperty(exports, "getWebAudioSupport", { enumerable: true, get: function () { return web_audio_1.getWebAudioSupport; } });
77
+ Object.defineProperty(exports, "getWebAudioVolume", { enumerable: true, get: function () { return web_audio_1.getWebAudioVolume; } });
78
+ Object.defineProperty(exports, "isIOSDevice", { enumerable: true, get: function () { return web_audio_1.isIOSDevice; } });
79
+ Object.defineProperty(exports, "isWebAudioSupported", { enumerable: true, get: function () { return web_audio_1.isWebAudioSupported; } });
80
+ Object.defineProperty(exports, "resumeAudioContext", { enumerable: true, get: function () { return web_audio_1.resumeAudioContext; } });
81
+ Object.defineProperty(exports, "setWebAudioConfig", { enumerable: true, get: function () { return web_audio_1.setWebAudioConfig; } });
82
+ Object.defineProperty(exports, "setWebAudioVolume", { enumerable: true, get: function () { return web_audio_1.setWebAudioVolume; } });
83
+ Object.defineProperty(exports, "shouldUseWebAudio", { enumerable: true, get: function () { return web_audio_1.shouldUseWebAudio; } });
84
+ // Audio information and progress tracking functions
85
+ var info_1 = require("./info");
86
+ Object.defineProperty(exports, "getAllChannelsInfo", { enumerable: true, get: function () { return info_1.getAllChannelsInfo; } });
87
+ Object.defineProperty(exports, "getCurrentAudioInfo", { enumerable: true, get: function () { return info_1.getCurrentAudioInfo; } });
88
+ Object.defineProperty(exports, "getQueueSnapshot", { enumerable: true, get: function () { return info_1.getQueueSnapshot; } });
89
+ Object.defineProperty(exports, "offAudioComplete", { enumerable: true, get: function () { return info_1.offAudioComplete; } });
90
+ Object.defineProperty(exports, "offAudioPause", { enumerable: true, get: function () { return info_1.offAudioPause; } });
91
+ Object.defineProperty(exports, "offAudioProgress", { enumerable: true, get: function () { return info_1.offAudioProgress; } });
92
+ Object.defineProperty(exports, "offAudioResume", { enumerable: true, get: function () { return info_1.offAudioResume; } });
93
+ Object.defineProperty(exports, "offAudioStart", { enumerable: true, get: function () { return info_1.offAudioStart; } });
94
+ Object.defineProperty(exports, "offQueueChange", { enumerable: true, get: function () { return info_1.offQueueChange; } });
95
+ Object.defineProperty(exports, "onAudioComplete", { enumerable: true, get: function () { return info_1.onAudioComplete; } });
96
+ Object.defineProperty(exports, "onAudioPause", { enumerable: true, get: function () { return info_1.onAudioPause; } });
97
+ Object.defineProperty(exports, "onAudioProgress", { enumerable: true, get: function () { return info_1.onAudioProgress; } });
98
+ Object.defineProperty(exports, "onAudioResume", { enumerable: true, get: function () { return info_1.onAudioResume; } });
99
+ Object.defineProperty(exports, "onAudioStart", { enumerable: true, get: function () { return info_1.onAudioStart; } });
100
+ Object.defineProperty(exports, "onQueueChange", { enumerable: true, get: function () { return info_1.onQueueChange; } });
101
+ // Core data access for legacy compatibility
102
+ var info_2 = require("./info");
103
+ Object.defineProperty(exports, "audioChannels", { enumerable: true, get: function () { return info_2.audioChannels; } });
104
+ // Utility helper functions
105
+ var utils_1 = require("./utils");
106
+ Object.defineProperty(exports, "cleanWebpackFilename", { enumerable: true, get: function () { return utils_1.cleanWebpackFilename; } });
107
+ Object.defineProperty(exports, "createQueueSnapshot", { enumerable: true, get: function () { return utils_1.createQueueSnapshot; } });
108
+ Object.defineProperty(exports, "extractFileName", { enumerable: true, get: function () { return utils_1.extractFileName; } });
109
+ Object.defineProperty(exports, "getAudioInfoFromElement", { enumerable: true, get: function () { return utils_1.getAudioInfoFromElement; } });
110
+ Object.defineProperty(exports, "sanitizeForDisplay", { enumerable: true, get: function () { return utils_1.sanitizeForDisplay; } });
111
+ Object.defineProperty(exports, "validateAudioUrl", { enumerable: true, get: function () { return utils_1.validateAudioUrl; } });
112
+ // Enums and constants
113
+ var types_1 = require("./types");
114
+ Object.defineProperty(exports, "AudioErrorType", { enumerable: true, get: function () { return types_1.AudioErrorType; } });
115
+ Object.defineProperty(exports, "EasingType", { enumerable: true, get: function () { return types_1.EasingType; } });
116
+ Object.defineProperty(exports, "FadeType", { enumerable: true, get: function () { return types_1.FadeType; } });
117
+ Object.defineProperty(exports, "MAX_CHANNELS", { enumerable: true, get: function () { return types_1.MAX_CHANNELS; } });
118
+ Object.defineProperty(exports, "TimerType", { enumerable: true, get: function () { return types_1.TimerType; } });
119
+ Object.defineProperty(exports, "GLOBAL_PROGRESS_KEY", { enumerable: true, get: function () { return types_1.GLOBAL_PROGRESS_KEY; } });
package/dist/info.d.ts ADDED
@@ -0,0 +1,224 @@
1
+ /**
2
+ * @fileoverview Audio information and progress tracking functions for the audioq package
3
+ */
4
+ import { AudioInfo, QueueSnapshot, ProgressCallback, QueueChangeCallback, AudioStartCallback, AudioCompleteCallback, AudioPauseCallback, AudioResumeCallback, ExtendedAudioQueueChannel } from './types';
5
+ /**
6
+ * Gets the current list of whitelisted channel properties
7
+ * This is automatically derived from the ExtendedAudioQueueChannel interface
8
+ * @returns Array of whitelisted property names
9
+ * @internal
10
+ */
11
+ export declare const getWhitelistedChannelProperties: () => string[];
12
+ /**
13
+ * Returns the list of non-whitelisted properties found on a specific channel
14
+ * These are properties that will trigger warnings when modified directly
15
+ * @param channelNumber - The channel number to inspect (defaults to 0)
16
+ * @returns Array of property names that are not in the whitelist, or empty array if channel doesn't exist
17
+ * @example
18
+ * ```typescript
19
+ * // Add some custom property to a channel
20
+ * (audioChannels[0] as any).customProperty = 'test';
21
+ *
22
+ * const nonWhitelisted = getNonWhitelistedChannelProperties(0);
23
+ * console.log(nonWhitelisted); // ['customProperty']
24
+ * ```
25
+ * @internal
26
+ */
27
+ export declare const getNonWhitelistedChannelProperties: (channelNumber?: number) => string[];
28
+ /**
29
+ * Global array to store audio channels with their queues and callback management
30
+ * Each channel maintains its own audio queue and event callback sets
31
+ *
32
+ * Note: While you can inspect this array for debugging, direct modification is discouraged.
33
+ * Use the provided API functions for safe channel management.
34
+ */
35
+ export declare const audioChannels: ExtendedAudioQueueChannel[];
36
+ /**
37
+ * Gets current audio information for a specific channel
38
+ * @param channelNumber - The channel number (defaults to 0)
39
+ * @returns AudioInfo object or null if no audio is playing
40
+ * @example
41
+ * ```typescript
42
+ * const info = getCurrentAudioInfo(0);
43
+ * if (info) {
44
+ * console.log(`Currently playing: ${info.fileName}`);
45
+ * console.log(`Progress: ${(info.progress * 100).toFixed(1)}%`);
46
+ * }
47
+ * ```
48
+ */
49
+ export declare const getCurrentAudioInfo: (channelNumber?: number) => AudioInfo | null;
50
+ /**
51
+ * Gets audio information for all channels
52
+ * @returns Array of AudioInfo objects (null for channels with no audio)
53
+ * @example
54
+ * ```typescript
55
+ * const allInfo = getAllChannelsInfo();
56
+ * allInfo.forEach((info, channel) => {
57
+ * if (info) {
58
+ * console.log(`Channel ${channel}: ${info.fileName}`);
59
+ * }
60
+ * });
61
+ * ```
62
+ */
63
+ export declare const getAllChannelsInfo: () => (AudioInfo | null)[];
64
+ /**
65
+ * Gets a complete snapshot of the queue state for a specific channel
66
+ * @param channelNumber - The channel number (defaults to 0)
67
+ * @returns QueueSnapshot object or null if channel doesn't exist
68
+ * @example
69
+ * ```typescript
70
+ * const snapshot = getQueueSnapshot();
71
+ * if (snapshot) {
72
+ * console.log(`Queue has ${snapshot.totalItems} items`);
73
+ * console.log(`Currently playing: ${snapshot.items[0]?.fileName}`);
74
+ * }
75
+ * const channelSnapshot = getQueueSnapshot(2);
76
+ * ```
77
+ */
78
+ export declare const getQueueSnapshot: (channelNumber?: number) => QueueSnapshot | null;
79
+ /**
80
+ * Subscribes to real-time progress updates for a specific channel
81
+ * @param channelNumber - The channel number
82
+ * @param callback - Function to call with audio info updates
83
+ * @throws Error if the channel number exceeds the maximum allowed channels
84
+ * @example
85
+ * ```typescript
86
+ * onAudioProgress(0, (info) => {
87
+ * updateProgressBar(info.progress);
88
+ * updateTimeDisplay(info.currentTime, info.duration);
89
+ * });
90
+ * ```
91
+ */
92
+ export declare const onAudioProgress: (channelNumber: number, callback: ProgressCallback) => void;
93
+ /**
94
+ * Removes progress listeners for a specific channel
95
+ * @param channelNumber - The channel number (defaults to 0)
96
+ * @example
97
+ * ```typescript
98
+ * offAudioProgress();
99
+ * offAudioProgress(1); // Stop receiving progress updates for channel 1
100
+ * ```
101
+ */
102
+ export declare function offAudioProgress(channelNumber?: number): void;
103
+ /**
104
+ * Subscribes to queue change events for a specific channel
105
+ * @param channelNumber - The channel number to monitor
106
+ * @param callback - Function to call when queue changes
107
+ * @throws Error if the channel number exceeds the maximum allowed channels
108
+ * @example
109
+ * ```typescript
110
+ * onQueueChange(0, (snapshot) => {
111
+ * updateQueueDisplay(snapshot.items);
112
+ * updateQueueCount(snapshot.totalItems);
113
+ * });
114
+ * ```
115
+ */
116
+ export declare const onQueueChange: (channelNumber: number, callback: QueueChangeCallback) => void;
117
+ /**
118
+ * Removes queue change listeners for a specific channel
119
+ * @param channelNumber - The channel number (defaults to 0)
120
+ * @example
121
+ * ```typescript
122
+ * offQueueChange(); // Stop receiving queue change notifications for default channel (0)
123
+ * offQueueChange(1); // Stop receiving queue change notifications for channel 1
124
+ * ```
125
+ */
126
+ export declare const offQueueChange: (channelNumber?: number) => void;
127
+ /**
128
+ * Subscribes to audio start events for a specific channel
129
+ * @param channelNumber - The channel number to monitor
130
+ * @param callback - Function to call when audio starts playing
131
+ * @throws Error if the channel number exceeds the maximum allowed channels
132
+ * @example
133
+ * ```typescript
134
+ * onAudioStart(0, (info) => {
135
+ * showNowPlaying(info.fileName);
136
+ * setTotalDuration(info.duration);
137
+ * });
138
+ * ```
139
+ */
140
+ export declare const onAudioStart: (channelNumber: number, callback: AudioStartCallback) => void;
141
+ /**
142
+ * Subscribes to audio complete events for a specific channel
143
+ * @param channelNumber - The channel number to monitor
144
+ * @param callback - Function to call when audio completes
145
+ * @throws Error if the channel number exceeds the maximum allowed channels
146
+ * @example
147
+ * ```typescript
148
+ * onAudioComplete(0, (info) => {
149
+ * logPlaybackComplete(info.fileName);
150
+ * if (info.remainingInQueue === 0) {
151
+ * showQueueComplete();
152
+ * }
153
+ * });
154
+ * ```
155
+ */
156
+ export declare const onAudioComplete: (channelNumber: number, callback: AudioCompleteCallback) => void;
157
+ /**
158
+ * Subscribes to audio pause events for a specific channel
159
+ * @param channelNumber - The channel number to monitor
160
+ * @param callback - Function to call when audio is paused
161
+ * @throws Error if the channel number exceeds the maximum allowed channels
162
+ * @example
163
+ * ```typescript
164
+ * onAudioPause(0, (channelNumber, info) => {
165
+ * showPauseIndicator();
166
+ * logPauseEvent(info.fileName, info.currentTime);
167
+ * });
168
+ * ```
169
+ */
170
+ export declare const onAudioPause: (channelNumber: number, callback: AudioPauseCallback) => void;
171
+ /**
172
+ * Subscribes to audio resume events for a specific channel
173
+ * @param channelNumber - The channel number to monitor
174
+ * @param callback - Function to call when audio is resumed
175
+ * @throws Error if the channel number exceeds the maximum allowed channels
176
+ * @example
177
+ * ```typescript
178
+ * onAudioResume(0, (channelNumber, info) => {
179
+ * hidePauseIndicator();
180
+ * logResumeEvent(info.fileName, info.currentTime);
181
+ * });
182
+ * ```
183
+ */
184
+ export declare const onAudioResume: (channelNumber: number, callback: AudioResumeCallback) => void;
185
+ /**
186
+ * Removes pause event listeners for a specific channel
187
+ * @param channelNumber - The channel number (defaults to 0)
188
+ * @example
189
+ * ```typescript
190
+ * offAudioPause(); // Stop receiving pause notifications for default channel (0)
191
+ * offAudioPause(1); // Stop receiving pause notifications for channel 1
192
+ * ```
193
+ */
194
+ export declare const offAudioPause: (channelNumber?: number) => void;
195
+ /**
196
+ * Removes resume event listeners for a specific channel
197
+ * @param channelNumber - The channel number (defaults to 0)
198
+ * @example
199
+ * ```typescript
200
+ * offAudioResume(); // Stop receiving resume notifications for default channel (0)
201
+ * offAudioResume(1); // Stop receiving resume notifications for channel 1
202
+ * ```
203
+ */
204
+ export declare const offAudioResume: (channelNumber?: number) => void;
205
+ /**
206
+ * Removes audio start event listeners for a specific channel
207
+ * @param channelNumber - The channel number (defaults to 0)
208
+ * @example
209
+ * ```typescript
210
+ * offAudioStart(); // Stop receiving start notifications for default channel (0)
211
+ * offAudioStart(1); // Stop receiving start notifications for channel 1
212
+ * ```
213
+ */
214
+ export declare const offAudioStart: (channelNumber?: number) => void;
215
+ /**
216
+ * Removes audio complete event listeners for a specific channel
217
+ * @param channelNumber - The channel number (defaults to 0)
218
+ * @example
219
+ * ```typescript
220
+ * offAudioComplete(); // Stop receiving completion notifications for default channel (0)
221
+ * offAudioComplete(1); // Stop receiving completion notifications for channel 1
222
+ * ```
223
+ */
224
+ export declare const offAudioComplete: (channelNumber?: number) => void;