audio-channel-queue 1.9.0 → 1.10.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/README.md +197 -313
- package/dist/core.d.ts +59 -1
- package/dist/core.js +331 -40
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +10 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +21 -2
- package/dist/info.d.ts +17 -6
- package/dist/info.js +81 -10
- package/dist/pause.js +1 -1
- package/dist/queue-manipulation.d.ts +104 -0
- package/dist/queue-manipulation.js +319 -0
- package/dist/types.d.ts +46 -8
- package/dist/types.js +13 -1
- package/dist/utils.d.ts +25 -0
- package/dist/utils.js +98 -10
- package/dist/volume.d.ts +14 -1
- package/dist/volume.js +173 -54
- package/package.json +12 -2
- package/src/core.ts +389 -50
- package/src/errors.ts +14 -2
- package/src/index.ts +26 -5
- package/src/info.ts +107 -9
- package/src/pause.ts +4 -6
- package/src/queue-manipulation.ts +378 -0
- package/src/types.ts +51 -9
- package/src/utils.ts +110 -9
- package/src/volume.ts +214 -62
package/dist/index.js
CHANGED
|
@@ -5,8 +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.
|
|
9
|
-
exports.GLOBAL_PROGRESS_KEY = exports.FadeType = exports.EasingType = exports.getAudioInfoFromElement = exports.extractFileName = exports.createQueueSnapshot = exports.cleanWebpackFilename = void 0;
|
|
8
|
+
exports.getAllChannelsInfo = exports.cancelAllVolumeTransitions = exports.cancelVolumeTransition = 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.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.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.offAudioResume = exports.offAudioProgress = exports.offAudioPause = exports.getQueueSnapshot = exports.getCurrentAudioInfo = 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; } });
|
|
@@ -15,6 +15,19 @@ Object.defineProperty(exports, "stopCurrentAudioInChannel", { enumerable: true,
|
|
|
15
15
|
Object.defineProperty(exports, "stopAllAudioInChannel", { enumerable: true, get: function () { return core_1.stopAllAudioInChannel; } });
|
|
16
16
|
Object.defineProperty(exports, "stopAllAudio", { enumerable: true, get: function () { return core_1.stopAllAudio; } });
|
|
17
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; } });
|
|
18
31
|
// Error handling and recovery functions
|
|
19
32
|
var errors_1 = require("./errors");
|
|
20
33
|
Object.defineProperty(exports, "getErrorRecovery", { enumerable: true, get: function () { return errors_1.getErrorRecovery; } });
|
|
@@ -51,6 +64,8 @@ Object.defineProperty(exports, "setAllChannelsVolume", { enumerable: true, get:
|
|
|
51
64
|
Object.defineProperty(exports, "setChannelVolume", { enumerable: true, get: function () { return volume_1.setChannelVolume; } });
|
|
52
65
|
Object.defineProperty(exports, "setVolumeDucking", { enumerable: true, get: function () { return volume_1.setVolumeDucking; } });
|
|
53
66
|
Object.defineProperty(exports, "transitionVolume", { enumerable: true, get: function () { return volume_1.transitionVolume; } });
|
|
67
|
+
Object.defineProperty(exports, "cancelVolumeTransition", { enumerable: true, get: function () { return volume_1.cancelVolumeTransition; } });
|
|
68
|
+
Object.defineProperty(exports, "cancelAllVolumeTransitions", { enumerable: true, get: function () { return volume_1.cancelAllVolumeTransitions; } });
|
|
54
69
|
// Audio information and progress tracking functions
|
|
55
70
|
var info_1 = require("./info");
|
|
56
71
|
Object.defineProperty(exports, "getAllChannelsInfo", { enumerable: true, get: function () { return info_1.getAllChannelsInfo; } });
|
|
@@ -75,8 +90,12 @@ Object.defineProperty(exports, "cleanWebpackFilename", { enumerable: true, get:
|
|
|
75
90
|
Object.defineProperty(exports, "createQueueSnapshot", { enumerable: true, get: function () { return utils_1.createQueueSnapshot; } });
|
|
76
91
|
Object.defineProperty(exports, "extractFileName", { enumerable: true, get: function () { return utils_1.extractFileName; } });
|
|
77
92
|
Object.defineProperty(exports, "getAudioInfoFromElement", { enumerable: true, get: function () { return utils_1.getAudioInfoFromElement; } });
|
|
93
|
+
Object.defineProperty(exports, "sanitizeForDisplay", { enumerable: true, get: function () { return utils_1.sanitizeForDisplay; } });
|
|
94
|
+
Object.defineProperty(exports, "validateAudioUrl", { enumerable: true, get: function () { return utils_1.validateAudioUrl; } });
|
|
78
95
|
// Enums and constants
|
|
79
96
|
var types_1 = require("./types");
|
|
80
97
|
Object.defineProperty(exports, "EasingType", { enumerable: true, get: function () { return types_1.EasingType; } });
|
|
81
98
|
Object.defineProperty(exports, "FadeType", { enumerable: true, get: function () { return types_1.FadeType; } });
|
|
99
|
+
Object.defineProperty(exports, "MAX_CHANNELS", { enumerable: true, get: function () { return types_1.MAX_CHANNELS; } });
|
|
100
|
+
Object.defineProperty(exports, "TimerType", { enumerable: true, get: function () { return types_1.TimerType; } });
|
|
82
101
|
Object.defineProperty(exports, "GLOBAL_PROGRESS_KEY", { enumerable: true, get: function () { return types_1.GLOBAL_PROGRESS_KEY; } });
|
package/dist/info.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ import { AudioInfo, QueueSnapshot, ProgressCallback, QueueChangeCallback, AudioS
|
|
|
5
5
|
/**
|
|
6
6
|
* Global array to store audio channels with their queues and callback management
|
|
7
7
|
* Each channel maintains its own audio queue and event callback sets
|
|
8
|
+
*
|
|
9
|
+
* Note: While you can inspect this array for debugging, direct modification is discouraged.
|
|
10
|
+
* Use the provided API functions for safe channel management.
|
|
8
11
|
*/
|
|
9
12
|
export declare const audioChannels: ExtendedAudioQueueChannel[];
|
|
10
13
|
/**
|
|
@@ -37,22 +40,24 @@ export declare const getCurrentAudioInfo: (channelNumber?: number) => AudioInfo
|
|
|
37
40
|
export declare const getAllChannelsInfo: () => (AudioInfo | null)[];
|
|
38
41
|
/**
|
|
39
42
|
* Gets a complete snapshot of the queue state for a specific channel
|
|
40
|
-
* @param channelNumber - The channel number
|
|
43
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
41
44
|
* @returns QueueSnapshot object or null if channel doesn't exist
|
|
42
45
|
* @example
|
|
43
46
|
* ```typescript
|
|
44
|
-
* const snapshot = getQueueSnapshot(
|
|
47
|
+
* const snapshot = getQueueSnapshot();
|
|
45
48
|
* if (snapshot) {
|
|
46
49
|
* console.log(`Queue has ${snapshot.totalItems} items`);
|
|
47
50
|
* console.log(`Currently playing: ${snapshot.items[0]?.fileName}`);
|
|
48
51
|
* }
|
|
52
|
+
* const channelSnapshot = getQueueSnapshot(2);
|
|
49
53
|
* ```
|
|
50
54
|
*/
|
|
51
|
-
export declare const getQueueSnapshot: (channelNumber
|
|
55
|
+
export declare const getQueueSnapshot: (channelNumber?: number) => QueueSnapshot | null;
|
|
52
56
|
/**
|
|
53
57
|
* Subscribes to real-time progress updates for a specific channel
|
|
54
58
|
* @param channelNumber - The channel number
|
|
55
59
|
* @param callback - Function to call with audio info updates
|
|
60
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
56
61
|
* @example
|
|
57
62
|
* ```typescript
|
|
58
63
|
* onAudioProgress(0, (info) => {
|
|
@@ -64,17 +69,19 @@ export declare const getQueueSnapshot: (channelNumber: number) => QueueSnapshot
|
|
|
64
69
|
export declare const onAudioProgress: (channelNumber: number, callback: ProgressCallback) => void;
|
|
65
70
|
/**
|
|
66
71
|
* Removes progress listeners for a specific channel
|
|
67
|
-
* @param channelNumber - The channel number
|
|
72
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
68
73
|
* @example
|
|
69
74
|
* ```typescript
|
|
70
|
-
* offAudioProgress(
|
|
75
|
+
* offAudioProgress();
|
|
76
|
+
* offAudioProgress(1); // Stop receiving progress updates for channel 1
|
|
71
77
|
* ```
|
|
72
78
|
*/
|
|
73
|
-
export declare
|
|
79
|
+
export declare function offAudioProgress(channelNumber?: number): void;
|
|
74
80
|
/**
|
|
75
81
|
* Subscribes to queue change events for a specific channel
|
|
76
82
|
* @param channelNumber - The channel number to monitor
|
|
77
83
|
* @param callback - Function to call when queue changes
|
|
84
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
78
85
|
* @example
|
|
79
86
|
* ```typescript
|
|
80
87
|
* onQueueChange(0, (snapshot) => {
|
|
@@ -97,6 +104,7 @@ export declare const offQueueChange: (channelNumber: number) => void;
|
|
|
97
104
|
* Subscribes to audio start events for a specific channel
|
|
98
105
|
* @param channelNumber - The channel number to monitor
|
|
99
106
|
* @param callback - Function to call when audio starts playing
|
|
107
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
100
108
|
* @example
|
|
101
109
|
* ```typescript
|
|
102
110
|
* onAudioStart(0, (info) => {
|
|
@@ -110,6 +118,7 @@ export declare const onAudioStart: (channelNumber: number, callback: AudioStartC
|
|
|
110
118
|
* Subscribes to audio complete events for a specific channel
|
|
111
119
|
* @param channelNumber - The channel number to monitor
|
|
112
120
|
* @param callback - Function to call when audio completes
|
|
121
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
113
122
|
* @example
|
|
114
123
|
* ```typescript
|
|
115
124
|
* onAudioComplete(0, (info) => {
|
|
@@ -125,6 +134,7 @@ export declare const onAudioComplete: (channelNumber: number, callback: AudioCom
|
|
|
125
134
|
* Subscribes to audio pause events for a specific channel
|
|
126
135
|
* @param channelNumber - The channel number to monitor
|
|
127
136
|
* @param callback - Function to call when audio is paused
|
|
137
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
128
138
|
* @example
|
|
129
139
|
* ```typescript
|
|
130
140
|
* onAudioPause(0, (channelNumber, info) => {
|
|
@@ -138,6 +148,7 @@ export declare const onAudioPause: (channelNumber: number, callback: AudioPauseC
|
|
|
138
148
|
* Subscribes to audio resume events for a specific channel
|
|
139
149
|
* @param channelNumber - The channel number to monitor
|
|
140
150
|
* @param callback - Function to call when audio is resumed
|
|
151
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
141
152
|
* @example
|
|
142
153
|
* ```typescript
|
|
143
154
|
* onAudioResume(0, (channelNumber, info) => {
|
package/dist/info.js
CHANGED
|
@@ -3,15 +3,73 @@
|
|
|
3
3
|
* @fileoverview Audio information and progress tracking functions for the audio-channel-queue package
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.offAudioResume = exports.offAudioPause = exports.onAudioResume = exports.onAudioPause = exports.onAudioComplete = exports.onAudioStart = exports.offQueueChange = exports.onQueueChange = exports.
|
|
6
|
+
exports.offAudioResume = exports.offAudioPause = exports.onAudioResume = exports.onAudioPause = exports.onAudioComplete = exports.onAudioStart = exports.offQueueChange = exports.onQueueChange = exports.onAudioProgress = exports.getQueueSnapshot = exports.getAllChannelsInfo = exports.getCurrentAudioInfo = exports.audioChannels = void 0;
|
|
7
|
+
exports.offAudioProgress = offAudioProgress;
|
|
7
8
|
const types_1 = require("./types");
|
|
8
9
|
const utils_1 = require("./utils");
|
|
9
10
|
const events_1 = require("./events");
|
|
10
11
|
/**
|
|
11
12
|
* Global array to store audio channels with their queues and callback management
|
|
12
13
|
* Each channel maintains its own audio queue and event callback sets
|
|
14
|
+
*
|
|
15
|
+
* Note: While you can inspect this array for debugging, direct modification is discouraged.
|
|
16
|
+
* Use the provided API functions for safe channel management.
|
|
13
17
|
*/
|
|
14
|
-
exports.audioChannels = []
|
|
18
|
+
exports.audioChannels = new Proxy([], {
|
|
19
|
+
deleteProperty(target, prop) {
|
|
20
|
+
if (typeof prop === 'string' && !isNaN(Number(prop))) {
|
|
21
|
+
// eslint-disable-next-line no-console
|
|
22
|
+
console.warn('Warning: Direct deletion from audioChannels detected. ' +
|
|
23
|
+
'Consider using stopAllAudioInChannel() for proper cleanup.');
|
|
24
|
+
}
|
|
25
|
+
delete target[prop];
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
get(target, prop) {
|
|
29
|
+
const value = target[prop];
|
|
30
|
+
// Return channel objects with warnings on modification attempts
|
|
31
|
+
if (typeof value === 'object' &&
|
|
32
|
+
value !== null &&
|
|
33
|
+
typeof prop === 'string' &&
|
|
34
|
+
!isNaN(Number(prop))) {
|
|
35
|
+
return new Proxy(value, {
|
|
36
|
+
set(channelTarget, channelProp, channelValue) {
|
|
37
|
+
// Allow internal modifications but warn about direct property changes
|
|
38
|
+
if (typeof channelProp === 'string' &&
|
|
39
|
+
!['queue', 'volume', 'isPaused', 'isLocked', 'volumeConfig'].includes(channelProp)) {
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.warn(`Warning: Direct modification of channel.${channelProp} detected. ` +
|
|
42
|
+
'Use API functions for safer channel management.');
|
|
43
|
+
}
|
|
44
|
+
const key = typeof channelProp === 'symbol' ? channelProp.toString() : channelProp;
|
|
45
|
+
channelTarget[key] = channelValue;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
},
|
|
52
|
+
set(target, prop, value) {
|
|
53
|
+
// Allow normal array operations
|
|
54
|
+
const key = typeof prop === 'symbol' ? prop.toString() : prop;
|
|
55
|
+
target[key] = value;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Validates a channel number against MAX_CHANNELS limit
|
|
61
|
+
* @param channelNumber - The channel number to validate
|
|
62
|
+
* @throws Error if the channel number is invalid
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
const validateChannelNumber = (channelNumber) => {
|
|
66
|
+
if (channelNumber < 0) {
|
|
67
|
+
throw new Error('Channel number must be non-negative');
|
|
68
|
+
}
|
|
69
|
+
if (channelNumber >= types_1.MAX_CHANNELS) {
|
|
70
|
+
throw new Error(`Channel number ${channelNumber} exceeds maximum allowed channels (${types_1.MAX_CHANNELS})`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
15
73
|
/**
|
|
16
74
|
* Gets current audio information for a specific channel
|
|
17
75
|
* @param channelNumber - The channel number (defaults to 0)
|
|
@@ -57,18 +115,19 @@ const getAllChannelsInfo = () => {
|
|
|
57
115
|
exports.getAllChannelsInfo = getAllChannelsInfo;
|
|
58
116
|
/**
|
|
59
117
|
* Gets a complete snapshot of the queue state for a specific channel
|
|
60
|
-
* @param channelNumber - The channel number
|
|
118
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
61
119
|
* @returns QueueSnapshot object or null if channel doesn't exist
|
|
62
120
|
* @example
|
|
63
121
|
* ```typescript
|
|
64
|
-
* const snapshot = getQueueSnapshot(
|
|
122
|
+
* const snapshot = getQueueSnapshot();
|
|
65
123
|
* if (snapshot) {
|
|
66
124
|
* console.log(`Queue has ${snapshot.totalItems} items`);
|
|
67
125
|
* console.log(`Currently playing: ${snapshot.items[0]?.fileName}`);
|
|
68
126
|
* }
|
|
127
|
+
* const channelSnapshot = getQueueSnapshot(2);
|
|
69
128
|
* ```
|
|
70
129
|
*/
|
|
71
|
-
const getQueueSnapshot = (channelNumber) => {
|
|
130
|
+
const getQueueSnapshot = (channelNumber = 0) => {
|
|
72
131
|
return (0, utils_1.createQueueSnapshot)(channelNumber, exports.audioChannels);
|
|
73
132
|
};
|
|
74
133
|
exports.getQueueSnapshot = getQueueSnapshot;
|
|
@@ -76,6 +135,7 @@ exports.getQueueSnapshot = getQueueSnapshot;
|
|
|
76
135
|
* Subscribes to real-time progress updates for a specific channel
|
|
77
136
|
* @param channelNumber - The channel number
|
|
78
137
|
* @param callback - Function to call with audio info updates
|
|
138
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
79
139
|
* @example
|
|
80
140
|
* ```typescript
|
|
81
141
|
* onAudioProgress(0, (info) => {
|
|
@@ -85,6 +145,7 @@ exports.getQueueSnapshot = getQueueSnapshot;
|
|
|
85
145
|
* ```
|
|
86
146
|
*/
|
|
87
147
|
const onAudioProgress = (channelNumber, callback) => {
|
|
148
|
+
validateChannelNumber(channelNumber);
|
|
88
149
|
if (!exports.audioChannels[channelNumber]) {
|
|
89
150
|
exports.audioChannels[channelNumber] = {
|
|
90
151
|
audioCompleteCallbacks: new Set(),
|
|
@@ -122,13 +183,14 @@ const onAudioProgress = (channelNumber, callback) => {
|
|
|
122
183
|
exports.onAudioProgress = onAudioProgress;
|
|
123
184
|
/**
|
|
124
185
|
* Removes progress listeners for a specific channel
|
|
125
|
-
* @param channelNumber - The channel number
|
|
186
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
126
187
|
* @example
|
|
127
188
|
* ```typescript
|
|
128
|
-
* offAudioProgress(
|
|
189
|
+
* offAudioProgress();
|
|
190
|
+
* offAudioProgress(1); // Stop receiving progress updates for channel 1
|
|
129
191
|
* ```
|
|
130
192
|
*/
|
|
131
|
-
|
|
193
|
+
function offAudioProgress(channelNumber = 0) {
|
|
132
194
|
const channel = exports.audioChannels[channelNumber];
|
|
133
195
|
if (!(channel === null || channel === void 0 ? void 0 : channel.progressCallbacks))
|
|
134
196
|
return;
|
|
@@ -139,12 +201,12 @@ const offAudioProgress = (channelNumber) => {
|
|
|
139
201
|
}
|
|
140
202
|
// Clear all callbacks for this channel
|
|
141
203
|
channel.progressCallbacks.clear();
|
|
142
|
-
}
|
|
143
|
-
exports.offAudioProgress = offAudioProgress;
|
|
204
|
+
}
|
|
144
205
|
/**
|
|
145
206
|
* Subscribes to queue change events for a specific channel
|
|
146
207
|
* @param channelNumber - The channel number to monitor
|
|
147
208
|
* @param callback - Function to call when queue changes
|
|
209
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
148
210
|
* @example
|
|
149
211
|
* ```typescript
|
|
150
212
|
* onQueueChange(0, (snapshot) => {
|
|
@@ -154,6 +216,7 @@ exports.offAudioProgress = offAudioProgress;
|
|
|
154
216
|
* ```
|
|
155
217
|
*/
|
|
156
218
|
const onQueueChange = (channelNumber, callback) => {
|
|
219
|
+
validateChannelNumber(channelNumber);
|
|
157
220
|
if (!exports.audioChannels[channelNumber]) {
|
|
158
221
|
exports.audioChannels[channelNumber] = {
|
|
159
222
|
audioCompleteCallbacks: new Set(),
|
|
@@ -194,6 +257,7 @@ exports.offQueueChange = offQueueChange;
|
|
|
194
257
|
* Subscribes to audio start events for a specific channel
|
|
195
258
|
* @param channelNumber - The channel number to monitor
|
|
196
259
|
* @param callback - Function to call when audio starts playing
|
|
260
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
197
261
|
* @example
|
|
198
262
|
* ```typescript
|
|
199
263
|
* onAudioStart(0, (info) => {
|
|
@@ -203,6 +267,7 @@ exports.offQueueChange = offQueueChange;
|
|
|
203
267
|
* ```
|
|
204
268
|
*/
|
|
205
269
|
const onAudioStart = (channelNumber, callback) => {
|
|
270
|
+
validateChannelNumber(channelNumber);
|
|
206
271
|
if (!exports.audioChannels[channelNumber]) {
|
|
207
272
|
exports.audioChannels[channelNumber] = {
|
|
208
273
|
audioCompleteCallbacks: new Set(),
|
|
@@ -228,6 +293,7 @@ exports.onAudioStart = onAudioStart;
|
|
|
228
293
|
* Subscribes to audio complete events for a specific channel
|
|
229
294
|
* @param channelNumber - The channel number to monitor
|
|
230
295
|
* @param callback - Function to call when audio completes
|
|
296
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
231
297
|
* @example
|
|
232
298
|
* ```typescript
|
|
233
299
|
* onAudioComplete(0, (info) => {
|
|
@@ -239,6 +305,7 @@ exports.onAudioStart = onAudioStart;
|
|
|
239
305
|
* ```
|
|
240
306
|
*/
|
|
241
307
|
const onAudioComplete = (channelNumber, callback) => {
|
|
308
|
+
validateChannelNumber(channelNumber);
|
|
242
309
|
if (!exports.audioChannels[channelNumber]) {
|
|
243
310
|
exports.audioChannels[channelNumber] = {
|
|
244
311
|
audioCompleteCallbacks: new Set(),
|
|
@@ -264,6 +331,7 @@ exports.onAudioComplete = onAudioComplete;
|
|
|
264
331
|
* Subscribes to audio pause events for a specific channel
|
|
265
332
|
* @param channelNumber - The channel number to monitor
|
|
266
333
|
* @param callback - Function to call when audio is paused
|
|
334
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
267
335
|
* @example
|
|
268
336
|
* ```typescript
|
|
269
337
|
* onAudioPause(0, (channelNumber, info) => {
|
|
@@ -273,6 +341,7 @@ exports.onAudioComplete = onAudioComplete;
|
|
|
273
341
|
* ```
|
|
274
342
|
*/
|
|
275
343
|
const onAudioPause = (channelNumber, callback) => {
|
|
344
|
+
validateChannelNumber(channelNumber);
|
|
276
345
|
if (!exports.audioChannels[channelNumber]) {
|
|
277
346
|
exports.audioChannels[channelNumber] = {
|
|
278
347
|
audioCompleteCallbacks: new Set(),
|
|
@@ -298,6 +367,7 @@ exports.onAudioPause = onAudioPause;
|
|
|
298
367
|
* Subscribes to audio resume events for a specific channel
|
|
299
368
|
* @param channelNumber - The channel number to monitor
|
|
300
369
|
* @param callback - Function to call when audio is resumed
|
|
370
|
+
* @throws Error if the channel number exceeds the maximum allowed channels
|
|
301
371
|
* @example
|
|
302
372
|
* ```typescript
|
|
303
373
|
* onAudioResume(0, (channelNumber, info) => {
|
|
@@ -307,6 +377,7 @@ exports.onAudioPause = onAudioPause;
|
|
|
307
377
|
* ```
|
|
308
378
|
*/
|
|
309
379
|
const onAudioResume = (channelNumber, callback) => {
|
|
380
|
+
validateChannelNumber(channelNumber);
|
|
310
381
|
if (!exports.audioChannels[channelNumber]) {
|
|
311
382
|
exports.audioChannels[channelNumber] = {
|
|
312
383
|
audioCompleteCallbacks: new Set(),
|
package/dist/pause.js
CHANGED
|
@@ -77,7 +77,7 @@ const pauseWithFade = (...args_1) => __awaiter(void 0, [...args_1], void 0, func
|
|
|
77
77
|
// First fade or no transition in progress, capture current volume
|
|
78
78
|
// But ensure we don't capture a volume of 0 during a transition
|
|
79
79
|
const currentVolume = getChannelVolumeSync(channelNumber);
|
|
80
|
-
originalVolume = currentVolume > 0 ? currentVolume : (_c = (_b = channel.fadeState) === null || _b === void 0 ? void 0 : _b.originalVolume) !== null && _c !== void 0 ? _c : 1.0;
|
|
80
|
+
originalVolume = currentVolume > 0 ? currentVolume : ((_c = (_b = channel.fadeState) === null || _b === void 0 ? void 0 : _b.originalVolume) !== null && _c !== void 0 ? _c : 1.0);
|
|
81
81
|
}
|
|
82
82
|
// Store fade state for resumeWithFade to use (including custom duration)
|
|
83
83
|
channel.fadeState = {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Queue manipulation functions for the audio-channel-queue package
|
|
3
|
+
* Provides advanced queue management including item removal, reordering, and clearing
|
|
4
|
+
*/
|
|
5
|
+
import { QueueManipulationResult, QueueItem } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Removes a specific item from the queue by its slot number (0-based index)
|
|
8
|
+
* Cannot remove the currently playing item (index 0) - use stopCurrentAudioInChannel instead
|
|
9
|
+
* @param queuedSlotNumber - Zero-based index of the item to remove (must be > 0)
|
|
10
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
11
|
+
* @returns Promise resolving to operation result with success status and updated queue
|
|
12
|
+
* @throws Error if trying to remove currently playing item or invalid slot number
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Remove the second item in queue (index 1)
|
|
16
|
+
* const result = await removeQueuedItem(1, 0);
|
|
17
|
+
* if (result.success) {
|
|
18
|
+
* console.log(`Removed item, queue now has ${result.updatedQueue.totalItems} items`);
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // Remove the third item from channel 1
|
|
22
|
+
* await removeQueuedItem(2, 1);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const removeQueuedItem: (queuedSlotNumber: number, channelNumber?: number) => Promise<QueueManipulationResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Reorders a queue item by moving it from one position to another
|
|
28
|
+
* Cannot reorder the currently playing item (index 0)
|
|
29
|
+
* @param currentQueuedSlotNumber - Current zero-based index of the item to move (must be > 0)
|
|
30
|
+
* @param newQueuedSlotNumber - New zero-based index where the item should be placed (must be > 0)
|
|
31
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
32
|
+
* @returns Promise resolving to operation result with success status and updated queue
|
|
33
|
+
* @throws Error if trying to reorder currently playing item or invalid slot numbers
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Move item from position 2 to position 1 (make it play next)
|
|
37
|
+
* const result = await reorderQueue(2, 1, 0);
|
|
38
|
+
* if (result.success) {
|
|
39
|
+
* console.log('Item moved successfully');
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // Move item from position 1 to end of queue
|
|
43
|
+
* await reorderQueue(1, 4, 0); // Assuming queue has 5+ items
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const reorderQueue: (currentQueuedSlotNumber: number, newQueuedSlotNumber: number, channelNumber?: number) => Promise<QueueManipulationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Clears all queued audio items after the currently playing item
|
|
49
|
+
* The current audio will continue playing but nothing will follow it
|
|
50
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
51
|
+
* @returns Promise resolving to operation result with success status and updated queue
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // Let current song finish but clear everything after it
|
|
55
|
+
* const result = await clearQueueAfterCurrent(0);
|
|
56
|
+
* if (result.success) {
|
|
57
|
+
* console.log(`Cleared queue, current audio will be the last to play`);
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const clearQueueAfterCurrent: (channelNumber?: number) => Promise<QueueManipulationResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets information about a specific queue item by its slot number
|
|
64
|
+
* @param queueSlotNumber - Zero-based index of the queue item
|
|
65
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
66
|
+
* @returns QueueItem information or null if slot doesn't exist
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const itemInfo = getQueueItemInfo(1, 0);
|
|
70
|
+
* if (itemInfo) {
|
|
71
|
+
* console.log(`Next to play: ${itemInfo.fileName}`);
|
|
72
|
+
* console.log(`Duration: ${itemInfo.duration}ms`);
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare const getQueueItemInfo: (queueSlotNumber: number, channelNumber?: number) => QueueItem | null;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the current queue length for a specific channel
|
|
79
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
80
|
+
* @returns Number of items in the queue, or 0 if channel doesn't exist
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const queueSize = getQueueLength(0);
|
|
84
|
+
* console.log(`Channel 0 has ${queueSize} items in queue`);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare const getQueueLength: (channelNumber?: number) => number;
|
|
88
|
+
/**
|
|
89
|
+
* Swaps the positions of two queue items
|
|
90
|
+
* Cannot swap with the currently playing item (index 0)
|
|
91
|
+
* @param slotA - Zero-based index of first item to swap (must be > 0)
|
|
92
|
+
* @param slotB - Zero-based index of second item to swap (must be > 0)
|
|
93
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
94
|
+
* @returns Promise resolving to operation result with success status and updated queue
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Swap the second and third items in queue
|
|
98
|
+
* const result = await swapQueueItems(1, 2, 0);
|
|
99
|
+
* if (result.success) {
|
|
100
|
+
* console.log('Items swapped successfully');
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare const swapQueueItems: (slotA: number, slotB: number, channelNumber?: number) => Promise<QueueManipulationResult>;
|