@pexip/media-processor 16.7.1 → 17.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -7
  3. package/dist/main/audio.d.ts +123 -0
  4. package/dist/main/audio.js +653 -0
  5. package/dist/main/benchUtils.d.ts +12 -0
  6. package/dist/main/benchUtils.js +34 -0
  7. package/dist/main/generator.d.ts +4 -0
  8. package/dist/main/generator.js +4 -0
  9. package/dist/main/index.d.ts +17 -0
  10. package/dist/main/index.js +17 -0
  11. package/dist/main/math.d.ts +41 -0
  12. package/dist/main/math.js +57 -0
  13. package/dist/main/path.d.ts +102 -0
  14. package/dist/main/path.js +103 -0
  15. package/dist/main/process.d.ts +239 -0
  16. package/dist/main/process.js +364 -0
  17. package/dist/main/processor.d.ts +5 -0
  18. package/dist/main/processor.js +4 -0
  19. package/dist/main/transformer.d.ts +1 -0
  20. package/dist/main/transformer.js +4 -0
  21. package/dist/main/tsconfig.tsbuildinfo +1 -0
  22. package/dist/main/typeGuards.d.ts +5 -0
  23. package/dist/main/typeGuards.js +24 -0
  24. package/dist/main/types.d.ts +342 -0
  25. package/dist/main/types.js +1 -0
  26. package/dist/main/utils.d.ts +173 -0
  27. package/dist/main/utils.js +364 -0
  28. package/dist/main/video/canvasRenderUtils.d.ts +22 -0
  29. package/dist/main/video/canvasRenderUtils.js +198 -0
  30. package/dist/main/video/canvasTransform.d.ts +8 -0
  31. package/dist/main/video/canvasTransform.js +173 -0
  32. package/dist/main/video/constants.d.ts +10 -0
  33. package/dist/main/video/constants.js +12 -0
  34. package/dist/main/video/index.d.ts +9 -0
  35. package/dist/main/video/index.js +9 -0
  36. package/dist/main/video/load.d.ts +17 -0
  37. package/dist/main/video/load.js +47 -0
  38. package/dist/main/video/segmenters/index.d.ts +1 -0
  39. package/dist/main/video/segmenters/index.js +1 -0
  40. package/dist/main/video/segmenters/mediapipe.d.ts +13 -0
  41. package/dist/main/video/segmenters/mediapipe.js +85 -0
  42. package/dist/main/video/transformer.d.ts +10 -0
  43. package/dist/main/video/transformer.js +56 -0
  44. package/dist/main/video/typeGuards.d.ts +2 -0
  45. package/dist/main/video/typeGuards.js +13 -0
  46. package/dist/main/video/types.d.ts +98 -0
  47. package/dist/main/video/types.js +20 -0
  48. package/dist/main/video/utils.d.ts +102 -0
  49. package/dist/main/video/utils.js +476 -0
  50. package/dist/main/video/video.d.ts +19 -0
  51. package/dist/main/video/video.js +48 -0
  52. package/dist/main/video/videoStreamTrackProcessor.d.ts +14 -0
  53. package/dist/main/video/videoStreamTrackProcessor.js +82 -0
  54. package/dist/main/visual.d.ts +80 -0
  55. package/dist/main/visual.js +135 -0
  56. package/dist/main/workletNodes.d.ts +2 -0
  57. package/dist/main/workletNodes.js +3 -0
  58. package/dist/workers/index.d.ts +0 -0
  59. package/dist/workers/index.js +1 -0
  60. package/dist/workers/tsconfig.tsbuildinfo +1 -0
  61. package/dist/worklets/denoise.worklet.d.ts +1 -0
  62. package/dist/worklets/denoise.worklet.js +1 -2
  63. package/dist/worklets/tsconfig.tsbuildinfo +1 -0
  64. package/dist/worklets/types.d.ts +52 -0
  65. package/dist/worklets/types.js +0 -0
  66. package/package.json +10 -8
  67. package/dist/index.d.ts +0 -1129
  68. package/dist/index.mjs +0 -2441
  69. package/dist/worklets/denoise.worklet.js.map +0 -7
