audio-channel-queue 1.5.0 → 1.7.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 +323 -96
- package/dist/core.d.ts +27 -9
- package/dist/core.js +132 -29
- package/dist/errors.d.ts +137 -0
- package/dist/errors.js +461 -0
- package/dist/events.d.ts +23 -1
- package/dist/events.js +50 -2
- package/dist/index.d.ts +9 -19
- package/dist/index.js +45 -25
- package/dist/info.d.ts +47 -2
- package/dist/info.js +126 -7
- package/dist/pause.d.ts +87 -0
- package/dist/pause.js +186 -0
- package/dist/types.d.ts +113 -12
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +24 -4
- package/dist/volume.d.ts +98 -0
- package/dist/volume.js +305 -0
- package/package.json +4 -1
- package/src/core.ts +144 -27
- package/src/errors.ts +480 -0
- package/src/events.ts +242 -188
- package/src/index.ts +91 -66
- package/src/info.ts +386 -261
- package/src/pause.ts +190 -0
- package/src/types.ts +235 -126
- package/src/utils.ts +133 -108
- package/src/volume.ts +331 -0
package/dist/index.js
CHANGED
|
@@ -1,45 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* @fileoverview Main entry point for the audio-channel-queue package
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* multi-channel support, and extensive event handling capabilities.
|
|
7
|
-
*
|
|
8
|
-
* @example Basic Usage
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { queueAudio, onAudioProgress } from 'audio-channel-queue';
|
|
11
|
-
*
|
|
12
|
-
* // Queue an audio file
|
|
13
|
-
* await queueAudio('song.mp3');
|
|
14
|
-
*
|
|
15
|
-
* // Track progress
|
|
16
|
-
* onAudioProgress(0, (info) => {
|
|
17
|
-
* console.log(`Progress: ${info.progress * 100}%`);
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
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
|
|
20
6
|
*/
|
|
21
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.getAudioInfoFromElement = exports.extractFileName = exports.createQueueSnapshot = exports.cleanWebpackFilename = exports.
|
|
23
|
-
//
|
|
8
|
+
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 = exports.getAllChannelsInfo = exports.setVolumeDucking = exports.setChannelVolume = exports.setAllChannelsVolume = exports.getChannelVolume = exports.getAllChannelsVolume = exports.clearVolumeDucking = exports.togglePauseChannel = exports.togglePauseAllChannels = exports.resumeChannel = exports.resumeAllChannels = exports.pauseChannel = 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
|
+
// Core queue management functions
|
|
24
10
|
var core_1 = require("./core");
|
|
25
|
-
Object.defineProperty(exports, "playAudioQueue", { enumerable: true, get: function () { return core_1.playAudioQueue; } });
|
|
26
11
|
Object.defineProperty(exports, "queueAudio", { enumerable: true, get: function () { return core_1.queueAudio; } });
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
Object.defineProperty(exports, "stopAllAudioInChannel", { enumerable: true, get: function () { return core_1.stopAllAudioInChannel; } });
|
|
12
|
+
Object.defineProperty(exports, "queueAudioPriority", { enumerable: true, get: function () { return core_1.queueAudioPriority; } });
|
|
29
13
|
Object.defineProperty(exports, "stopCurrentAudioInChannel", { enumerable: true, get: function () { return core_1.stopCurrentAudioInChannel; } });
|
|
30
|
-
|
|
14
|
+
Object.defineProperty(exports, "stopAllAudioInChannel", { enumerable: true, get: function () { return core_1.stopAllAudioInChannel; } });
|
|
15
|
+
Object.defineProperty(exports, "stopAllAudio", { enumerable: true, get: function () { return core_1.stopAllAudio; } });
|
|
16
|
+
Object.defineProperty(exports, "playAudioQueue", { enumerable: true, get: function () { return core_1.playAudioQueue; } });
|
|
17
|
+
// Error handling and recovery functions
|
|
18
|
+
var errors_1 = require("./errors");
|
|
19
|
+
Object.defineProperty(exports, "getErrorRecovery", { enumerable: true, get: function () { return errors_1.getErrorRecovery; } });
|
|
20
|
+
Object.defineProperty(exports, "getRetryConfig", { enumerable: true, get: function () { return errors_1.getRetryConfig; } });
|
|
21
|
+
Object.defineProperty(exports, "offAudioError", { enumerable: true, get: function () { return errors_1.offAudioError; } });
|
|
22
|
+
Object.defineProperty(exports, "onAudioError", { enumerable: true, get: function () { return errors_1.onAudioError; } });
|
|
23
|
+
Object.defineProperty(exports, "retryFailedAudio", { enumerable: true, get: function () { return errors_1.retryFailedAudio; } });
|
|
24
|
+
Object.defineProperty(exports, "setErrorRecovery", { enumerable: true, get: function () { return errors_1.setErrorRecovery; } });
|
|
25
|
+
Object.defineProperty(exports, "setRetryConfig", { enumerable: true, get: function () { return errors_1.setRetryConfig; } });
|
|
26
|
+
// Pause and resume management functions
|
|
27
|
+
var pause_1 = require("./pause");
|
|
28
|
+
Object.defineProperty(exports, "getAllChannelsPauseState", { enumerable: true, get: function () { return pause_1.getAllChannelsPauseState; } });
|
|
29
|
+
Object.defineProperty(exports, "isChannelPaused", { enumerable: true, get: function () { return pause_1.isChannelPaused; } });
|
|
30
|
+
Object.defineProperty(exports, "pauseAllChannels", { enumerable: true, get: function () { return pause_1.pauseAllChannels; } });
|
|
31
|
+
Object.defineProperty(exports, "pauseChannel", { enumerable: true, get: function () { return pause_1.pauseChannel; } });
|
|
32
|
+
Object.defineProperty(exports, "resumeAllChannels", { enumerable: true, get: function () { return pause_1.resumeAllChannels; } });
|
|
33
|
+
Object.defineProperty(exports, "resumeChannel", { enumerable: true, get: function () { return pause_1.resumeChannel; } });
|
|
34
|
+
Object.defineProperty(exports, "togglePauseAllChannels", { enumerable: true, get: function () { return pause_1.togglePauseAllChannels; } });
|
|
35
|
+
Object.defineProperty(exports, "togglePauseChannel", { enumerable: true, get: function () { return pause_1.togglePauseChannel; } });
|
|
36
|
+
// Volume control and ducking functions
|
|
37
|
+
var volume_1 = require("./volume");
|
|
38
|
+
Object.defineProperty(exports, "clearVolumeDucking", { enumerable: true, get: function () { return volume_1.clearVolumeDucking; } });
|
|
39
|
+
Object.defineProperty(exports, "getAllChannelsVolume", { enumerable: true, get: function () { return volume_1.getAllChannelsVolume; } });
|
|
40
|
+
Object.defineProperty(exports, "getChannelVolume", { enumerable: true, get: function () { return volume_1.getChannelVolume; } });
|
|
41
|
+
Object.defineProperty(exports, "setAllChannelsVolume", { enumerable: true, get: function () { return volume_1.setAllChannelsVolume; } });
|
|
42
|
+
Object.defineProperty(exports, "setChannelVolume", { enumerable: true, get: function () { return volume_1.setChannelVolume; } });
|
|
43
|
+
Object.defineProperty(exports, "setVolumeDucking", { enumerable: true, get: function () { return volume_1.setVolumeDucking; } });
|
|
44
|
+
// Audio information and progress tracking functions
|
|
31
45
|
var info_1 = require("./info");
|
|
32
|
-
Object.defineProperty(exports, "audioChannels", { enumerable: true, get: function () { return info_1.audioChannels; } });
|
|
33
46
|
Object.defineProperty(exports, "getAllChannelsInfo", { enumerable: true, get: function () { return info_1.getAllChannelsInfo; } });
|
|
34
47
|
Object.defineProperty(exports, "getCurrentAudioInfo", { enumerable: true, get: function () { return info_1.getCurrentAudioInfo; } });
|
|
35
48
|
Object.defineProperty(exports, "getQueueSnapshot", { enumerable: true, get: function () { return info_1.getQueueSnapshot; } });
|
|
49
|
+
Object.defineProperty(exports, "offAudioPause", { enumerable: true, get: function () { return info_1.offAudioPause; } });
|
|
36
50
|
Object.defineProperty(exports, "offAudioProgress", { enumerable: true, get: function () { return info_1.offAudioProgress; } });
|
|
51
|
+
Object.defineProperty(exports, "offAudioResume", { enumerable: true, get: function () { return info_1.offAudioResume; } });
|
|
52
|
+
Object.defineProperty(exports, "offQueueChange", { enumerable: true, get: function () { return info_1.offQueueChange; } });
|
|
37
53
|
Object.defineProperty(exports, "onAudioComplete", { enumerable: true, get: function () { return info_1.onAudioComplete; } });
|
|
54
|
+
Object.defineProperty(exports, "onAudioPause", { enumerable: true, get: function () { return info_1.onAudioPause; } });
|
|
38
55
|
Object.defineProperty(exports, "onAudioProgress", { enumerable: true, get: function () { return info_1.onAudioProgress; } });
|
|
56
|
+
Object.defineProperty(exports, "onAudioResume", { enumerable: true, get: function () { return info_1.onAudioResume; } });
|
|
39
57
|
Object.defineProperty(exports, "onAudioStart", { enumerable: true, get: function () { return info_1.onAudioStart; } });
|
|
40
58
|
Object.defineProperty(exports, "onQueueChange", { enumerable: true, get: function () { return info_1.onQueueChange; } });
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
// Core data access for legacy compatibility
|
|
60
|
+
var info_2 = require("./info");
|
|
61
|
+
Object.defineProperty(exports, "audioChannels", { enumerable: true, get: function () { return info_2.audioChannels; } });
|
|
62
|
+
// Utility helper functions
|
|
43
63
|
var utils_1 = require("./utils");
|
|
44
64
|
Object.defineProperty(exports, "cleanWebpackFilename", { enumerable: true, get: function () { return utils_1.cleanWebpackFilename; } });
|
|
45
65
|
Object.defineProperty(exports, "createQueueSnapshot", { enumerable: true, get: function () { return utils_1.createQueueSnapshot; } });
|
package/dist/info.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Audio information and progress tracking functions for the audio-channel-queue package
|
|
3
3
|
*/
|
|
4
|
-
import { AudioInfo, QueueSnapshot, ProgressCallback, QueueChangeCallback, AudioStartCallback, AudioCompleteCallback, ExtendedAudioQueueChannel } from './types';
|
|
4
|
+
import { AudioInfo, QueueSnapshot, ProgressCallback, QueueChangeCallback, AudioStartCallback, AudioCompleteCallback, AudioPauseCallback, AudioResumeCallback, ExtendedAudioQueueChannel } from './types';
|
|
5
5
|
/**
|
|
6
|
-
* Global array
|
|
6
|
+
* Global array to store audio channels with their queues and callback management
|
|
7
|
+
* Each channel maintains its own audio queue and event callback sets
|
|
7
8
|
*/
|
|
8
9
|
export declare const audioChannels: ExtendedAudioQueueChannel[];
|
|
9
10
|
/**
|
|
@@ -120,3 +121,47 @@ export declare const onAudioStart: (channelNumber: number, callback: AudioStartC
|
|
|
120
121
|
* ```
|
|
121
122
|
*/
|
|
122
123
|
export declare const onAudioComplete: (channelNumber: number, callback: AudioCompleteCallback) => void;
|
|
124
|
+
/**
|
|
125
|
+
* Subscribes to audio pause events for a specific channel
|
|
126
|
+
* @param channelNumber - The channel number to monitor
|
|
127
|
+
* @param callback - Function to call when audio is paused
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* onAudioPause(0, (channelNumber, info) => {
|
|
131
|
+
* showPauseIndicator();
|
|
132
|
+
* logPauseEvent(info.fileName, info.currentTime);
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare const onAudioPause: (channelNumber: number, callback: AudioPauseCallback) => void;
|
|
137
|
+
/**
|
|
138
|
+
* Subscribes to audio resume events for a specific channel
|
|
139
|
+
* @param channelNumber - The channel number to monitor
|
|
140
|
+
* @param callback - Function to call when audio is resumed
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* onAudioResume(0, (channelNumber, info) => {
|
|
144
|
+
* hidePauseIndicator();
|
|
145
|
+
* logResumeEvent(info.fileName, info.currentTime);
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare const onAudioResume: (channelNumber: number, callback: AudioResumeCallback) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Removes pause event listeners for a specific channel
|
|
152
|
+
* @param channelNumber - The channel number
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* offAudioPause(0); // Stop receiving pause notifications for channel 0
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare const offAudioPause: (channelNumber: number) => void;
|
|
159
|
+
/**
|
|
160
|
+
* Removes resume event listeners for a specific channel
|
|
161
|
+
* @param channelNumber - The channel number
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* offAudioResume(0); // Stop receiving resume notifications for channel 0
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare const offAudioResume: (channelNumber: number) => void;
|
package/dist/info.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
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.onAudioComplete = exports.onAudioStart = exports.offQueueChange = exports.onQueueChange = exports.offAudioProgress = exports.onAudioProgress = exports.getQueueSnapshot = exports.getAllChannelsInfo = exports.getCurrentAudioInfo = exports.audioChannels = void 0;
|
|
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
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const events_1 = require("./events");
|
|
9
9
|
/**
|
|
10
|
-
* Global array
|
|
10
|
+
* Global array to store audio channels with their queues and callback management
|
|
11
|
+
* Each channel maintains its own audio queue and event callback sets
|
|
11
12
|
*/
|
|
12
13
|
exports.audioChannels = [];
|
|
13
14
|
/**
|
|
@@ -29,7 +30,7 @@ const getCurrentAudioInfo = (channelNumber = 0) => {
|
|
|
29
30
|
return null;
|
|
30
31
|
}
|
|
31
32
|
const currentAudio = channel.queue[0];
|
|
32
|
-
return (0, utils_1.getAudioInfoFromElement)(currentAudio);
|
|
33
|
+
return (0, utils_1.getAudioInfoFromElement)(currentAudio, channelNumber, exports.audioChannels);
|
|
33
34
|
};
|
|
34
35
|
exports.getCurrentAudioInfo = getCurrentAudioInfo;
|
|
35
36
|
/**
|
|
@@ -86,10 +87,15 @@ const onAudioProgress = (channelNumber, callback) => {
|
|
|
86
87
|
if (!exports.audioChannels[channelNumber]) {
|
|
87
88
|
exports.audioChannels[channelNumber] = {
|
|
88
89
|
audioCompleteCallbacks: new Set(),
|
|
90
|
+
audioErrorCallbacks: new Set(),
|
|
91
|
+
audioPauseCallbacks: new Set(),
|
|
92
|
+
audioResumeCallbacks: new Set(),
|
|
89
93
|
audioStartCallbacks: new Set(),
|
|
94
|
+
isPaused: false,
|
|
90
95
|
progressCallbacks: new Map(),
|
|
91
96
|
queue: [],
|
|
92
|
-
queueChangeCallbacks: new Set()
|
|
97
|
+
queueChangeCallbacks: new Set(),
|
|
98
|
+
volume: 1.0
|
|
93
99
|
};
|
|
94
100
|
}
|
|
95
101
|
const channel = exports.audioChannels[channelNumber];
|
|
@@ -150,10 +156,15 @@ const onQueueChange = (channelNumber, callback) => {
|
|
|
150
156
|
if (!exports.audioChannels[channelNumber]) {
|
|
151
157
|
exports.audioChannels[channelNumber] = {
|
|
152
158
|
audioCompleteCallbacks: new Set(),
|
|
159
|
+
audioErrorCallbacks: new Set(),
|
|
160
|
+
audioPauseCallbacks: new Set(),
|
|
161
|
+
audioResumeCallbacks: new Set(),
|
|
153
162
|
audioStartCallbacks: new Set(),
|
|
163
|
+
isPaused: false,
|
|
154
164
|
progressCallbacks: new Map(),
|
|
155
165
|
queue: [],
|
|
156
|
-
queueChangeCallbacks: new Set()
|
|
166
|
+
queueChangeCallbacks: new Set(),
|
|
167
|
+
volume: 1.0
|
|
157
168
|
};
|
|
158
169
|
}
|
|
159
170
|
const channel = exports.audioChannels[channelNumber];
|
|
@@ -194,10 +205,15 @@ const onAudioStart = (channelNumber, callback) => {
|
|
|
194
205
|
if (!exports.audioChannels[channelNumber]) {
|
|
195
206
|
exports.audioChannels[channelNumber] = {
|
|
196
207
|
audioCompleteCallbacks: new Set(),
|
|
208
|
+
audioErrorCallbacks: new Set(),
|
|
209
|
+
audioPauseCallbacks: new Set(),
|
|
210
|
+
audioResumeCallbacks: new Set(),
|
|
197
211
|
audioStartCallbacks: new Set(),
|
|
212
|
+
isPaused: false,
|
|
198
213
|
progressCallbacks: new Map(),
|
|
199
214
|
queue: [],
|
|
200
|
-
queueChangeCallbacks: new Set()
|
|
215
|
+
queueChangeCallbacks: new Set(),
|
|
216
|
+
volume: 1.0
|
|
201
217
|
};
|
|
202
218
|
}
|
|
203
219
|
const channel = exports.audioChannels[channelNumber];
|
|
@@ -225,10 +241,15 @@ const onAudioComplete = (channelNumber, callback) => {
|
|
|
225
241
|
if (!exports.audioChannels[channelNumber]) {
|
|
226
242
|
exports.audioChannels[channelNumber] = {
|
|
227
243
|
audioCompleteCallbacks: new Set(),
|
|
244
|
+
audioErrorCallbacks: new Set(),
|
|
245
|
+
audioPauseCallbacks: new Set(),
|
|
246
|
+
audioResumeCallbacks: new Set(),
|
|
228
247
|
audioStartCallbacks: new Set(),
|
|
248
|
+
isPaused: false,
|
|
229
249
|
progressCallbacks: new Map(),
|
|
230
250
|
queue: [],
|
|
231
|
-
queueChangeCallbacks: new Set()
|
|
251
|
+
queueChangeCallbacks: new Set(),
|
|
252
|
+
volume: 1.0
|
|
232
253
|
};
|
|
233
254
|
}
|
|
234
255
|
const channel = exports.audioChannels[channelNumber];
|
|
@@ -238,3 +259,101 @@ const onAudioComplete = (channelNumber, callback) => {
|
|
|
238
259
|
channel.audioCompleteCallbacks.add(callback);
|
|
239
260
|
};
|
|
240
261
|
exports.onAudioComplete = onAudioComplete;
|
|
262
|
+
/**
|
|
263
|
+
* Subscribes to audio pause events for a specific channel
|
|
264
|
+
* @param channelNumber - The channel number to monitor
|
|
265
|
+
* @param callback - Function to call when audio is paused
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* onAudioPause(0, (channelNumber, info) => {
|
|
269
|
+
* showPauseIndicator();
|
|
270
|
+
* logPauseEvent(info.fileName, info.currentTime);
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
const onAudioPause = (channelNumber, callback) => {
|
|
275
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
276
|
+
exports.audioChannels[channelNumber] = {
|
|
277
|
+
audioCompleteCallbacks: new Set(),
|
|
278
|
+
audioErrorCallbacks: new Set(),
|
|
279
|
+
audioPauseCallbacks: new Set(),
|
|
280
|
+
audioResumeCallbacks: new Set(),
|
|
281
|
+
audioStartCallbacks: new Set(),
|
|
282
|
+
isPaused: false,
|
|
283
|
+
progressCallbacks: new Map(),
|
|
284
|
+
queue: [],
|
|
285
|
+
queueChangeCallbacks: new Set(),
|
|
286
|
+
volume: 1.0
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const channel = exports.audioChannels[channelNumber];
|
|
290
|
+
if (!channel.audioPauseCallbacks) {
|
|
291
|
+
channel.audioPauseCallbacks = new Set();
|
|
292
|
+
}
|
|
293
|
+
channel.audioPauseCallbacks.add(callback);
|
|
294
|
+
};
|
|
295
|
+
exports.onAudioPause = onAudioPause;
|
|
296
|
+
/**
|
|
297
|
+
* Subscribes to audio resume events for a specific channel
|
|
298
|
+
* @param channelNumber - The channel number to monitor
|
|
299
|
+
* @param callback - Function to call when audio is resumed
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* onAudioResume(0, (channelNumber, info) => {
|
|
303
|
+
* hidePauseIndicator();
|
|
304
|
+
* logResumeEvent(info.fileName, info.currentTime);
|
|
305
|
+
* });
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
const onAudioResume = (channelNumber, callback) => {
|
|
309
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
310
|
+
exports.audioChannels[channelNumber] = {
|
|
311
|
+
audioCompleteCallbacks: new Set(),
|
|
312
|
+
audioErrorCallbacks: new Set(),
|
|
313
|
+
audioPauseCallbacks: new Set(),
|
|
314
|
+
audioResumeCallbacks: new Set(),
|
|
315
|
+
audioStartCallbacks: new Set(),
|
|
316
|
+
isPaused: false,
|
|
317
|
+
progressCallbacks: new Map(),
|
|
318
|
+
queue: [],
|
|
319
|
+
queueChangeCallbacks: new Set(),
|
|
320
|
+
volume: 1.0
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
const channel = exports.audioChannels[channelNumber];
|
|
324
|
+
if (!channel.audioResumeCallbacks) {
|
|
325
|
+
channel.audioResumeCallbacks = new Set();
|
|
326
|
+
}
|
|
327
|
+
channel.audioResumeCallbacks.add(callback);
|
|
328
|
+
};
|
|
329
|
+
exports.onAudioResume = onAudioResume;
|
|
330
|
+
/**
|
|
331
|
+
* Removes pause event listeners for a specific channel
|
|
332
|
+
* @param channelNumber - The channel number
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* offAudioPause(0); // Stop receiving pause notifications for channel 0
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
const offAudioPause = (channelNumber) => {
|
|
339
|
+
const channel = exports.audioChannels[channelNumber];
|
|
340
|
+
if (!channel || !channel.audioPauseCallbacks)
|
|
341
|
+
return;
|
|
342
|
+
channel.audioPauseCallbacks.clear();
|
|
343
|
+
};
|
|
344
|
+
exports.offAudioPause = offAudioPause;
|
|
345
|
+
/**
|
|
346
|
+
* Removes resume event listeners for a specific channel
|
|
347
|
+
* @param channelNumber - The channel number
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* offAudioResume(0); // Stop receiving resume notifications for channel 0
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
const offAudioResume = (channelNumber) => {
|
|
354
|
+
const channel = exports.audioChannels[channelNumber];
|
|
355
|
+
if (!channel || !channel.audioResumeCallbacks)
|
|
356
|
+
return;
|
|
357
|
+
channel.audioResumeCallbacks.clear();
|
|
358
|
+
};
|
|
359
|
+
exports.offAudioResume = offAudioResume;
|
package/dist/pause.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pause and resume management functions for the audio-channel-queue package
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Pauses the currently playing audio in a specific channel
|
|
6
|
+
* @param channelNumber - The channel number to pause (defaults to 0)
|
|
7
|
+
* @returns Promise that resolves when the audio is paused
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* await pauseChannel(0); // Pause audio in channel 0
|
|
11
|
+
* await pauseChannel(); // Pause audio in default channel
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const pauseChannel: (channelNumber?: number) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Resumes the currently paused audio in a specific channel
|
|
17
|
+
* @param channelNumber - The channel number to resume (defaults to 0)
|
|
18
|
+
* @returns Promise that resolves when the audio starts playing
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* await resumeChannel(0); // Resume audio in channel 0
|
|
22
|
+
* await resumeChannel(); // Resume audio in default channel
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const resumeChannel: (channelNumber?: number) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Toggles pause/resume state for a specific channel
|
|
28
|
+
* @param channelNumber - The channel number to toggle (defaults to 0)
|
|
29
|
+
* @returns Promise that resolves when the toggle is complete
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* await togglePauseChannel(0); // Toggle pause state for channel 0
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const togglePauseChannel: (channelNumber?: number) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Pauses all currently playing audio across all channels
|
|
38
|
+
* @returns Promise that resolves when all audio is paused
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* await pauseAllChannels(); // Pause everything
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const pauseAllChannels: () => Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Resumes all currently paused audio across all channels
|
|
47
|
+
* @returns Promise that resolves when all audio is resumed
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* await resumeAllChannels(); // Resume everything that was paused
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare const resumeAllChannels: () => Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a specific channel is currently paused
|
|
56
|
+
* @param channelNumber - The channel number to check (defaults to 0)
|
|
57
|
+
* @returns True if the channel is paused, false otherwise
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const isPaused = isChannelPaused(0);
|
|
61
|
+
* console.log(`Channel 0 is ${isPaused ? 'paused' : 'playing'}`);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const isChannelPaused: (channelNumber?: number) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the pause state of all channels
|
|
67
|
+
* @returns Array of boolean values indicating pause state for each channel
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const pauseStates = getAllChannelsPauseState();
|
|
71
|
+
* pauseStates.forEach((isPaused, index) => {
|
|
72
|
+
* console.log(`Channel ${index}: ${isPaused ? 'paused' : 'playing'}`);
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare const getAllChannelsPauseState: () => boolean[];
|
|
77
|
+
/**
|
|
78
|
+
* Toggles pause/resume state for all channels globally
|
|
79
|
+
* If any channels are currently playing, all channels will be paused
|
|
80
|
+
* If all channels are paused, all channels will be resumed
|
|
81
|
+
* @returns Promise that resolves when the toggle is complete
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* await togglePauseAllChannels(); // Pause all if any are playing, resume all if all are paused
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare const togglePauseAllChannels: () => Promise<void>;
|
package/dist/pause.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Pause and resume management functions for the audio-channel-queue package
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.togglePauseAllChannels = exports.getAllChannelsPauseState = exports.isChannelPaused = exports.resumeAllChannels = exports.pauseAllChannels = exports.togglePauseChannel = exports.resumeChannel = exports.pauseChannel = void 0;
|
|
16
|
+
const info_1 = require("./info");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
const events_1 = require("./events");
|
|
19
|
+
/**
|
|
20
|
+
* Pauses the currently playing audio in a specific channel
|
|
21
|
+
* @param channelNumber - The channel number to pause (defaults to 0)
|
|
22
|
+
* @returns Promise that resolves when the audio is paused
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* await pauseChannel(0); // Pause audio in channel 0
|
|
26
|
+
* await pauseChannel(); // Pause audio in default channel
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const pauseChannel = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (channelNumber = 0) {
|
|
30
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
31
|
+
if (channel && channel.queue.length > 0) {
|
|
32
|
+
const currentAudio = channel.queue[0];
|
|
33
|
+
if (!currentAudio.paused && !currentAudio.ended) {
|
|
34
|
+
currentAudio.pause();
|
|
35
|
+
channel.isPaused = true;
|
|
36
|
+
const audioInfo = (0, utils_1.getAudioInfoFromElement)(currentAudio, channelNumber, info_1.audioChannels);
|
|
37
|
+
if (audioInfo) {
|
|
38
|
+
(0, events_1.emitAudioPause)(channelNumber, audioInfo, info_1.audioChannels);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
exports.pauseChannel = pauseChannel;
|
|
44
|
+
/**
|
|
45
|
+
* Resumes the currently paused audio in a specific channel
|
|
46
|
+
* @param channelNumber - The channel number to resume (defaults to 0)
|
|
47
|
+
* @returns Promise that resolves when the audio starts playing
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* await resumeChannel(0); // Resume audio in channel 0
|
|
51
|
+
* await resumeChannel(); // Resume audio in default channel
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
const resumeChannel = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (channelNumber = 0) {
|
|
55
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
56
|
+
if (channel && channel.queue.length > 0) {
|
|
57
|
+
const currentAudio = channel.queue[0];
|
|
58
|
+
// Only resume if both the channel is marked as paused AND the audio element is actually paused AND not ended
|
|
59
|
+
if (channel.isPaused && currentAudio.paused && !currentAudio.ended) {
|
|
60
|
+
yield currentAudio.play();
|
|
61
|
+
channel.isPaused = false;
|
|
62
|
+
const audioInfo = (0, utils_1.getAudioInfoFromElement)(currentAudio, channelNumber, info_1.audioChannels);
|
|
63
|
+
if (audioInfo) {
|
|
64
|
+
(0, events_1.emitAudioResume)(channelNumber, audioInfo, info_1.audioChannels);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
exports.resumeChannel = resumeChannel;
|
|
70
|
+
/**
|
|
71
|
+
* Toggles pause/resume state for a specific channel
|
|
72
|
+
* @param channelNumber - The channel number to toggle (defaults to 0)
|
|
73
|
+
* @returns Promise that resolves when the toggle is complete
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* await togglePauseChannel(0); // Toggle pause state for channel 0
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
const togglePauseChannel = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (channelNumber = 0) {
|
|
80
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
81
|
+
if (channel && channel.queue.length > 0) {
|
|
82
|
+
const currentAudio = channel.queue[0];
|
|
83
|
+
if (currentAudio.paused) {
|
|
84
|
+
yield (0, exports.resumeChannel)(channelNumber);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
yield (0, exports.pauseChannel)(channelNumber);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
exports.togglePauseChannel = togglePauseChannel;
|
|
92
|
+
/**
|
|
93
|
+
* Pauses all currently playing audio across all channels
|
|
94
|
+
* @returns Promise that resolves when all audio is paused
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* await pauseAllChannels(); // Pause everything
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
const pauseAllChannels = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
const pausePromises = [];
|
|
102
|
+
info_1.audioChannels.forEach((_channel, index) => {
|
|
103
|
+
pausePromises.push((0, exports.pauseChannel)(index));
|
|
104
|
+
});
|
|
105
|
+
yield Promise.all(pausePromises);
|
|
106
|
+
});
|
|
107
|
+
exports.pauseAllChannels = pauseAllChannels;
|
|
108
|
+
/**
|
|
109
|
+
* Resumes all currently paused audio across all channels
|
|
110
|
+
* @returns Promise that resolves when all audio is resumed
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* await resumeAllChannels(); // Resume everything that was paused
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
const resumeAllChannels = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const resumePromises = [];
|
|
118
|
+
info_1.audioChannels.forEach((_channel, index) => {
|
|
119
|
+
resumePromises.push((0, exports.resumeChannel)(index));
|
|
120
|
+
});
|
|
121
|
+
yield Promise.all(resumePromises);
|
|
122
|
+
});
|
|
123
|
+
exports.resumeAllChannels = resumeAllChannels;
|
|
124
|
+
/**
|
|
125
|
+
* Checks if a specific channel is currently paused
|
|
126
|
+
* @param channelNumber - The channel number to check (defaults to 0)
|
|
127
|
+
* @returns True if the channel is paused, false otherwise
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const isPaused = isChannelPaused(0);
|
|
131
|
+
* console.log(`Channel 0 is ${isPaused ? 'paused' : 'playing'}`);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
const isChannelPaused = (channelNumber = 0) => {
|
|
135
|
+
const channel = info_1.audioChannels[channelNumber];
|
|
136
|
+
return (channel === null || channel === void 0 ? void 0 : channel.isPaused) || false;
|
|
137
|
+
};
|
|
138
|
+
exports.isChannelPaused = isChannelPaused;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the pause state of all channels
|
|
141
|
+
* @returns Array of boolean values indicating pause state for each channel
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const pauseStates = getAllChannelsPauseState();
|
|
145
|
+
* pauseStates.forEach((isPaused, index) => {
|
|
146
|
+
* console.log(`Channel ${index}: ${isPaused ? 'paused' : 'playing'}`);
|
|
147
|
+
* });
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
const getAllChannelsPauseState = () => {
|
|
151
|
+
return info_1.audioChannels.map((channel) => (channel === null || channel === void 0 ? void 0 : channel.isPaused) || false);
|
|
152
|
+
};
|
|
153
|
+
exports.getAllChannelsPauseState = getAllChannelsPauseState;
|
|
154
|
+
/**
|
|
155
|
+
* Toggles pause/resume state for all channels globally
|
|
156
|
+
* If any channels are currently playing, all channels will be paused
|
|
157
|
+
* If all channels are paused, all channels will be resumed
|
|
158
|
+
* @returns Promise that resolves when the toggle is complete
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* await togglePauseAllChannels(); // Pause all if any are playing, resume all if all are paused
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
const togglePauseAllChannels = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
let hasPlayingChannel = false;
|
|
166
|
+
// Check if any channel is currently playing
|
|
167
|
+
for (let i = 0; i < info_1.audioChannels.length; i++) {
|
|
168
|
+
const channel = info_1.audioChannels[i];
|
|
169
|
+
if (channel && channel.queue.length > 0) {
|
|
170
|
+
const currentAudio = channel.queue[0];
|
|
171
|
+
if (!currentAudio.paused && !currentAudio.ended) {
|
|
172
|
+
hasPlayingChannel = true;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// If any channel is playing, pause all channels
|
|
178
|
+
// If no channels are playing, resume all channels
|
|
179
|
+
if (hasPlayingChannel) {
|
|
180
|
+
yield (0, exports.pauseAllChannels)();
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
yield (0, exports.resumeAllChannels)();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
exports.togglePauseAllChannels = togglePauseAllChannels;
|