audio-channel-queue 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +4 -3
- package/dist/errors.js +27 -17
- package/dist/events.js +21 -14
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -2
- package/dist/info.js +8 -7
- package/dist/pause.d.ts +24 -12
- package/dist/pause.js +93 -41
- package/dist/types.d.ts +12 -3
- package/dist/types.js +6 -1
- package/dist/utils.js +4 -3
- package/dist/volume.js +37 -15
- package/package.json +8 -3
- package/src/core.ts +59 -42
- package/src/errors.ts +504 -480
- package/src/events.ts +36 -27
- package/src/index.ts +47 -43
- package/src/info.ts +23 -22
- package/src/pause.ts +168 -85
- package/src/types.ts +12 -2
- package/src/utils.ts +7 -7
- package/src/volume.ts +47 -30
package/src/events.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* @fileoverview Event handling and emission for the audio-channel-queue package
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
AudioStartInfo,
|
|
7
|
-
AudioCompleteInfo,
|
|
5
|
+
import {
|
|
6
|
+
AudioStartInfo,
|
|
7
|
+
AudioCompleteInfo,
|
|
8
8
|
ExtendedAudioQueueChannel,
|
|
9
9
|
QueueSnapshot,
|
|
10
10
|
ProgressCallback,
|
|
11
11
|
AudioInfo,
|
|
12
|
+
GLOBAL_PROGRESS_KEY
|
|
12
13
|
} from './types';
|
|
13
14
|
import { createQueueSnapshot, getAudioInfoFromElement } from './utils';
|
|
14
15
|
|
|
@@ -22,19 +23,20 @@ import { createQueueSnapshot, getAudioInfoFromElement } from './utils';
|
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
25
|
export const emitQueueChange = (
|
|
25
|
-
channelNumber: number,
|
|
26
|
+
channelNumber: number,
|
|
26
27
|
audioChannels: ExtendedAudioQueueChannel[]
|
|
27
28
|
): void => {
|
|
28
29
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
29
|
-
if (!channel
|
|
30
|
+
if (!channel?.queueChangeCallbacks) return;
|
|
30
31
|
|
|
31
32
|
const snapshot: QueueSnapshot | null = createQueueSnapshot(channelNumber, audioChannels);
|
|
32
33
|
if (!snapshot) return;
|
|
33
34
|
|
|
34
|
-
channel.queueChangeCallbacks.forEach(callback => {
|
|
35
|
+
channel.queueChangeCallbacks.forEach((callback) => {
|
|
35
36
|
try {
|
|
36
37
|
callback(snapshot);
|
|
37
38
|
} catch (error) {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
38
40
|
console.error('Error in queue change callback:', error);
|
|
39
41
|
}
|
|
40
42
|
});
|
|
@@ -51,17 +53,18 @@ export const emitQueueChange = (
|
|
|
51
53
|
* ```
|
|
52
54
|
*/
|
|
53
55
|
export const emitAudioStart = (
|
|
54
|
-
channelNumber: number,
|
|
56
|
+
channelNumber: number,
|
|
55
57
|
audioInfo: AudioStartInfo,
|
|
56
58
|
audioChannels: ExtendedAudioQueueChannel[]
|
|
57
59
|
): void => {
|
|
58
60
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
59
|
-
if (!channel
|
|
61
|
+
if (!channel?.audioStartCallbacks) return;
|
|
60
62
|
|
|
61
|
-
channel.audioStartCallbacks.forEach(callback => {
|
|
63
|
+
channel.audioStartCallbacks.forEach((callback) => {
|
|
62
64
|
try {
|
|
63
65
|
callback(audioInfo);
|
|
64
66
|
} catch (error) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
65
68
|
console.error('Error in audio start callback:', error);
|
|
66
69
|
}
|
|
67
70
|
});
|
|
@@ -78,17 +81,18 @@ export const emitAudioStart = (
|
|
|
78
81
|
* ```
|
|
79
82
|
*/
|
|
80
83
|
export const emitAudioComplete = (
|
|
81
|
-
channelNumber: number,
|
|
84
|
+
channelNumber: number,
|
|
82
85
|
audioInfo: AudioCompleteInfo,
|
|
83
86
|
audioChannels: ExtendedAudioQueueChannel[]
|
|
84
87
|
): void => {
|
|
85
88
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
86
|
-
if (!channel
|
|
89
|
+
if (!channel?.audioCompleteCallbacks) return;
|
|
87
90
|
|
|
88
|
-
channel.audioCompleteCallbacks.forEach(callback => {
|
|
91
|
+
channel.audioCompleteCallbacks.forEach((callback) => {
|
|
89
92
|
try {
|
|
90
93
|
callback(audioInfo);
|
|
91
94
|
} catch (error) {
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
92
96
|
console.error('Error in audio complete callback:', error);
|
|
93
97
|
}
|
|
94
98
|
});
|
|
@@ -105,17 +109,18 @@ export const emitAudioComplete = (
|
|
|
105
109
|
* ```
|
|
106
110
|
*/
|
|
107
111
|
export const emitAudioPause = (
|
|
108
|
-
channelNumber: number,
|
|
112
|
+
channelNumber: number,
|
|
109
113
|
audioInfo: AudioInfo,
|
|
110
114
|
audioChannels: ExtendedAudioQueueChannel[]
|
|
111
115
|
): void => {
|
|
112
116
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
113
|
-
if (!channel
|
|
117
|
+
if (!channel?.audioPauseCallbacks) return;
|
|
114
118
|
|
|
115
|
-
channel.audioPauseCallbacks.forEach(callback => {
|
|
119
|
+
channel.audioPauseCallbacks.forEach((callback) => {
|
|
116
120
|
try {
|
|
117
121
|
callback(channelNumber, audioInfo);
|
|
118
122
|
} catch (error) {
|
|
123
|
+
// eslint-disable-next-line no-console
|
|
119
124
|
console.error('Error in audio pause callback:', error);
|
|
120
125
|
}
|
|
121
126
|
});
|
|
@@ -132,24 +137,25 @@ export const emitAudioPause = (
|
|
|
132
137
|
* ```
|
|
133
138
|
*/
|
|
134
139
|
export const emitAudioResume = (
|
|
135
|
-
channelNumber: number,
|
|
140
|
+
channelNumber: number,
|
|
136
141
|
audioInfo: AudioInfo,
|
|
137
142
|
audioChannels: ExtendedAudioQueueChannel[]
|
|
138
143
|
): void => {
|
|
139
144
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
140
|
-
if (!channel
|
|
145
|
+
if (!channel?.audioResumeCallbacks) return;
|
|
141
146
|
|
|
142
|
-
channel.audioResumeCallbacks.forEach(callback => {
|
|
147
|
+
channel.audioResumeCallbacks.forEach((callback) => {
|
|
143
148
|
try {
|
|
144
149
|
callback(channelNumber, audioInfo);
|
|
145
150
|
} catch (error) {
|
|
151
|
+
// eslint-disable-next-line no-console
|
|
146
152
|
console.error('Error in audio resume callback:', error);
|
|
147
153
|
}
|
|
148
154
|
});
|
|
149
155
|
};
|
|
150
156
|
|
|
151
157
|
// Store listener functions for cleanup
|
|
152
|
-
const progressListeners
|
|
158
|
+
const progressListeners: WeakMap<HTMLAudioElement, () => void> = new WeakMap();
|
|
153
159
|
|
|
154
160
|
/**
|
|
155
161
|
* Sets up comprehensive progress tracking for an audio element
|
|
@@ -163,7 +169,7 @@ const progressListeners = new WeakMap<HTMLAudioElement, () => void>();
|
|
|
163
169
|
* ```
|
|
164
170
|
*/
|
|
165
171
|
export const setupProgressTracking = (
|
|
166
|
-
audio: HTMLAudioElement,
|
|
172
|
+
audio: HTMLAudioElement,
|
|
167
173
|
channelNumber: number,
|
|
168
174
|
audioChannels: ExtendedAudioQueueChannel[]
|
|
169
175
|
): void => {
|
|
@@ -179,12 +185,14 @@ export const setupProgressTracking = (
|
|
|
179
185
|
|
|
180
186
|
const updateProgress = (): void => {
|
|
181
187
|
// Get callbacks for this specific audio element AND the channel-wide callbacks
|
|
182
|
-
const audioCallbacks: Set<ProgressCallback> =
|
|
183
|
-
|
|
184
|
-
|
|
188
|
+
const audioCallbacks: Set<ProgressCallback> =
|
|
189
|
+
channel.progressCallbacks?.get(audio) ?? new Set();
|
|
190
|
+
const channelCallbacks: Set<ProgressCallback> =
|
|
191
|
+
channel.progressCallbacks?.get(GLOBAL_PROGRESS_KEY) ?? new Set();
|
|
192
|
+
|
|
185
193
|
// Combine both sets of callbacks
|
|
186
194
|
const allCallbacks: Set<ProgressCallback> = new Set([...audioCallbacks, ...channelCallbacks]);
|
|
187
|
-
|
|
195
|
+
|
|
188
196
|
if (allCallbacks.size === 0) return;
|
|
189
197
|
|
|
190
198
|
const info: AudioInfo | null = getAudioInfoFromElement(audio, channelNumber, audioChannels);
|
|
@@ -193,6 +201,7 @@ export const setupProgressTracking = (
|
|
|
193
201
|
try {
|
|
194
202
|
callback(info);
|
|
195
203
|
} catch (error) {
|
|
204
|
+
// eslint-disable-next-line no-console
|
|
196
205
|
console.error('Error in progress callback:', error);
|
|
197
206
|
}
|
|
198
207
|
});
|
|
@@ -221,12 +230,12 @@ export const setupProgressTracking = (
|
|
|
221
230
|
* ```
|
|
222
231
|
*/
|
|
223
232
|
export const cleanupProgressTracking = (
|
|
224
|
-
audio: HTMLAudioElement,
|
|
233
|
+
audio: HTMLAudioElement,
|
|
225
234
|
channelNumber: number,
|
|
226
235
|
audioChannels: ExtendedAudioQueueChannel[]
|
|
227
236
|
): void => {
|
|
228
237
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
229
|
-
if (!channel
|
|
238
|
+
if (!channel?.progressCallbacks) return;
|
|
230
239
|
|
|
231
240
|
// Remove event listeners
|
|
232
241
|
const updateProgress: (() => void) | undefined = progressListeners.get(audio);
|
|
@@ -240,4 +249,4 @@ export const cleanupProgressTracking = (
|
|
|
240
249
|
}
|
|
241
250
|
|
|
242
251
|
channel.progressCallbacks.delete(audio);
|
|
243
|
-
};
|
|
252
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -5,65 +5,72 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// Core queue management functions
|
|
8
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
queueAudio,
|
|
10
|
+
queueAudioPriority,
|
|
11
|
+
stopCurrentAudioInChannel,
|
|
12
|
+
stopAllAudioInChannel,
|
|
13
|
+
stopAllAudio,
|
|
14
|
+
playAudioQueue
|
|
15
|
+
} from './core';
|
|
9
16
|
|
|
10
17
|
// Error handling and recovery functions
|
|
11
|
-
export {
|
|
12
|
-
getErrorRecovery,
|
|
13
|
-
getRetryConfig,
|
|
14
|
-
offAudioError,
|
|
15
|
-
onAudioError,
|
|
18
|
+
export {
|
|
19
|
+
getErrorRecovery,
|
|
20
|
+
getRetryConfig,
|
|
21
|
+
offAudioError,
|
|
22
|
+
onAudioError,
|
|
16
23
|
retryFailedAudio,
|
|
17
|
-
setErrorRecovery,
|
|
18
|
-
setRetryConfig
|
|
24
|
+
setErrorRecovery,
|
|
25
|
+
setRetryConfig
|
|
19
26
|
} from './errors';
|
|
20
27
|
|
|
21
28
|
// Pause and resume management functions
|
|
22
|
-
export {
|
|
23
|
-
getAllChannelsPauseState,
|
|
24
|
-
isChannelPaused,
|
|
25
|
-
pauseAllChannels,
|
|
29
|
+
export {
|
|
30
|
+
getAllChannelsPauseState,
|
|
31
|
+
isChannelPaused,
|
|
32
|
+
pauseAllChannels,
|
|
26
33
|
pauseAllWithFade,
|
|
27
|
-
pauseChannel,
|
|
34
|
+
pauseChannel,
|
|
28
35
|
pauseWithFade,
|
|
29
|
-
resumeAllChannels,
|
|
36
|
+
resumeAllChannels,
|
|
30
37
|
resumeAllWithFade,
|
|
31
|
-
resumeChannel,
|
|
38
|
+
resumeChannel,
|
|
32
39
|
resumeWithFade,
|
|
33
40
|
togglePauseAllChannels,
|
|
34
41
|
togglePauseAllWithFade,
|
|
35
42
|
togglePauseChannel,
|
|
36
|
-
togglePauseWithFade
|
|
43
|
+
togglePauseWithFade
|
|
37
44
|
} from './pause';
|
|
38
45
|
|
|
39
46
|
// Volume control and ducking functions
|
|
40
|
-
export {
|
|
47
|
+
export {
|
|
41
48
|
clearVolumeDucking,
|
|
42
49
|
fadeVolume,
|
|
43
|
-
getAllChannelsVolume,
|
|
44
|
-
getChannelVolume,
|
|
50
|
+
getAllChannelsVolume,
|
|
51
|
+
getChannelVolume,
|
|
45
52
|
getFadeConfig,
|
|
46
|
-
setAllChannelsVolume,
|
|
47
|
-
setChannelVolume,
|
|
53
|
+
setAllChannelsVolume,
|
|
54
|
+
setChannelVolume,
|
|
48
55
|
setVolumeDucking,
|
|
49
|
-
transitionVolume
|
|
56
|
+
transitionVolume
|
|
50
57
|
} from './volume';
|
|
51
58
|
|
|
52
59
|
// Audio information and progress tracking functions
|
|
53
|
-
export {
|
|
54
|
-
getAllChannelsInfo,
|
|
55
|
-
getCurrentAudioInfo,
|
|
56
|
-
getQueueSnapshot,
|
|
57
|
-
offAudioPause,
|
|
58
|
-
offAudioProgress,
|
|
60
|
+
export {
|
|
61
|
+
getAllChannelsInfo,
|
|
62
|
+
getCurrentAudioInfo,
|
|
63
|
+
getQueueSnapshot,
|
|
64
|
+
offAudioPause,
|
|
65
|
+
offAudioProgress,
|
|
59
66
|
offAudioResume,
|
|
60
|
-
offQueueChange,
|
|
61
|
-
onAudioComplete,
|
|
62
|
-
onAudioPause,
|
|
63
|
-
onAudioProgress,
|
|
64
|
-
onAudioResume,
|
|
65
|
-
onAudioStart,
|
|
66
|
-
onQueueChange
|
|
67
|
+
offQueueChange,
|
|
68
|
+
onAudioComplete,
|
|
69
|
+
onAudioPause,
|
|
70
|
+
onAudioProgress,
|
|
71
|
+
onAudioResume,
|
|
72
|
+
onAudioStart,
|
|
73
|
+
onQueueChange
|
|
67
74
|
} from './info';
|
|
68
75
|
|
|
69
76
|
// Core data access for legacy compatibility
|
|
@@ -78,12 +85,12 @@ export {
|
|
|
78
85
|
} from './utils';
|
|
79
86
|
|
|
80
87
|
// TypeScript type definitions and interfaces
|
|
81
|
-
export type {
|
|
88
|
+
export type {
|
|
82
89
|
AudioCompleteCallback,
|
|
83
90
|
AudioCompleteInfo,
|
|
84
91
|
AudioErrorCallback,
|
|
85
92
|
AudioErrorInfo,
|
|
86
|
-
AudioInfo,
|
|
93
|
+
AudioInfo,
|
|
87
94
|
AudioPauseCallback,
|
|
88
95
|
AudioQueueOptions,
|
|
89
96
|
AudioResumeCallback,
|
|
@@ -98,11 +105,8 @@ export type {
|
|
|
98
105
|
QueueItem,
|
|
99
106
|
QueueSnapshot,
|
|
100
107
|
RetryConfig,
|
|
101
|
-
VolumeConfig
|
|
108
|
+
VolumeConfig
|
|
102
109
|
} from './types';
|
|
103
110
|
|
|
104
|
-
// Enums
|
|
105
|
-
export {
|
|
106
|
-
EasingType,
|
|
107
|
-
FadeType
|
|
108
|
-
} from './types';
|
|
111
|
+
// Enums and constants
|
|
112
|
+
export { EasingType, FadeType, GLOBAL_PROGRESS_KEY } from './types';
|
package/src/info.ts
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
* @fileoverview Audio information and progress tracking functions for the audio-channel-queue package
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
AudioInfo,
|
|
7
|
-
QueueSnapshot,
|
|
5
|
+
import {
|
|
6
|
+
AudioInfo,
|
|
7
|
+
QueueSnapshot,
|
|
8
8
|
ProgressCallback,
|
|
9
9
|
QueueChangeCallback,
|
|
10
10
|
AudioStartCallback,
|
|
11
11
|
AudioCompleteCallback,
|
|
12
12
|
AudioPauseCallback,
|
|
13
13
|
AudioResumeCallback,
|
|
14
|
-
ExtendedAudioQueueChannel
|
|
14
|
+
ExtendedAudioQueueChannel,
|
|
15
|
+
GLOBAL_PROGRESS_KEY
|
|
15
16
|
} from './types';
|
|
16
17
|
import { getAudioInfoFromElement, createQueueSnapshot } from './utils';
|
|
17
18
|
import { setupProgressTracking, cleanupProgressTracking } from './events';
|
|
@@ -60,11 +61,11 @@ export const getCurrentAudioInfo = (channelNumber: number = 0): AudioInfo | null
|
|
|
60
61
|
*/
|
|
61
62
|
export const getAllChannelsInfo = (): (AudioInfo | null)[] => {
|
|
62
63
|
const allChannelsInfo: (AudioInfo | null)[] = [];
|
|
63
|
-
|
|
64
|
-
for (let i = 0; i < audioChannels.length; i++) {
|
|
64
|
+
|
|
65
|
+
for (let i: number = 0; i < audioChannels.length; i++) {
|
|
65
66
|
allChannelsInfo.push(getCurrentAudioInfo(i));
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
|
|
68
69
|
return allChannelsInfo;
|
|
69
70
|
};
|
|
70
71
|
|
|
@@ -99,7 +100,7 @@ export const getQueueSnapshot = (channelNumber: number): QueueSnapshot | null =>
|
|
|
99
100
|
*/
|
|
100
101
|
export const onAudioProgress = (channelNumber: number, callback: ProgressCallback): void => {
|
|
101
102
|
if (!audioChannels[channelNumber]) {
|
|
102
|
-
audioChannels[channelNumber] = {
|
|
103
|
+
audioChannels[channelNumber] = {
|
|
103
104
|
audioCompleteCallbacks: new Set(),
|
|
104
105
|
audioErrorCallbacks: new Set(),
|
|
105
106
|
audioPauseCallbacks: new Set(),
|
|
@@ -125,16 +126,16 @@ export const onAudioProgress = (channelNumber: number, callback: ProgressCallbac
|
|
|
125
126
|
channel.progressCallbacks.set(currentAudio, new Set());
|
|
126
127
|
}
|
|
127
128
|
channel.progressCallbacks.get(currentAudio)!.add(callback);
|
|
128
|
-
|
|
129
|
+
|
|
129
130
|
// Set up tracking if not already done
|
|
130
131
|
setupProgressTracking(currentAudio, channelNumber, audioChannels);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
// Store callback for future audio elements in this channel
|
|
134
|
-
if (!channel.progressCallbacks.has(
|
|
135
|
-
channel.progressCallbacks.set(
|
|
135
|
+
if (!channel.progressCallbacks.has(GLOBAL_PROGRESS_KEY)) {
|
|
136
|
+
channel.progressCallbacks.set(GLOBAL_PROGRESS_KEY, new Set());
|
|
136
137
|
}
|
|
137
|
-
channel.progressCallbacks.get(
|
|
138
|
+
channel.progressCallbacks.get(GLOBAL_PROGRESS_KEY)!.add(callback);
|
|
138
139
|
};
|
|
139
140
|
|
|
140
141
|
/**
|
|
@@ -147,7 +148,7 @@ export const onAudioProgress = (channelNumber: number, callback: ProgressCallbac
|
|
|
147
148
|
*/
|
|
148
149
|
export const offAudioProgress = (channelNumber: number): void => {
|
|
149
150
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
150
|
-
if (!channel
|
|
151
|
+
if (!channel?.progressCallbacks) return;
|
|
151
152
|
|
|
152
153
|
// Clean up event listeners for current audio if exists
|
|
153
154
|
if (channel.queue.length > 0) {
|
|
@@ -173,7 +174,7 @@ export const offAudioProgress = (channelNumber: number): void => {
|
|
|
173
174
|
*/
|
|
174
175
|
export const onQueueChange = (channelNumber: number, callback: QueueChangeCallback): void => {
|
|
175
176
|
if (!audioChannels[channelNumber]) {
|
|
176
|
-
audioChannels[channelNumber] = {
|
|
177
|
+
audioChannels[channelNumber] = {
|
|
177
178
|
audioCompleteCallbacks: new Set(),
|
|
178
179
|
audioErrorCallbacks: new Set(),
|
|
179
180
|
audioPauseCallbacks: new Set(),
|
|
@@ -205,7 +206,7 @@ export const onQueueChange = (channelNumber: number, callback: QueueChangeCallba
|
|
|
205
206
|
*/
|
|
206
207
|
export const offQueueChange = (channelNumber: number): void => {
|
|
207
208
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
208
|
-
if (!channel
|
|
209
|
+
if (!channel?.queueChangeCallbacks) return;
|
|
209
210
|
|
|
210
211
|
channel.queueChangeCallbacks.clear();
|
|
211
212
|
};
|
|
@@ -224,7 +225,7 @@ export const offQueueChange = (channelNumber: number): void => {
|
|
|
224
225
|
*/
|
|
225
226
|
export const onAudioStart = (channelNumber: number, callback: AudioStartCallback): void => {
|
|
226
227
|
if (!audioChannels[channelNumber]) {
|
|
227
|
-
audioChannels[channelNumber] = {
|
|
228
|
+
audioChannels[channelNumber] = {
|
|
228
229
|
audioCompleteCallbacks: new Set(),
|
|
229
230
|
audioErrorCallbacks: new Set(),
|
|
230
231
|
audioPauseCallbacks: new Set(),
|
|
@@ -262,7 +263,7 @@ export const onAudioStart = (channelNumber: number, callback: AudioStartCallback
|
|
|
262
263
|
*/
|
|
263
264
|
export const onAudioComplete = (channelNumber: number, callback: AudioCompleteCallback): void => {
|
|
264
265
|
if (!audioChannels[channelNumber]) {
|
|
265
|
-
audioChannels[channelNumber] = {
|
|
266
|
+
audioChannels[channelNumber] = {
|
|
266
267
|
audioCompleteCallbacks: new Set(),
|
|
267
268
|
audioErrorCallbacks: new Set(),
|
|
268
269
|
audioPauseCallbacks: new Set(),
|
|
@@ -298,7 +299,7 @@ export const onAudioComplete = (channelNumber: number, callback: AudioCompleteCa
|
|
|
298
299
|
*/
|
|
299
300
|
export const onAudioPause = (channelNumber: number, callback: AudioPauseCallback): void => {
|
|
300
301
|
if (!audioChannels[channelNumber]) {
|
|
301
|
-
audioChannels[channelNumber] = {
|
|
302
|
+
audioChannels[channelNumber] = {
|
|
302
303
|
audioCompleteCallbacks: new Set(),
|
|
303
304
|
audioErrorCallbacks: new Set(),
|
|
304
305
|
audioPauseCallbacks: new Set(),
|
|
@@ -334,7 +335,7 @@ export const onAudioPause = (channelNumber: number, callback: AudioPauseCallback
|
|
|
334
335
|
*/
|
|
335
336
|
export const onAudioResume = (channelNumber: number, callback: AudioResumeCallback): void => {
|
|
336
337
|
if (!audioChannels[channelNumber]) {
|
|
337
|
-
audioChannels[channelNumber] = {
|
|
338
|
+
audioChannels[channelNumber] = {
|
|
338
339
|
audioCompleteCallbacks: new Set(),
|
|
339
340
|
audioErrorCallbacks: new Set(),
|
|
340
341
|
audioPauseCallbacks: new Set(),
|
|
@@ -366,7 +367,7 @@ export const onAudioResume = (channelNumber: number, callback: AudioResumeCallba
|
|
|
366
367
|
*/
|
|
367
368
|
export const offAudioPause = (channelNumber: number): void => {
|
|
368
369
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
369
|
-
if (!channel
|
|
370
|
+
if (!channel?.audioPauseCallbacks) return;
|
|
370
371
|
|
|
371
372
|
channel.audioPauseCallbacks.clear();
|
|
372
373
|
};
|
|
@@ -381,7 +382,7 @@ export const offAudioPause = (channelNumber: number): void => {
|
|
|
381
382
|
*/
|
|
382
383
|
export const offAudioResume = (channelNumber: number): void => {
|
|
383
384
|
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
384
|
-
if (!channel
|
|
385
|
+
if (!channel?.audioResumeCallbacks) return;
|
|
385
386
|
|
|
386
387
|
channel.audioResumeCallbacks.clear();
|
|
387
|
-
};
|
|
388
|
+
};
|