@@ -0,0 +1,342 @@
1
+ /**
2
+ * Interface for Point consist of coordinates x and y
3
+ *
4
+ * @alpha
5
+ */
6
+ export interface Point {
7
+ x: number;
8
+ y: number;
9
+ }
10
+ export interface Size {
11
+ width: number;
12
+ height: number;
13
+ }
14
+ export type Rect = Point & Size;
15
+ export interface Frame extends Size {
16
+ source: Canvas | HTMLVideoElement | HTMLImageElement;
17
+ }
18
+ /**
19
+ * Unsubscribe the subscription
20
+ */
21
+ export type Unsubscribe = () => void;
22
+ /**
23
+ * Same as {@link https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer | AudioBuffer}
24
+ * Or the return from {@link https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getFloatFrequencyData | AnalyserNode.getFloatFrequencyData()}
25
+ */
26
+ export type AudioBufferFloats = Float32Array;
27
+ /**
28
+ * Same as the return from {@link https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData | AnalyserNode.getByteFrequencyData()}
29
+ */
30
+ export type AudioBufferBytes = Uint8Array;
31
+ /**
32
+ * Audio samples from each channel, either in float or bytes form
33
+ *
34
+ * @example
35
+ *
36
+ * ```
37
+ * | | | Sample Frame 1 | Sample Frame 2 | Sample Frame 3 |
38
+ * | Input | Channel L: | sample 1 | sample 2 | sample 3 |
39
+ * | | Channel R: | sample 1 | sample 2 | sample 3 |
40
+ * ```
41
+ * We can get 2 `AudioSamples` from "Channel L" and "Channel R" from "Input"
42
+ */
43
+ export type AudioSamples = number[] | AudioBufferFloats | AudioBufferBytes;
44
+ /**
45
+ * Data structure for the audio statistics while processing
46
+ */
47
+ export interface AudioStats {
48
+ /**
49
+ * Indicating the audio is silent when it is set to `true`
50
+ */
51
+ silent: boolean;
52
+ /**
53
+ * Indicating the audio is mono when it is set to `true`
54
+ *
55
+ * `undefined` means cannot-not-tell.
56
+ */
57
+ mono?: boolean;
58
+ /**
59
+ * Indicating the audio is low volume when it is set to `true`
60
+ */
61
+ lowVolume: boolean;
62
+ /**
63
+ * Indicating the audio is clipping when it is set to `true`
64
+ */
65
+ clipping: boolean;
66
+ /**
67
+ * Peak gain value
68
+ */
69
+ peak: number;
70
+ /**
71
+ * Global rms
72
+ */
73
+ rms: number;
74
+ /**
75
+ * Maximum running RMS value
76
+ */
77
+ maxRms: number;
78
+ /**
79
+ * Maximum Clip count
80
+ */
81
+ maxClipCount: number;
82
+ /**
83
+ * Value of sum squared sample used for RMS calculation
84
+ */
85
+ sumSquare: number;
86
+ /**
87
+ * Value of sum number of sample used for RMS calculation
88
+ */
89
+ sumLength: number;
90
+ }
91
+ /**
92
+ * Stats options for calculating the audio stats
93
+ */
94
+ export interface StatsOptions {
95
+ /**
96
+ * Used for the analysis
97
+ */
98
+ samples: AudioSamples;
99
+ /**
100
+ * this will be used for accumulation
101
+ */
102
+ baseStats?: AudioStats;
103
+ /**
104
+ * Threshold for clipping
105
+ *
106
+ * @defaultValue
107
+ * `1.0` as assuming it is float value
108
+ */
109
+ clipThreshold?: number;
110
+ /**
111
+ * Threshold for silent
112
+ *
113
+ * @defaultValue
114
+ * 1.0 / 32767
115
+ */
116
+ silentThreshold?: number;
117
+ }
118
+ export interface SubscribableOptions {
119
+ updateFrequency?: number;
120
+ }
121
+ export interface WorkletMessagePortOptions<T> {
122
+ messageHandler: (message: T) => void;
123
+ errorHandler?: (event: Event) => void;
124
+ }
125
+ export interface AnalyzerSubscribableOptions extends SubscribableOptions, WorkletMessagePortOptions<Analyzer> {
126
+ }
127
+ /**
128
+ * A wrapper for the Denoise wasm module
129
+ */
130
+ export interface Denoise {
131
+ vad(channel: number): number;
132
+ free(): void;
133
+ pipe(inputs: Float32Array[][], outputs: Float32Array[][]): void;
134
+ }
135
+ export type NodeConnectionAction = 'connect' | 'disconnect';
136
+ export type BaseAudioNode = Pick<AudioNode, NodeConnectionAction>;
137
+ export interface Gain extends BaseAudioNode {
138
+ readonly node: GainNode;
139
+ mute: boolean;
140
+ }
141
+ export interface Analyzer extends BaseAudioNode {
142
+ readonly node: AnalyserNode;
143
+ readonly frequencyBinCount: AnalyserNode['frequencyBinCount'];
144
+ fftSize: AnalyserNode['fftSize'];
145
+ minDecibels: AnalyserNode['minDecibels'];
146
+ maxDecibels: AnalyserNode['maxDecibels'];
147
+ smoothingTimeConstant: AnalyserNode['smoothingTimeConstant'];
148
+ /**
149
+ * Copies the current waveform, or time-domain, data into a Uint8Array
150
+ * (unsigned byte array) passed into it.
151
+ *
152
+ * If the array has fewer elements than the `AnalyserNode.fftSize`, excess
153
+ * elements are dropped.
154
+ * If it has more elements than needed, excess elements are ignored.
155
+ *
156
+ * @param buffer - Use provided buffer instead of creating a new one
157
+ *
158
+ * @remarks
159
+ * The bytes versions are not cheaper than the float version but provided
160
+ * for convenient: the byte version are computed from the float version,
161
+ * using simple quantization to 2^8 values
162
+ * ref. https://padenot.github.io/web-audio-perf/#analysernode
163
+ */
164
+ getByteTimeDomainData(buffer: Uint8Array): void;
165
+ /**
166
+ * Copies the current frequency data into a Uint8Array (unsigned byte array)
167
+ * passed into it.
168
+ *
169
+ * The frequency data is composed of integers on a scale from 0 to 255.
170
+ *
171
+ * @param buffer - Use provided buffer instead of creating a new one
172
+ *
173
+ * @remarks
174
+ * The bytes versions are not cheaper than the float version but provided
175
+ * for convenient: the byte version are computed from the float version,
176
+ * using simple quantization to 2^8 values
177
+ * ref. https://padenot.github.io/web-audio-perf/#analysernode
178
+ */
179
+ getByteFrequencyData(buffer: Uint8Array): void;
180
+ /**
181
+ * Copies the current waveform, or time-domain, data into Float32Array
182
+ * passed into it
183
+ *
184
+ * @param buffer - Use provided buffer instead of creating a new one
185
+ *
186
+ * @remarks
187
+ * The buffer size should be the same as `AnalyserNode.fftSize`
188
+ */
189
+ getFloatTimeDomainData(buffer: Float32Array): void;
190
+ /**
191
+ * Copies the current waveform, or time-domain, data into Float32Array
192
+ * passed into it
193
+ *
194
+ * @param buffer - Use provided buffer instead of creating a new one
195
+ *
196
+ * @remarks
197
+ * The buffer size should be the same as `AnalyserNode.frequencyBinCount`
198
+ */
199
+ getFloatFrequencyData(buffer: Float32Array): void;
200
+ /**
201
+ * Utility function to get the average volume from `getByteFrequencyData`
202
+ *
203
+ * @param options - `buffer`, use provided buffer instead of creating a new
204
+ * one, and `beforeAlter`, will analyze the raw data before any changes to
205
+ * the audio signal when it is set to `true`
206
+ *
207
+ * @remarks
208
+ * This is a better option when you only need to get the volume in terms of
209
+ * performance and complexity.
210
+ */
211
+ getAverageVolume(buffer: Float32Array): number;
212
+ }
213
+ export interface AudioNodeProps<T extends AudioNode, R extends BaseAudioNode> {
214
+ name: string;
215
+ node: R | undefined;
216
+ audioNode: T | undefined;
217
+ outputs: WeakSet<AudioNodeInit | AudioParam>;
218
+ }
219
+ export type AudioNodeParam = BaseAudioNode | AudioParam;
220
+ export type Node = AudioNode | AudioParam;
221
+ export type Nodes = Node[];
222
+ export type ConnectParamBaseType = AudioParam | BaseAudioNode;
223
+ export type ConnectInitParamBaseType = AudioParam | AudioNodeInit;
224
+ export type ConnectParamType = ConnectParamBaseType | undefined;
225
+ export type ConnectInitParamType = ConnectInitParamBaseType | undefined;
226
+ type AudioNodeInputIndex = number | undefined;
227
+ type AudioNodeOutputIndex = number | undefined;
228
+ export type ConnectParamBase<T extends ConnectParamType | ConnectInitParamType> = [
229
+ T,
230
+ T extends undefined ? undefined : AudioNodeOutputIndex,
231
+ T extends undefined ? undefined : AudioNodeInputIndex
232
+ ] | T;
233
+ export type AudioNodeConnectParam = ConnectParamBase<ConnectParamType>;
234
+ export type AudioNodeInitConnectParam = ConnectParamBase<ConnectInitParamType>;
235
+ export type AudioNodeInitConnection = AudioNodeInitConnectParam[];
236
+ export type AudioNodeInitConnections = AudioNodeInitConnection[];
237
+ export interface AudioNodeInit<T extends AudioNode = AudioNode, R extends BaseAudioNode = BaseAudioNode> extends Readonly<AudioNodeProps<T, R>> {
238
+ /**
239
+ * Internal function to create the actual AudioNode.
240
+ * Should ONLY be CALLED inside an AudioGraph
241
+ *
242
+ * @param context - Audio Context to use
243
+ * @param prevNode - The input AudioNode for connection
244
+ *
245
+ * @internal
246
+ */
247
+ create(context: AudioContext, prevNode?: AudioNode): [T, R];
248
+ /**
249
+ * Internal function to connect a signal output
250
+ * Should ONLY be CALLED inside an AudioGraph
251
+ *
252
+ * @param param - The init to connect
253
+ *
254
+ * @internal
255
+ */
256
+ connect(param: AudioNodeInitConnectParam | undefined): void;
257
+ /**
258
+ * Internal function to disconnect a signal output
259
+ * Should ONLY be CALLED inside an AudioGraph
260
+ *
261
+ * @param param - The init to disconnect
262
+ *
263
+ * @internal
264
+ */
265
+ disconnect(param: AudioNodeInitConnectParam | undefined): void;
266
+ /**
267
+ * Check if there is a connection to the provided init
268
+ * @param init - AudioNodeInit
269
+ */
270
+ hasConnectedTo(init: AudioNodeInit | AudioParam): boolean;
271
+ /**
272
+ * Internal function to release the node init resources
273
+ * Should ONLY be CALLED inside an AudioGraph
274
+ *
275
+ * @internal
276
+ */
277
+ release(): void;
278
+ toJSON?: () => unknown;
279
+ }
280
+ export type MediaStreamAudioSourceNodeInit = AudioNodeInit<MediaStreamAudioSourceNode, MediaStreamAudioSourceNode>;
281
+ export type MediaElementAudioSourceNodeInit = AudioNodeInit<MediaElementAudioSourceNode, MediaElementAudioSourceNode>;
282
+ export type AnalyzerNodeInit = AudioNodeInit<AnalyserNode, Analyzer>;
283
+ export type DenoiseWorkletNodeInit = AudioNodeInit<AudioWorkletNode>;
284
+ export type GainNodeInit = AudioNodeInit<GainNode, Gain>;
285
+ export type MediaStreamAudioDestinationNodeInit = AudioNodeInit<MediaStreamAudioDestinationNode, MediaStreamAudioDestinationNode>;
286
+ export type AudioDestinationNodeInit = AudioNodeInit<AudioDestinationNode, AudioDestinationNode>;
287
+ export type DelayNodeInit = AudioNodeInit<DelayNode, DelayNode>;
288
+ export type ChannelSplitterNodeInit = AudioNodeInit<ChannelSplitterNode, ChannelSplitterNode>;
289
+ export interface WorkletModule {
290
+ moduleURL: string;
291
+ options?: WorkletOptions;
292
+ }
293
+ export interface AudioGraphOptions {
294
+ context?: AudioContext;
295
+ contextOptions?: AudioContextOptions;
296
+ }
297
+ type AudioGraphState = AudioContext['state'] | 'closing';
298
+ export interface AudioGraph {
299
+ readonly context: AudioContext;
300
+ readonly inits: AudioNodeInit[];
301
+ readonly state: AudioGraphState;
302
+ connect(sequence: AudioNodeInitConnection): void;
303
+ disconnect(sequence: AudioNodeInitConnection): void;
304
+ addWorklet(moduleURL: string, options?: WorkletOptions): Promise<void>;
305
+ releaseInit(init: AudioNodeInit): void;
306
+ release(): Promise<void>;
307
+ }
308
+ /**
309
+ * We need to add the missing type def to work with AudioContextState in Safari
310
+ * See https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/state#resuming_interrupted_play_states_in_ios_safari
311
+ *
312
+ */
313
+ export type UniversalAudioContextState = AudioContextState | 'interrupted';
314
+ export type Canvas = HTMLCanvasElement | OffscreenCanvas;
315
+ export type CanvasContext = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
316
+ /**
317
+ * Clock interface to get the current time with now method, @see Performance['now']
318
+ */
319
+ export interface Clock {
320
+ now: Performance['now'];
321
+ }
322
+ /**
323
+ * Limit the rate of flow in terms of millisecond, and provided Clock
324
+ */
325
+ export interface ThrottleOptions {
326
+ throttleMs?: number;
327
+ clock?: Clock;
328
+ }
329
+ export type IsVoice<T> = (data: T) => boolean;
330
+ export type AsyncCallback = () => Promise<void>;
331
+ export type Callback<R, T extends unknown[]> = (...params: T) => R;
332
+ export interface Runner<P extends unknown[]> {
333
+ start(...params: P): Promise<void>;
334
+ stop(): void;
335
+ frameRate: number;
336
+ }
337
+ export type RunnerCreator<P extends unknown[], R> = (callback: Callback<R, P>, frameRate: number) => Runner<P>;
338
+ export interface Transform<I, O> extends Transformer<I, O> {
339
+ init(): Promise<void>;
340
+ destroy(): Promise<void>;
341
+ }
342
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,173 @@
1
+ import type { Clock, Callback } from './types';
2
+ export declare const hasCreateGain: (context: BaseAudioContext) => boolean;
3
+ export declare const hasAudioWorkletNode: () => boolean;
4
+ export declare const hasAudioWorklet: () => boolean;
5
+ export declare const stopStreamTracks: (stream?: MediaStream) => void | undefined;
6
+ /**
7
+ * A function to create `MediaStreamAudioSourceNode` using constructor or factory
8
+ * function depends on the browser supports
9
+ *
10
+ * @param context - @see {@link AudioContext}
11
+ * @param options - @see {@link MediaStreamAudioSourceOptions}
12
+ *
13
+ * @internal
14
+ */
15
+ export declare const createMediaStreamAudioSourceNode: (context: AudioContext, options: MediaStreamAudioSourceOptions) => MediaStreamAudioSourceNode;
16
+ /**
17
+ * A function to create `MediaStreamAudioSourceNode` using constructor or factory
18
+ * function depends on the browser supports
19
+ *
20
+ * @param context - @see {@link AudioContext}
21
+ * @param options - @see {@link MediaStreamAudioSourceOptions}
22
+ *
23
+ * @internal
24
+ */
25
+ export declare const createMediaElementSourceNode: (context: AudioContext, options: MediaElementAudioSourceOptions) => MediaElementAudioSourceNode;
26
+ /**
27
+ * A function to create `AnalyserNode` using constructor or factory
28
+ * function depends on the browser supports
29
+ *
30
+ * @param audioContext - @see {@link AudioContext}
31
+ * @param options - @see {@link AnalyserOptions}
32
+ *
33
+ * @internal
34
+ */
35
+ export declare const createAnalyserNode: (audioContext: BaseAudioContext, options?: AnalyserOptions) => AnalyserNode;
36
+ /**
37
+ * A function to create `GainNode` using constructor or factory
38
+ * function depends on the browser supports
39
+ *
40
+ * @param context - @see {@link AudioContext}
41
+ * @param options - @see {@link GainOptions}
42
+ *
43
+ * @internal
44
+ */
45
+ export declare const createGainNode: (context: BaseAudioContext, options?: GainOptions) => GainNode;
46
+ /**
47
+ * A function to clone the Audio Track
48
+ *
49
+ * @param stream - Stream to be cloned
50
+ *
51
+ * @internal
52
+ */
53
+ export declare const createMediaStreamAudioClone: (stream: MediaStream) => MediaStream;
54
+ /**
55
+ * A function to create `MediaStreamAudioDestinationNode` using constructor or
56
+ * factory function depends on the browser supports
57
+ *
58
+ * @param context - @see {@link AudioContext}
59
+ * @param options - @see {@link AudioNodeOptions}
60
+ *
61
+ * @internal
62
+ */
63
+ export declare const createMediaStreamAudioDestinationNode: (context: AudioContext, options?: AudioNodeOptions) => MediaStreamAudioDestinationNode;
64
+ /**
65
+ * A function to create `DelayNode` using constructor or
66
+ * factory function depends on the browser supports
67
+ *
68
+ * @param context - @see {@link AudioContext}
69
+ * @param options - @see {@link DelayOptions}
70
+ *
71
+ * @internal
72
+ */
73
+ export declare const createDelayNode: (context: AudioContext, options?: DelayOptions) => DelayNode;
74
+ /**
75
+ * A function to create `ChannelSplitterNode` using constructor or
76
+ * factory function depends on the browser supports
77
+ *
78
+ * @param context - @see {@link AudioContext}
79
+ * @param options - @see {@link ChannelSplitterOptions}
80
+ *
81
+ * @internal
82
+ */
83
+ export declare const createChannelSplitterNode: (context: AudioContext, options?: ChannelSplitterOptions) => ChannelSplitterNode;
84
+ /**
85
+ * A function to create `ChannelMergerNode` using constructor or
86
+ * factory function depends on the browser supports
87
+ *
88
+ * @param context - @see {@link AudioContext}
89
+ * @param options - @see {@link ChannelSplitterOptions}
90
+ *
91
+ * @internal
92
+ */
93
+ export declare const createChannelMergerNode: (context: AudioContext, options?: ChannelMergerOptions) => ChannelMergerNode;
94
+ /**
95
+ * Map mute value to gain value
96
+ *
97
+ * ```
98
+ * `true` -> 0
99
+ * `false` -> 1
100
+ * ```
101
+ */
102
+ export declare const muteToGain: (mute: boolean) => number;
103
+ /**
104
+ * Calculate the timeout based on the provided data and returns a timeout in
105
+ * milliseconds with compensation added
106
+ *
107
+ * @param targetTime - The target timeout after the compensation
108
+ * @param startTime - The start time of the last execution
109
+ * @param endTime - The end time of the last execution
110
+ */
111
+ export declare const calculateNextTimeout: (targetTime: number, startTime: number, endTime: number) => number;
112
+ type Timeouts = Pick<WindowOrWorkerGlobalScope, 'setTimeout' | 'clearTimeout'>;
113
+ /**
114
+ * @param delayInMS - Delay in terms of milliseconds
115
+ * @param params - The parameters to be passed to the provided callback
116
+ */
117
+ type DelayCallback<P extends unknown[], R> = (delayInMS: number, ...params: P) => Promise<void | R>;
118
+ /**
119
+ * Cancel the delay created by the @see {@link createDelayedCallback}, when it
120
+ * is invoked the ongoing delay will be resolved immediately
121
+ */
122
+ type CancelDelay = () => void;
123
+ /**
124
+ * Convert a callback to an async callback with delay added
125
+ *
126
+ * @param callback - The callback to be delayed
127
+ * @param options - The options to inject dependences
128
+ *
129
+ * @example
130
+ *
131
+ * ```typescript
132
+ * const getRandom = () => Math.random();
133
+ * const [delayGetRandom, cancelDelayGetRandom] = createDelayedCallback(getRandom);
134
+ *
135
+ * // Delay 500 ms to get the random number
136
+ * const random = await delayGetRandom(500);
137
+ * ```
138
+ */
139
+ export declare const createDelayedCallback: <R, P extends unknown[]>(callback: Callback<R, P>, { setTimeout, clearTimeout, }?: Partial<Timeouts>) => [DelayCallback<P, R>, CancelDelay];
140
+ type AsyncCallbackLoopOptions = Timeouts & Pick<Performance, 'now'> & {
141
+ frameRate: number;
142
+ };
143
+ /**
144
+ * Create an async callback loop to be called recursively with delay based on
145
+ * the `frameRate`
146
+ *
147
+ * @param callback - The callback to be invoked
148
+ * @param frameRate - The rate to be expected to invoke the `callback`
149
+ */
150
+ export declare const createAsyncCallbackLoop: <P extends unknown[], R extends Promise<unknown>>(callback: Callback<R, P>, frameRate: number, { setTimeout, clearTimeout, now, }?: Partial<AsyncCallbackLoopOptions>) => {
151
+ start: (...params: P) => Promise<void>;
152
+ stop: () => void;
153
+ frameRate: number;
154
+ };
155
+ export declare const DEFAULT_THROTTLE_MS = 3000;
156
+ /**
157
+ * A function to limit the provided callback being called too frequently, and
158
+ * assuming the function is called repeatably, and NOT for general purpose.
159
+ *
160
+ * @param callback - the callback to be called under the specified time
161
+ * @param throttleMs - the specified time for throttling
162
+ * @param clock - how to get the current time
163
+ */
164
+ export declare const throttleProcess: <P extends unknown[]>(callback: Callback<void, P>, throttleMs?: number, clock?: Clock) => (...params: P) => void;
165
+ type Unsubscribe = () => void;
166
+ /**
167
+ * Subscribe visibilitychange event
168
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event}
169
+ *
170
+ * @param callback - A callback to be called with `document.hidden` when the event is trigger
171
+ */
172
+ export declare const subscribeVisibilityChangeEvent: (callback: (hidden: boolean) => Promise<void>) => Unsubscribe;
173
+ export {};