@exode-team/react-recorder 1.1.11 → 1.1.12

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.
@@ -4,6 +4,8 @@
4
4
  * @author: exode <hello@exode.ru>
5
5
  */
6
6
  export declare const AUDIO_LEVEL_BARS = 40;
7
+ /** Waveform decoding resamples to this rate — only the amplitude envelope matters */
8
+ export declare const WAVEFORM_SAMPLE_RATE = 44100;
7
9
  export declare const createInitialLevels: () => number[];
8
10
  export declare const TIMELINE_SAMPLE_INTERVAL = 150;
9
11
  export declare const TIMELINE_BAR_WIDTH = 3;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,eAAO,MAAM,mBAAmB,QAAO,MAAM,EAAuD,CAAC;AAErG,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,uBAAuB,KAAK,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,qFAAqF;AACrF,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAE1C,eAAO,MAAM,mBAAmB,QAAO,MAAM,EAAuD,CAAC;AAErG,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,uBAAuB,KAAK,CAAC"}
package/dist/index.cjs CHANGED
@@ -184,6 +184,8 @@ const revokeObjectURL = (url) => {
184
184
  * @author: exode <hello@exode.ru>
185
185
  */
186
186
  const AUDIO_LEVEL_BARS = 40;
187
+ /** Waveform decoding resamples to this rate — only the amplitude envelope matters */
188
+ const WAVEFORM_SAMPLE_RATE = 44100;
187
189
  const createInitialLevels = () => Array.from({ length: AUDIO_LEVEL_BARS }, () => 0);
188
190
  const TIMELINE_SAMPLE_INTERVAL = 150;
189
191
  const TIMELINE_BAR_WIDTH = 3;
@@ -290,32 +292,33 @@ const decodeSkippingJunk = async (context, blob) => {
290
292
  }
291
293
  };
292
294
  const decodeAudioLevels = async (blob, barCount = AUDIO_LEVEL_BARS) => {
293
- const context = new AudioContext();
294
- try {
295
- const audioBuffer = await decodeSkippingJunk(context, blob);
296
- const channelData = audioBuffer.getChannelData(0);
297
- if (!channelData.length) {
298
- return Array.from({ length: barCount }, () => 0);
299
- }
300
- const levels = [];
301
- const segmentLength = Math.max(1, Math.floor(channelData.length / barCount));
302
- for (let i = 0; i < barCount; i += 1) {
303
- const segmentStart = i * segmentLength;
304
- let sum = 0;
305
- for (let j = 0; j < segmentLength; j += 1) {
306
- const sample = channelData[segmentStart + j];
307
- if (sample !== undefined) {
308
- sum += Math.abs(sample);
309
- }
295
+ /**
296
+ * Offline context stays out of the audio session. A realtime AudioContext
297
+ * registers as a WebAudio source, which pins WebKit to the AmbientSound
298
+ * category and leaves media playback silent inside iOS apps — including
299
+ * iPad apps running on macOS.
300
+ */
301
+ const context = new OfflineAudioContext(1, 1, WAVEFORM_SAMPLE_RATE);
302
+ const audioBuffer = await decodeSkippingJunk(context, blob);
303
+ const channelData = audioBuffer.getChannelData(0);
304
+ if (!channelData.length) {
305
+ return Array.from({ length: barCount }, () => 0);
306
+ }
307
+ const levels = [];
308
+ const segmentLength = Math.max(1, Math.floor(channelData.length / barCount));
309
+ for (let i = 0; i < barCount; i += 1) {
310
+ const segmentStart = i * segmentLength;
311
+ let sum = 0;
312
+ for (let j = 0; j < segmentLength; j += 1) {
313
+ const sample = channelData[segmentStart + j];
314
+ if (sample !== undefined) {
315
+ sum += Math.abs(sample);
310
316
  }
311
- const average = sum / segmentLength;
312
- levels.push(Math.min(100, average * 200));
313
317
  }
314
- return levels;
315
- }
316
- finally {
317
- await context.close();
318
+ const average = sum / segmentLength;
319
+ levels.push(Math.min(100, average * 200));
318
320
  }
321
+ return levels;
319
322
  };
320
323
 
321
324
  /**