audio-channel-queue 1.4.0 → 1.6.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 +483 -20
- package/dist/core.d.ts +71 -0
- package/dist/core.js +273 -0
- package/dist/events.d.ts +81 -0
- package/dist/events.js +210 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +77 -0
- package/dist/info.d.ts +166 -0
- package/dist/info.js +352 -0
- package/dist/pause.d.ts +87 -0
- package/dist/pause.js +186 -0
- package/dist/types.d.ts +183 -0
- package/dist/types.js +5 -0
- package/dist/utils.d.ts +58 -0
- package/dist/utils.js +126 -0
- package/dist/volume.d.ts +98 -0
- package/dist/volume.js +302 -0
- package/package.json +10 -4
- package/src/core.ts +306 -0
- package/src/events.ts +243 -0
- package/src/index.ts +104 -0
- package/src/info.ts +380 -0
- package/src/pause.ts +190 -0
- package/src/types.ts +199 -0
- package/src/utils.ts +134 -0
- package/src/volume.ts +328 -0
- package/dist/audio.d.ts +0 -10
- package/dist/audio.js +0 -66
package/dist/info.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Audio information and progress tracking functions for the audio-channel-queue package
|
|
3
|
+
*/
|
|
4
|
+
import { AudioInfo, QueueSnapshot, ProgressCallback, QueueChangeCallback, AudioStartCallback, AudioCompleteCallback, AudioPauseCallback, AudioResumeCallback, ExtendedAudioQueueChannel } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Global array of extended audio queue channels
|
|
7
|
+
*/
|
|
8
|
+
export declare const audioChannels: ExtendedAudioQueueChannel[];
|
|
9
|
+
/**
|
|
10
|
+
* Gets current audio information for a specific channel
|
|
11
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
12
|
+
* @returns AudioInfo object or null if no audio is playing
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const info = getCurrentAudioInfo(0);
|
|
16
|
+
* if (info) {
|
|
17
|
+
* console.log(`Currently playing: ${info.fileName}`);
|
|
18
|
+
* console.log(`Progress: ${(info.progress * 100).toFixed(1)}%`);
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const getCurrentAudioInfo: (channelNumber?: number) => AudioInfo | null;
|
|
23
|
+
/**
|
|
24
|
+
* Gets audio information for all channels
|
|
25
|
+
* @returns Array of AudioInfo objects (null for channels with no audio)
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const allInfo = getAllChannelsInfo();
|
|
29
|
+
* allInfo.forEach((info, channel) => {
|
|
30
|
+
* if (info) {
|
|
31
|
+
* console.log(`Channel ${channel}: ${info.fileName}`);
|
|
32
|
+
* }
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const getAllChannelsInfo: () => (AudioInfo | null)[];
|
|
37
|
+
/**
|
|
38
|
+
* Gets a complete snapshot of the queue state for a specific channel
|
|
39
|
+
* @param channelNumber - The channel number
|
|
40
|
+
* @returns QueueSnapshot object or null if channel doesn't exist
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const snapshot = getQueueSnapshot(0);
|
|
44
|
+
* if (snapshot) {
|
|
45
|
+
* console.log(`Queue has ${snapshot.totalItems} items`);
|
|
46
|
+
* console.log(`Currently playing: ${snapshot.items[0]?.fileName}`);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const getQueueSnapshot: (channelNumber: number) => QueueSnapshot | null;
|
|
51
|
+
/**
|
|
52
|
+
* Subscribes to real-time progress updates for a specific channel
|
|
53
|
+
* @param channelNumber - The channel number
|
|
54
|
+
* @param callback - Function to call with audio info updates
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* onAudioProgress(0, (info) => {
|
|
58
|
+
* updateProgressBar(info.progress);
|
|
59
|
+
* updateTimeDisplay(info.currentTime, info.duration);
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const onAudioProgress: (channelNumber: number, callback: ProgressCallback) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Removes progress listeners for a specific channel
|
|
66
|
+
* @param channelNumber - The channel number
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* offAudioProgress(0); // Stop receiving progress updates for channel 0
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const offAudioProgress: (channelNumber: number) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribes to queue change events for a specific channel
|
|
75
|
+
* @param channelNumber - The channel number to monitor
|
|
76
|
+
* @param callback - Function to call when queue changes
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* onQueueChange(0, (snapshot) => {
|
|
80
|
+
* updateQueueDisplay(snapshot.items);
|
|
81
|
+
* updateQueueCount(snapshot.totalItems);
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare const onQueueChange: (channelNumber: number, callback: QueueChangeCallback) => void;
|
|
86
|
+
/**
|
|
87
|
+
* Removes queue change listeners for a specific channel
|
|
88
|
+
* @param channelNumber - The channel number
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* offQueueChange(0); // Stop receiving queue change notifications for channel 0
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare const offQueueChange: (channelNumber: number) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribes to audio start events for a specific channel
|
|
97
|
+
* @param channelNumber - The channel number to monitor
|
|
98
|
+
* @param callback - Function to call when audio starts playing
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* onAudioStart(0, (info) => {
|
|
102
|
+
* showNowPlaying(info.fileName);
|
|
103
|
+
* setTotalDuration(info.duration);
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare const onAudioStart: (channelNumber: number, callback: AudioStartCallback) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Subscribes to audio complete events for a specific channel
|
|
110
|
+
* @param channelNumber - The channel number to monitor
|
|
111
|
+
* @param callback - Function to call when audio completes
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* onAudioComplete(0, (info) => {
|
|
115
|
+
* logPlaybackComplete(info.fileName);
|
|
116
|
+
* if (info.remainingInQueue === 0) {
|
|
117
|
+
* showQueueComplete();
|
|
118
|
+
* }
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare const onAudioComplete: (channelNumber: number, callback: AudioCompleteCallback) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Subscribes to audio pause events for a specific channel
|
|
125
|
+
* @param channelNumber - The channel number to monitor
|
|
126
|
+
* @param callback - Function to call when audio is paused
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* onAudioPause(0, (channelNumber, info) => {
|
|
130
|
+
* showPauseIndicator();
|
|
131
|
+
* logPauseEvent(info.fileName, info.currentTime);
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare const onAudioPause: (channelNumber: number, callback: AudioPauseCallback) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Subscribes to audio resume events for a specific channel
|
|
138
|
+
* @param channelNumber - The channel number to monitor
|
|
139
|
+
* @param callback - Function to call when audio is resumed
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* onAudioResume(0, (channelNumber, info) => {
|
|
143
|
+
* hidePauseIndicator();
|
|
144
|
+
* logResumeEvent(info.fileName, info.currentTime);
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare const onAudioResume: (channelNumber: number, callback: AudioResumeCallback) => void;
|
|
149
|
+
/**
|
|
150
|
+
* Removes pause event listeners for a specific channel
|
|
151
|
+
* @param channelNumber - The channel number
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* offAudioPause(0); // Stop receiving pause notifications for channel 0
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare const offAudioPause: (channelNumber: number) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Removes resume event listeners for a specific channel
|
|
160
|
+
* @param channelNumber - The channel number
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* offAudioResume(0); // Stop receiving resume notifications for channel 0
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare const offAudioResume: (channelNumber: number) => void;
|
package/dist/info.js
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Audio information and progress tracking functions for the audio-channel-queue package
|
|
4
|
+
*/
|
|
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.offAudioProgress = exports.onAudioProgress = exports.getQueueSnapshot = exports.getAllChannelsInfo = exports.getCurrentAudioInfo = exports.audioChannels = void 0;
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const events_1 = require("./events");
|
|
9
|
+
/**
|
|
10
|
+
* Global array of extended audio queue channels
|
|
11
|
+
*/
|
|
12
|
+
exports.audioChannels = [];
|
|
13
|
+
/**
|
|
14
|
+
* Gets current audio information for a specific channel
|
|
15
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
16
|
+
* @returns AudioInfo object or null if no audio is playing
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const info = getCurrentAudioInfo(0);
|
|
20
|
+
* if (info) {
|
|
21
|
+
* console.log(`Currently playing: ${info.fileName}`);
|
|
22
|
+
* console.log(`Progress: ${(info.progress * 100).toFixed(1)}%`);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const getCurrentAudioInfo = (channelNumber = 0) => {
|
|
27
|
+
const channel = exports.audioChannels[channelNumber];
|
|
28
|
+
if (!channel || channel.queue.length === 0) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const currentAudio = channel.queue[0];
|
|
32
|
+
return (0, utils_1.getAudioInfoFromElement)(currentAudio, channelNumber, exports.audioChannels);
|
|
33
|
+
};
|
|
34
|
+
exports.getCurrentAudioInfo = getCurrentAudioInfo;
|
|
35
|
+
/**
|
|
36
|
+
* Gets audio information for all channels
|
|
37
|
+
* @returns Array of AudioInfo objects (null for channels with no audio)
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const allInfo = getAllChannelsInfo();
|
|
41
|
+
* allInfo.forEach((info, channel) => {
|
|
42
|
+
* if (info) {
|
|
43
|
+
* console.log(`Channel ${channel}: ${info.fileName}`);
|
|
44
|
+
* }
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
const getAllChannelsInfo = () => {
|
|
49
|
+
const allChannelsInfo = [];
|
|
50
|
+
for (let i = 0; i < exports.audioChannels.length; i++) {
|
|
51
|
+
allChannelsInfo.push((0, exports.getCurrentAudioInfo)(i));
|
|
52
|
+
}
|
|
53
|
+
return allChannelsInfo;
|
|
54
|
+
};
|
|
55
|
+
exports.getAllChannelsInfo = getAllChannelsInfo;
|
|
56
|
+
/**
|
|
57
|
+
* Gets a complete snapshot of the queue state for a specific channel
|
|
58
|
+
* @param channelNumber - The channel number
|
|
59
|
+
* @returns QueueSnapshot object or null if channel doesn't exist
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const snapshot = getQueueSnapshot(0);
|
|
63
|
+
* if (snapshot) {
|
|
64
|
+
* console.log(`Queue has ${snapshot.totalItems} items`);
|
|
65
|
+
* console.log(`Currently playing: ${snapshot.items[0]?.fileName}`);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
const getQueueSnapshot = (channelNumber) => {
|
|
70
|
+
return (0, utils_1.createQueueSnapshot)(channelNumber, exports.audioChannels);
|
|
71
|
+
};
|
|
72
|
+
exports.getQueueSnapshot = getQueueSnapshot;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribes to real-time progress updates for a specific channel
|
|
75
|
+
* @param channelNumber - The channel number
|
|
76
|
+
* @param callback - Function to call with audio info updates
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* onAudioProgress(0, (info) => {
|
|
80
|
+
* updateProgressBar(info.progress);
|
|
81
|
+
* updateTimeDisplay(info.currentTime, info.duration);
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
const onAudioProgress = (channelNumber, callback) => {
|
|
86
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
87
|
+
exports.audioChannels[channelNumber] = {
|
|
88
|
+
audioCompleteCallbacks: new Set(),
|
|
89
|
+
audioPauseCallbacks: new Set(),
|
|
90
|
+
audioResumeCallbacks: new Set(),
|
|
91
|
+
audioStartCallbacks: new Set(),
|
|
92
|
+
isPaused: false,
|
|
93
|
+
progressCallbacks: new Map(),
|
|
94
|
+
queue: [],
|
|
95
|
+
queueChangeCallbacks: new Set(),
|
|
96
|
+
volume: 1.0
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const channel = exports.audioChannels[channelNumber];
|
|
100
|
+
if (!channel.progressCallbacks) {
|
|
101
|
+
channel.progressCallbacks = new Map();
|
|
102
|
+
}
|
|
103
|
+
// Add callback for current audio if exists
|
|
104
|
+
if (channel.queue.length > 0) {
|
|
105
|
+
const currentAudio = channel.queue[0];
|
|
106
|
+
if (!channel.progressCallbacks.has(currentAudio)) {
|
|
107
|
+
channel.progressCallbacks.set(currentAudio, new Set());
|
|
108
|
+
}
|
|
109
|
+
channel.progressCallbacks.get(currentAudio).add(callback);
|
|
110
|
+
// Set up tracking if not already done
|
|
111
|
+
(0, events_1.setupProgressTracking)(currentAudio, channelNumber, exports.audioChannels);
|
|
112
|
+
}
|
|
113
|
+
// Store callback for future audio elements in this channel
|
|
114
|
+
if (!channel.progressCallbacks.has(null)) {
|
|
115
|
+
channel.progressCallbacks.set(null, new Set());
|
|
116
|
+
}
|
|
117
|
+
channel.progressCallbacks.get(null).add(callback);
|
|
118
|
+
};
|
|
119
|
+
exports.onAudioProgress = onAudioProgress;
|
|
120
|
+
/**
|
|
121
|
+
* Removes progress listeners for a specific channel
|
|
122
|
+
* @param channelNumber - The channel number
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* offAudioProgress(0); // Stop receiving progress updates for channel 0
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
const offAudioProgress = (channelNumber) => {
|
|
129
|
+
const channel = exports.audioChannels[channelNumber];
|
|
130
|
+
if (!channel || !channel.progressCallbacks)
|
|
131
|
+
return;
|
|
132
|
+
// Clean up event listeners for current audio if exists
|
|
133
|
+
if (channel.queue.length > 0) {
|
|
134
|
+
const currentAudio = channel.queue[0];
|
|
135
|
+
(0, events_1.cleanupProgressTracking)(currentAudio, channelNumber, exports.audioChannels);
|
|
136
|
+
}
|
|
137
|
+
// Clear all callbacks for this channel
|
|
138
|
+
channel.progressCallbacks.clear();
|
|
139
|
+
};
|
|
140
|
+
exports.offAudioProgress = offAudioProgress;
|
|
141
|
+
/**
|
|
142
|
+
* Subscribes to queue change events for a specific channel
|
|
143
|
+
* @param channelNumber - The channel number to monitor
|
|
144
|
+
* @param callback - Function to call when queue changes
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* onQueueChange(0, (snapshot) => {
|
|
148
|
+
* updateQueueDisplay(snapshot.items);
|
|
149
|
+
* updateQueueCount(snapshot.totalItems);
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
const onQueueChange = (channelNumber, callback) => {
|
|
154
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
155
|
+
exports.audioChannels[channelNumber] = {
|
|
156
|
+
audioCompleteCallbacks: new Set(),
|
|
157
|
+
audioPauseCallbacks: new Set(),
|
|
158
|
+
audioResumeCallbacks: new Set(),
|
|
159
|
+
audioStartCallbacks: new Set(),
|
|
160
|
+
isPaused: false,
|
|
161
|
+
progressCallbacks: new Map(),
|
|
162
|
+
queue: [],
|
|
163
|
+
queueChangeCallbacks: new Set(),
|
|
164
|
+
volume: 1.0
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const channel = exports.audioChannels[channelNumber];
|
|
168
|
+
if (!channel.queueChangeCallbacks) {
|
|
169
|
+
channel.queueChangeCallbacks = new Set();
|
|
170
|
+
}
|
|
171
|
+
channel.queueChangeCallbacks.add(callback);
|
|
172
|
+
};
|
|
173
|
+
exports.onQueueChange = onQueueChange;
|
|
174
|
+
/**
|
|
175
|
+
* Removes queue change listeners for a specific channel
|
|
176
|
+
* @param channelNumber - The channel number
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* offQueueChange(0); // Stop receiving queue change notifications for channel 0
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
const offQueueChange = (channelNumber) => {
|
|
183
|
+
const channel = exports.audioChannels[channelNumber];
|
|
184
|
+
if (!channel || !channel.queueChangeCallbacks)
|
|
185
|
+
return;
|
|
186
|
+
channel.queueChangeCallbacks.clear();
|
|
187
|
+
};
|
|
188
|
+
exports.offQueueChange = offQueueChange;
|
|
189
|
+
/**
|
|
190
|
+
* Subscribes to audio start events for a specific channel
|
|
191
|
+
* @param channelNumber - The channel number to monitor
|
|
192
|
+
* @param callback - Function to call when audio starts playing
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* onAudioStart(0, (info) => {
|
|
196
|
+
* showNowPlaying(info.fileName);
|
|
197
|
+
* setTotalDuration(info.duration);
|
|
198
|
+
* });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
const onAudioStart = (channelNumber, callback) => {
|
|
202
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
203
|
+
exports.audioChannels[channelNumber] = {
|
|
204
|
+
audioCompleteCallbacks: new Set(),
|
|
205
|
+
audioPauseCallbacks: new Set(),
|
|
206
|
+
audioResumeCallbacks: new Set(),
|
|
207
|
+
audioStartCallbacks: new Set(),
|
|
208
|
+
isPaused: false,
|
|
209
|
+
progressCallbacks: new Map(),
|
|
210
|
+
queue: [],
|
|
211
|
+
queueChangeCallbacks: new Set(),
|
|
212
|
+
volume: 1.0
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const channel = exports.audioChannels[channelNumber];
|
|
216
|
+
if (!channel.audioStartCallbacks) {
|
|
217
|
+
channel.audioStartCallbacks = new Set();
|
|
218
|
+
}
|
|
219
|
+
channel.audioStartCallbacks.add(callback);
|
|
220
|
+
};
|
|
221
|
+
exports.onAudioStart = onAudioStart;
|
|
222
|
+
/**
|
|
223
|
+
* Subscribes to audio complete events for a specific channel
|
|
224
|
+
* @param channelNumber - The channel number to monitor
|
|
225
|
+
* @param callback - Function to call when audio completes
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* onAudioComplete(0, (info) => {
|
|
229
|
+
* logPlaybackComplete(info.fileName);
|
|
230
|
+
* if (info.remainingInQueue === 0) {
|
|
231
|
+
* showQueueComplete();
|
|
232
|
+
* }
|
|
233
|
+
* });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
const onAudioComplete = (channelNumber, callback) => {
|
|
237
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
238
|
+
exports.audioChannels[channelNumber] = {
|
|
239
|
+
audioCompleteCallbacks: new Set(),
|
|
240
|
+
audioPauseCallbacks: new Set(),
|
|
241
|
+
audioResumeCallbacks: new Set(),
|
|
242
|
+
audioStartCallbacks: new Set(),
|
|
243
|
+
isPaused: false,
|
|
244
|
+
progressCallbacks: new Map(),
|
|
245
|
+
queue: [],
|
|
246
|
+
queueChangeCallbacks: new Set(),
|
|
247
|
+
volume: 1.0
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const channel = exports.audioChannels[channelNumber];
|
|
251
|
+
if (!channel.audioCompleteCallbacks) {
|
|
252
|
+
channel.audioCompleteCallbacks = new Set();
|
|
253
|
+
}
|
|
254
|
+
channel.audioCompleteCallbacks.add(callback);
|
|
255
|
+
};
|
|
256
|
+
exports.onAudioComplete = onAudioComplete;
|
|
257
|
+
/**
|
|
258
|
+
* Subscribes to audio pause events for a specific channel
|
|
259
|
+
* @param channelNumber - The channel number to monitor
|
|
260
|
+
* @param callback - Function to call when audio is paused
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* onAudioPause(0, (channelNumber, info) => {
|
|
264
|
+
* showPauseIndicator();
|
|
265
|
+
* logPauseEvent(info.fileName, info.currentTime);
|
|
266
|
+
* });
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
const onAudioPause = (channelNumber, callback) => {
|
|
270
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
271
|
+
exports.audioChannels[channelNumber] = {
|
|
272
|
+
audioCompleteCallbacks: new Set(),
|
|
273
|
+
audioPauseCallbacks: new Set(),
|
|
274
|
+
audioResumeCallbacks: new Set(),
|
|
275
|
+
audioStartCallbacks: new Set(),
|
|
276
|
+
isPaused: false,
|
|
277
|
+
progressCallbacks: new Map(),
|
|
278
|
+
queue: [],
|
|
279
|
+
queueChangeCallbacks: new Set(),
|
|
280
|
+
volume: 1.0
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const channel = exports.audioChannels[channelNumber];
|
|
284
|
+
if (!channel.audioPauseCallbacks) {
|
|
285
|
+
channel.audioPauseCallbacks = new Set();
|
|
286
|
+
}
|
|
287
|
+
channel.audioPauseCallbacks.add(callback);
|
|
288
|
+
};
|
|
289
|
+
exports.onAudioPause = onAudioPause;
|
|
290
|
+
/**
|
|
291
|
+
* Subscribes to audio resume events for a specific channel
|
|
292
|
+
* @param channelNumber - The channel number to monitor
|
|
293
|
+
* @param callback - Function to call when audio is resumed
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* onAudioResume(0, (channelNumber, info) => {
|
|
297
|
+
* hidePauseIndicator();
|
|
298
|
+
* logResumeEvent(info.fileName, info.currentTime);
|
|
299
|
+
* });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
const onAudioResume = (channelNumber, callback) => {
|
|
303
|
+
if (!exports.audioChannels[channelNumber]) {
|
|
304
|
+
exports.audioChannels[channelNumber] = {
|
|
305
|
+
audioCompleteCallbacks: new Set(),
|
|
306
|
+
audioPauseCallbacks: new Set(),
|
|
307
|
+
audioResumeCallbacks: new Set(),
|
|
308
|
+
audioStartCallbacks: new Set(),
|
|
309
|
+
isPaused: false,
|
|
310
|
+
progressCallbacks: new Map(),
|
|
311
|
+
queue: [],
|
|
312
|
+
queueChangeCallbacks: new Set(),
|
|
313
|
+
volume: 1.0
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
const channel = exports.audioChannels[channelNumber];
|
|
317
|
+
if (!channel.audioResumeCallbacks) {
|
|
318
|
+
channel.audioResumeCallbacks = new Set();
|
|
319
|
+
}
|
|
320
|
+
channel.audioResumeCallbacks.add(callback);
|
|
321
|
+
};
|
|
322
|
+
exports.onAudioResume = onAudioResume;
|
|
323
|
+
/**
|
|
324
|
+
* Removes pause event listeners for a specific channel
|
|
325
|
+
* @param channelNumber - The channel number
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* offAudioPause(0); // Stop receiving pause notifications for channel 0
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
const offAudioPause = (channelNumber) => {
|
|
332
|
+
const channel = exports.audioChannels[channelNumber];
|
|
333
|
+
if (!channel || !channel.audioPauseCallbacks)
|
|
334
|
+
return;
|
|
335
|
+
channel.audioPauseCallbacks.clear();
|
|
336
|
+
};
|
|
337
|
+
exports.offAudioPause = offAudioPause;
|
|
338
|
+
/**
|
|
339
|
+
* Removes resume event listeners for a specific channel
|
|
340
|
+
* @param channelNumber - The channel number
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* offAudioResume(0); // Stop receiving resume notifications for channel 0
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
const offAudioResume = (channelNumber) => {
|
|
347
|
+
const channel = exports.audioChannels[channelNumber];
|
|
348
|
+
if (!channel || !channel.audioResumeCallbacks)
|
|
349
|
+
return;
|
|
350
|
+
channel.audioResumeCallbacks.clear();
|
|
351
|
+
};
|
|
352
|
+
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>;
|