@capgo/capacitor-audio-recorder 8.0.12 → 8.1.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 +32 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/app/capgo/audiorecorder/CapacitorAudioRecorderPlugin.java +20 -1
- package/dist/docs.json +47 -0
- package/dist/esm/definitions.d.ts +35 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +7 -1
- package/dist/esm/web.js +59 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +59 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +59 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorAudioRecorderPlugin/CapacitorAudioRecorderPlugin.swift +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ npx cap sync
|
|
|
53
53
|
* [`stopRecording()`](#stoprecording)
|
|
54
54
|
* [`cancelRecording()`](#cancelrecording)
|
|
55
55
|
* [`getRecordingStatus()`](#getrecordingstatus)
|
|
56
|
+
* [`getCurrentAmplitude()`](#getcurrentamplitude)
|
|
56
57
|
* [`checkPermissions()`](#checkpermissions)
|
|
57
58
|
* [`requestPermissions()`](#requestpermissions)
|
|
58
59
|
* [`addListener('recordingError', ...)`](#addlistenerrecordingerror-)
|
|
@@ -157,6 +158,28 @@ Retrieve the current recording status.
|
|
|
157
158
|
--------------------
|
|
158
159
|
|
|
159
160
|
|
|
161
|
+
### getCurrentAmplitude()
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
getCurrentAmplitude() => Promise<GetCurrentAmplitudeResult>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Retrieve the current input amplitude (microphone level) as a normalized
|
|
168
|
+
number in the `[0, 1]` range.
|
|
169
|
+
|
|
170
|
+
Intended for driving live visualizations such as VU meters or waveforms
|
|
171
|
+
while recording. Returns `0` when no recording is active. Designed for
|
|
172
|
+
UI-rate polling — a 60–100 ms interval is a good starting point for a
|
|
173
|
+
waveform. Avoid calling it in a tight loop; each call crosses the
|
|
174
|
+
JS/native bridge.
|
|
175
|
+
|
|
176
|
+
**Returns:** <code>Promise<<a href="#getcurrentamplituderesult">GetCurrentAmplitudeResult</a>></code>
|
|
177
|
+
|
|
178
|
+
**Since:** 8.1.0
|
|
179
|
+
|
|
180
|
+
--------------------
|
|
181
|
+
|
|
182
|
+
|
|
160
183
|
### checkPermissions()
|
|
161
184
|
|
|
162
185
|
```typescript
|
|
@@ -310,6 +333,15 @@ Result returned by {@link CapacitorAudioRecorderPlugin.getRecordingStatus}.
|
|
|
310
333
|
| **`status`** | <code><a href="#recordingstatus">RecordingStatus</a></code> | The current recording status. | 1.0.0 |
|
|
311
334
|
|
|
312
335
|
|
|
336
|
+
#### GetCurrentAmplitudeResult
|
|
337
|
+
|
|
338
|
+
Result returned by {@link CapacitorAudioRecorderPlugin.getCurrentAmplitude}.
|
|
339
|
+
|
|
340
|
+
| Prop | Type | Description | Since |
|
|
341
|
+
| ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
342
|
+
| **`value`** | <code>number</code> | The current input amplitude normalized to the `[0, 1]` range, where `0` represents silence and `1` represents the maximum level the platform can report. The value is `0` when no recording is active. Note: the source signal differs between platforms — Android reports the peak sample amplitude since the last call, iOS reports the average power in dB converted to linear, and Web reports the RMS of the latest frame. Consumers that need cross-platform parity may want to apply a per-platform scaling curve. | 8.1.0 |
|
|
343
|
+
|
|
344
|
+
|
|
313
345
|
#### PermissionStatus
|
|
314
346
|
|
|
315
347
|
Permission information returned by {@link CapacitorAudioRecorderPlugin.checkPermissions}
|
|
@@ -24,7 +24,7 @@ import java.util.Locale;
|
|
|
24
24
|
)
|
|
25
25
|
public class CapacitorAudioRecorderPlugin extends com.getcapacitor.Plugin {
|
|
26
26
|
|
|
27
|
-
private final String pluginVersion = "8.0
|
|
27
|
+
private final String pluginVersion = "8.1.0";
|
|
28
28
|
|
|
29
29
|
private enum RecordingStatus {
|
|
30
30
|
INACTIVE,
|
|
@@ -155,6 +155,25 @@ public class CapacitorAudioRecorderPlugin extends com.getcapacitor.Plugin {
|
|
|
155
155
|
call.resolve(result);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
@PluginMethod
|
|
159
|
+
public void getCurrentAmplitude(PluginCall call) {
|
|
160
|
+
JSObject result = new JSObject();
|
|
161
|
+
if (mediaRecorder == null || status != RecordingStatus.RECORDING) {
|
|
162
|
+
result.put("value", 0.0);
|
|
163
|
+
call.resolve(result);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
double value;
|
|
167
|
+
try {
|
|
168
|
+
int peak = mediaRecorder.getMaxAmplitude();
|
|
169
|
+
value = Math.max(0.0, Math.min(1.0, peak / 32767.0));
|
|
170
|
+
} catch (IllegalStateException ex) {
|
|
171
|
+
value = 0.0;
|
|
172
|
+
}
|
|
173
|
+
result.put("value", value);
|
|
174
|
+
call.resolve(result);
|
|
175
|
+
}
|
|
176
|
+
|
|
158
177
|
@PluginMethod
|
|
159
178
|
public void checkPermissions(PluginCall call) {
|
|
160
179
|
PermissionState state = getPermissionState("microphone");
|
package/dist/docs.json
CHANGED
|
@@ -120,6 +120,27 @@
|
|
|
120
120
|
],
|
|
121
121
|
"slug": "getrecordingstatus"
|
|
122
122
|
},
|
|
123
|
+
{
|
|
124
|
+
"name": "getCurrentAmplitude",
|
|
125
|
+
"signature": "() => Promise<GetCurrentAmplitudeResult>",
|
|
126
|
+
"parameters": [],
|
|
127
|
+
"returns": "Promise<GetCurrentAmplitudeResult>",
|
|
128
|
+
"tags": [
|
|
129
|
+
{
|
|
130
|
+
"name": "returns",
|
|
131
|
+
"text": "The current amplitude."
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "since",
|
|
135
|
+
"text": "8.1.0"
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
"docs": "Retrieve the current input amplitude (microphone level) as a normalized\nnumber in the `[0, 1]` range.\n\nIntended for driving live visualizations such as VU meters or waveforms\nwhile recording. Returns `0` when no recording is active. Designed for\nUI-rate polling — a 60–100 ms interval is a good starting point for a\nwaveform. Avoid calling it in a tight loop; each call crosses the\nJS/native bridge.",
|
|
139
|
+
"complexTypes": [
|
|
140
|
+
"GetCurrentAmplitudeResult"
|
|
141
|
+
],
|
|
142
|
+
"slug": "getcurrentamplitude"
|
|
143
|
+
},
|
|
123
144
|
{
|
|
124
145
|
"name": "checkPermissions",
|
|
125
146
|
"signature": "() => Promise<PermissionStatus>",
|
|
@@ -424,6 +445,32 @@
|
|
|
424
445
|
}
|
|
425
446
|
]
|
|
426
447
|
},
|
|
448
|
+
{
|
|
449
|
+
"name": "GetCurrentAmplitudeResult",
|
|
450
|
+
"slug": "getcurrentamplituderesult",
|
|
451
|
+
"docs": "Result returned by {@link CapacitorAudioRecorderPlugin.getCurrentAmplitude}.",
|
|
452
|
+
"tags": [
|
|
453
|
+
{
|
|
454
|
+
"text": "8.1.0",
|
|
455
|
+
"name": "since"
|
|
456
|
+
}
|
|
457
|
+
],
|
|
458
|
+
"methods": [],
|
|
459
|
+
"properties": [
|
|
460
|
+
{
|
|
461
|
+
"name": "value",
|
|
462
|
+
"tags": [
|
|
463
|
+
{
|
|
464
|
+
"text": "8.1.0",
|
|
465
|
+
"name": "since"
|
|
466
|
+
}
|
|
467
|
+
],
|
|
468
|
+
"docs": "The current input amplitude normalized to the `[0, 1]` range, where `0`\nrepresents silence and `1` represents the maximum level the platform can\nreport. The value is `0` when no recording is active.\n\nNote: the source signal differs between platforms — Android reports the\npeak sample amplitude since the last call, iOS reports the average power\nin dB converted to linear, and Web reports the RMS of the latest frame.\nConsumers that need cross-platform parity may want to apply a\nper-platform scaling curve.",
|
|
469
|
+
"complexTypes": [],
|
|
470
|
+
"type": "number"
|
|
471
|
+
}
|
|
472
|
+
]
|
|
473
|
+
},
|
|
427
474
|
{
|
|
428
475
|
"name": "PermissionStatus",
|
|
429
476
|
"slug": "permissionstatus",
|
|
@@ -12,6 +12,27 @@ export interface GetRecordingStatusResult {
|
|
|
12
12
|
*/
|
|
13
13
|
status: RecordingStatus;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Result returned by {@link CapacitorAudioRecorderPlugin.getCurrentAmplitude}.
|
|
17
|
+
*
|
|
18
|
+
* @since 8.1.0
|
|
19
|
+
*/
|
|
20
|
+
export interface GetCurrentAmplitudeResult {
|
|
21
|
+
/**
|
|
22
|
+
* The current input amplitude normalized to the `[0, 1]` range, where `0`
|
|
23
|
+
* represents silence and `1` represents the maximum level the platform can
|
|
24
|
+
* report. The value is `0` when no recording is active.
|
|
25
|
+
*
|
|
26
|
+
* Note: the source signal differs between platforms — Android reports the
|
|
27
|
+
* peak sample amplitude since the last call, iOS reports the average power
|
|
28
|
+
* in dB converted to linear, and Web reports the RMS of the latest frame.
|
|
29
|
+
* Consumers that need cross-platform parity may want to apply a
|
|
30
|
+
* per-platform scaling curve.
|
|
31
|
+
*
|
|
32
|
+
* @since 8.1.0
|
|
33
|
+
*/
|
|
34
|
+
value: number;
|
|
35
|
+
}
|
|
15
36
|
/**
|
|
16
37
|
* Options accepted by {@link CapacitorAudioRecorderPlugin.startRecording}.
|
|
17
38
|
*
|
|
@@ -192,6 +213,20 @@ export interface CapacitorAudioRecorderPlugin {
|
|
|
192
213
|
* @since 1.0.0
|
|
193
214
|
*/
|
|
194
215
|
getRecordingStatus(): Promise<GetRecordingStatusResult>;
|
|
216
|
+
/**
|
|
217
|
+
* Retrieve the current input amplitude (microphone level) as a normalized
|
|
218
|
+
* number in the `[0, 1]` range.
|
|
219
|
+
*
|
|
220
|
+
* Intended for driving live visualizations such as VU meters or waveforms
|
|
221
|
+
* while recording. Returns `0` when no recording is active. Designed for
|
|
222
|
+
* UI-rate polling — a 60–100 ms interval is a good starting point for a
|
|
223
|
+
* waveform. Avoid calling it in a tight loop; each call crosses the
|
|
224
|
+
* JS/native bridge.
|
|
225
|
+
*
|
|
226
|
+
* @returns The current amplitude.
|
|
227
|
+
* @since 8.1.0
|
|
228
|
+
*/
|
|
229
|
+
getCurrentAmplitude(): Promise<GetCurrentAmplitudeResult>;
|
|
195
230
|
/**
|
|
196
231
|
* Return the current permission state for accessing the microphone.
|
|
197
232
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA2IA;;;;GAIG;AACH,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,wCAAqB,CAAA;IACrB,0CAAuB,CAAA;IACvB,oCAAiB,CAAA;AACnB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,0BASX;AATD,WAAY,0BAA0B;IACpC,6DAA+B,CAAA;IAC/B,gEAAkC,CAAA;IAClC,yEAA2C,CAAA;IAC3C,qEAAuC,CAAA;IACvC,wDAA0B,CAAA;IAC1B,iHAAmF,CAAA;IACnF,+DAAiC,CAAA;IACjC,4GAA8E,CAAA;AAChF,CAAC,EATW,0BAA0B,KAA1B,0BAA0B,QASrC;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,0CAAsB,CAAA;IACtB,+CAA2B,CAAA;IAC3B,gDAA4B,CAAA;IAC5B,4CAAwB,CAAA;IACxB,sDAAkC,CAAA;IAClC,4CAAwB,CAAA;AAC1B,CAAC,EARW,gBAAgB,KAAhB,gBAAgB,QAQ3B","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Result returned by {@link CapacitorAudioRecorderPlugin.getRecordingStatus}.\n *\n * @since 1.0.0\n */\nexport interface GetRecordingStatusResult {\n /**\n * The current recording status.\n *\n * @since 1.0.0\n */\n status: RecordingStatus;\n}\n\n/**\n * Result returned by {@link CapacitorAudioRecorderPlugin.getCurrentAmplitude}.\n *\n * @since 8.1.0\n */\nexport interface GetCurrentAmplitudeResult {\n /**\n * The current input amplitude normalized to the `[0, 1]` range, where `0`\n * represents silence and `1` represents the maximum level the platform can\n * report. The value is `0` when no recording is active.\n *\n * Note: the source signal differs between platforms — Android reports the\n * peak sample amplitude since the last call, iOS reports the average power\n * in dB converted to linear, and Web reports the RMS of the latest frame.\n * Consumers that need cross-platform parity may want to apply a\n * per-platform scaling curve.\n *\n * @since 8.1.0\n */\n value: number;\n}\n\n/**\n * Options accepted by {@link CapacitorAudioRecorderPlugin.startRecording}.\n *\n * @since 1.0.0\n */\nexport interface StartRecordingOptions {\n /**\n * The audio session category options for recording. Only available on iOS.\n *\n * @since 1.0.0\n */\n audioSessionCategoryOptions?: AudioSessionCategoryOption[];\n\n /**\n * The audio session mode for recording. Only available on iOS.\n *\n * @since 1.0.0\n */\n audioSessionMode?: AudioSessionMode;\n\n /**\n * The audio bit rate in bytes per second.\n * Only available on Android and iOS.\n *\n * @since 1.0.0\n */\n bitRate?: number;\n\n /**\n * The audio sample rate in Hz.\n * Only available on Android and iOS.\n *\n * @since 1.0.0\n */\n sampleRate?: number;\n}\n\n/**\n * Result returned by {@link CapacitorAudioRecorderPlugin.stopRecording}.\n *\n * @since 1.0.0\n */\nexport interface StopRecordingResult {\n /**\n * The recorded audio as a Blob. Only available on Web.\n *\n * @since 1.0.0\n */\n blob?: Blob;\n\n /**\n * The duration of the recording in milliseconds.\n *\n * @since 1.0.0\n */\n duration?: number;\n\n /**\n * The URI pointing to the recorded file. Only available on Android and iOS.\n *\n * @since 1.0.0\n */\n uri?: string;\n}\n\n/**\n * Permission information returned by {@link CapacitorAudioRecorderPlugin.checkPermissions}\n * and {@link CapacitorAudioRecorderPlugin.requestPermissions}.\n *\n * @since 1.0.0\n */\nexport interface PermissionStatus {\n /**\n * The permission state for audio recording.\n *\n * @since 1.0.0\n */\n recordAudio: PermissionState;\n}\n\n/**\n * Event emitted when an error occurs during recording.\n *\n * @since 1.0.0\n */\nexport interface RecordingErrorEvent {\n /**\n * The error message.\n *\n * @since 1.0.0\n */\n message: string;\n}\n\n/**\n * Event emitted when a recording completes.\n *\n * @since 1.0.0\n */\nexport type RecordingStoppedEvent = StopRecordingResult;\n\n/**\n * The recording status.\n *\n * @since 1.0.0\n */\nexport enum RecordingStatus {\n Inactive = 'INACTIVE',\n Recording = 'RECORDING',\n Paused = 'PAUSED',\n}\n\n/**\n * Audio session category options available on iOS.\n *\n * @since 1.0.0\n */\nexport enum AudioSessionCategoryOption {\n AllowAirPlay = 'ALLOW_AIR_PLAY',\n AllowBluetooth = 'ALLOW_BLUETOOTH',\n AllowBluetoothA2DP = 'ALLOW_BLUETOOTH_A2DP',\n DefaultToSpeaker = 'DEFAULT_TO_SPEAKER',\n DuckOthers = 'DUCK_OTHERS',\n InterruptSpokenAudioAndMixWithOthers = 'INTERRUPT_SPOKEN_AUDIO_AND_MIX_WITH_OTHERS',\n MixWithOthers = 'MIX_WITH_OTHERS',\n OverrideMutedMicrophoneInterruption = 'OVERRIDE_MUTED_MICROPHONE_INTERRUPTION',\n}\n\n/**\n * Audio session modes available on iOS.\n *\n * @since 1.0.0\n */\nexport enum AudioSessionMode {\n Default = 'DEFAULT',\n GameChat = 'GAME_CHAT',\n Measurement = 'MEASUREMENT',\n SpokenAudio = 'SPOKEN_AUDIO',\n VideoChat = 'VIDEO_CHAT',\n VideoRecording = 'VIDEO_RECORDING',\n VoiceChat = 'VOICE_CHAT',\n}\n\n/**\n * Platform permission states supported by Capacitor.\n *\n * @since 1.0.0\n */\nexport type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';\n\n/**\n * Capacitor plugin contract for recording audio.\n *\n * @since 1.0.0\n */\nexport interface CapacitorAudioRecorderPlugin {\n /**\n * Start recording audio using the device microphone.\n *\n * @param options Recording configuration options.\n * @since 1.0.0\n */\n startRecording(options?: StartRecordingOptions): Promise<void>;\n\n /**\n * Pause the ongoing recording. Only available on Android (API 24+), iOS, and Web.\n *\n * @since 1.0.0\n */\n pauseRecording(): Promise<void>;\n\n /**\n * Resume a previously paused recording.\n *\n * @since 1.0.0\n */\n resumeRecording(): Promise<void>;\n\n /**\n * Stop the current recording and persist the recorded audio.\n *\n * @returns Recording metadata such as duration and URI/blob.\n * @since 1.0.0\n */\n stopRecording(): Promise<StopRecordingResult>;\n\n /**\n * Cancel the current recording and discard any captured audio.\n *\n * @since 1.0.0\n */\n cancelRecording(): Promise<void>;\n\n /**\n * Retrieve the current recording status.\n *\n * @since 1.0.0\n */\n getRecordingStatus(): Promise<GetRecordingStatusResult>;\n\n /**\n * Retrieve the current input amplitude (microphone level) as a normalized\n * number in the `[0, 1]` range.\n *\n * Intended for driving live visualizations such as VU meters or waveforms\n * while recording. Returns `0` when no recording is active. Designed for\n * UI-rate polling — a 60–100 ms interval is a good starting point for a\n * waveform. Avoid calling it in a tight loop; each call crosses the\n * JS/native bridge.\n *\n * @returns The current amplitude.\n * @since 8.1.0\n */\n getCurrentAmplitude(): Promise<GetCurrentAmplitudeResult>;\n\n /**\n * Return the current permission state for accessing the microphone.\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request permission to access the microphone.\n *\n * @since 1.0.0\n */\n requestPermissions(): Promise<PermissionStatus>;\n\n /**\n * Listen for recording errors.\n *\n * @since 1.0.0\n */\n addListener(\n eventName: 'recordingError',\n listenerFunc: (event: RecordingErrorEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for pause events emitted when a recording is paused.\n *\n * @since 1.0.0\n */\n addListener(eventName: 'recordingPaused', listenerFunc: () => void): Promise<PluginListenerHandle>;\n\n /**\n * Listen for recording completion events.\n *\n * @since 1.0.0\n */\n addListener(\n eventName: 'recordingStopped',\n listenerFunc: (event: RecordingStoppedEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Remove all registered listeners.\n *\n * @since 1.0.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version.\n *\n * @returns Promise that resolves with the plugin version\n * @since 1.0.0\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin, type PluginListenerHandle } from '@capacitor/core';
|
|
2
|
-
import type { CapacitorAudioRecorderPlugin, PermissionStatus, RecordingErrorEvent, RecordingStoppedEvent, StartRecordingOptions, StopRecordingResult } from './definitions';
|
|
2
|
+
import type { CapacitorAudioRecorderPlugin, GetCurrentAmplitudeResult, PermissionStatus, RecordingErrorEvent, RecordingStoppedEvent, StartRecordingOptions, StopRecordingResult } from './definitions';
|
|
3
3
|
import { RecordingStatus } from './definitions';
|
|
4
4
|
export declare class CapacitorAudioRecorderWeb extends WebPlugin implements CapacitorAudioRecorderPlugin {
|
|
5
5
|
private mediaRecorder;
|
|
@@ -11,6 +11,9 @@ export declare class CapacitorAudioRecorderWeb extends WebPlugin implements Capa
|
|
|
11
11
|
private accumulatedPauseDuration;
|
|
12
12
|
private stopResolver;
|
|
13
13
|
private stopRejector;
|
|
14
|
+
private audioContext;
|
|
15
|
+
private analyser;
|
|
16
|
+
private analyserBuffer;
|
|
14
17
|
startRecording(_options?: StartRecordingOptions): Promise<void>;
|
|
15
18
|
pauseRecording(): Promise<void>;
|
|
16
19
|
resumeRecording(): Promise<void>;
|
|
@@ -19,6 +22,7 @@ export declare class CapacitorAudioRecorderWeb extends WebPlugin implements Capa
|
|
|
19
22
|
getRecordingStatus(): Promise<{
|
|
20
23
|
status: RecordingStatus;
|
|
21
24
|
}>;
|
|
25
|
+
getCurrentAmplitude(): Promise<GetCurrentAmplitudeResult>;
|
|
22
26
|
checkPermissions(): Promise<PermissionStatus>;
|
|
23
27
|
requestPermissions(): Promise<PermissionStatus>;
|
|
24
28
|
addListener<T extends 'recordingError' | 'recordingPaused' | 'recordingStopped'>(eventName: T, listenerFunc: T extends 'recordingError' ? (event: RecordingErrorEvent) => void : T extends 'recordingStopped' ? (event: RecordingStoppedEvent) => void : () => void): Promise<PluginListenerHandle>;
|
|
@@ -31,6 +35,8 @@ export declare class CapacitorAudioRecorderWeb extends WebPlugin implements Capa
|
|
|
31
35
|
private buildStopResult;
|
|
32
36
|
private resetStopHandlers;
|
|
33
37
|
private resetState;
|
|
38
|
+
private setupAnalyser;
|
|
39
|
+
private teardownAnalyser;
|
|
34
40
|
private cleanupMediaStream;
|
|
35
41
|
private ensurePermission;
|
|
36
42
|
private getPermissionState;
|
package/dist/esm/web.js
CHANGED
|
@@ -12,6 +12,9 @@ export class CapacitorAudioRecorderWeb extends WebPlugin {
|
|
|
12
12
|
this.accumulatedPauseDuration = 0;
|
|
13
13
|
this.stopResolver = null;
|
|
14
14
|
this.stopRejector = null;
|
|
15
|
+
this.audioContext = null;
|
|
16
|
+
this.analyser = null;
|
|
17
|
+
this.analyserBuffer = null;
|
|
15
18
|
}
|
|
16
19
|
async startRecording(_options) {
|
|
17
20
|
var _a, _b;
|
|
@@ -63,6 +66,7 @@ export class CapacitorAudioRecorderWeb extends WebPlugin {
|
|
|
63
66
|
this.resetStopHandlers();
|
|
64
67
|
this.resetState();
|
|
65
68
|
});
|
|
69
|
+
this.setupAnalyser();
|
|
66
70
|
this.mediaRecorder.start();
|
|
67
71
|
this.status = RecordingStatus.Recording;
|
|
68
72
|
}
|
|
@@ -137,6 +141,18 @@ export class CapacitorAudioRecorderWeb extends WebPlugin {
|
|
|
137
141
|
async getRecordingStatus() {
|
|
138
142
|
return { status: this.status };
|
|
139
143
|
}
|
|
144
|
+
async getCurrentAmplitude() {
|
|
145
|
+
if (this.status !== RecordingStatus.Recording || !this.analyser || !this.analyserBuffer) {
|
|
146
|
+
return { value: 0 };
|
|
147
|
+
}
|
|
148
|
+
this.analyser.getFloatTimeDomainData(this.analyserBuffer);
|
|
149
|
+
let sumOfSquares = 0;
|
|
150
|
+
for (const sample of this.analyserBuffer) {
|
|
151
|
+
sumOfSquares += sample * sample;
|
|
152
|
+
}
|
|
153
|
+
const rms = Math.sqrt(sumOfSquares / this.analyserBuffer.length);
|
|
154
|
+
return { value: Math.max(0, Math.min(1, rms)) };
|
|
155
|
+
}
|
|
140
156
|
async checkPermissions() {
|
|
141
157
|
const state = await this.getPermissionState();
|
|
142
158
|
return { recordAudio: state };
|
|
@@ -192,6 +208,7 @@ export class CapacitorAudioRecorderWeb extends WebPlugin {
|
|
|
192
208
|
this.pausedTimestamp = null;
|
|
193
209
|
this.accumulatedPauseDuration = 0;
|
|
194
210
|
this.recordedChunks = [];
|
|
211
|
+
this.teardownAnalyser();
|
|
195
212
|
this.cleanupMediaStream();
|
|
196
213
|
if (this.mediaRecorder) {
|
|
197
214
|
const recorder = this.mediaRecorder;
|
|
@@ -201,6 +218,48 @@ export class CapacitorAudioRecorderWeb extends WebPlugin {
|
|
|
201
218
|
}
|
|
202
219
|
this.mediaRecorder = null;
|
|
203
220
|
}
|
|
221
|
+
setupAnalyser() {
|
|
222
|
+
if (!this.mediaStream) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const AudioContextCtor = typeof AudioContext !== 'undefined'
|
|
227
|
+
? AudioContext
|
|
228
|
+
: globalThis.webkitAudioContext;
|
|
229
|
+
if (!AudioContextCtor) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const context = new AudioContextCtor();
|
|
233
|
+
this.audioContext = context;
|
|
234
|
+
const source = context.createMediaStreamSource(this.mediaStream);
|
|
235
|
+
const analyser = context.createAnalyser();
|
|
236
|
+
analyser.fftSize = 1024;
|
|
237
|
+
source.connect(analyser);
|
|
238
|
+
this.analyser = analyser;
|
|
239
|
+
this.analyserBuffer = new Float32Array(new ArrayBuffer(analyser.fftSize * Float32Array.BYTES_PER_ELEMENT));
|
|
240
|
+
}
|
|
241
|
+
catch (_a) {
|
|
242
|
+
this.teardownAnalyser();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
teardownAnalyser() {
|
|
246
|
+
if (this.analyser) {
|
|
247
|
+
try {
|
|
248
|
+
this.analyser.disconnect();
|
|
249
|
+
}
|
|
250
|
+
catch (_a) {
|
|
251
|
+
// Ignored.
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
this.analyser = null;
|
|
255
|
+
this.analyserBuffer = null;
|
|
256
|
+
if (this.audioContext) {
|
|
257
|
+
void this.audioContext.close().catch(() => {
|
|
258
|
+
// Ignored.
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
this.audioContext = null;
|
|
262
|
+
}
|
|
204
263
|
cleanupMediaStream() {
|
|
205
264
|
if (this.mediaStream) {
|
|
206
265
|
this.mediaStream.getTracks().forEach((track) => track.stop());
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA6B,MAAM,iBAAiB,CAAC;AAWvE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IAAxD;;QACU,kBAAa,GAAyB,IAAI,CAAC;QAC3C,gBAAW,GAAuB,IAAI,CAAC;QACvC,mBAAc,GAAe,EAAE,CAAC;QAChC,WAAM,GAAoB,eAAe,CAAC,QAAQ,CAAC;QACnD,mBAAc,GAAkB,IAAI,CAAC;QACrC,oBAAe,GAAkB,IAAI,CAAC;QACtC,6BAAwB,GAAG,CAAC,CAAC;QAC7B,iBAAY,GAAmD,IAAI,CAAC;QACpE,iBAAY,GAAoC,IAAI,CAAC;IA4Q/D,CAAC;IA1QC,KAAK,CAAC,cAAc,CAAC,QAAgC;;QACnD,IAAI,IA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CAAC;YACpB,CAAC;QACH,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAEO,WAAW,CAAC,OAAe;QACjC,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC;QACvC,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin, type PluginListenerHandle } from '@capacitor/core';\n\nimport type {\n CapacitorAudioRecorderPlugin,\n PermissionState,\n PermissionStatus,\n RecordingErrorEvent,\n RecordingStoppedEvent,\n StartRecordingOptions,\n StopRecordingResult,\n} from './definitions';\nimport { RecordingStatus } from './definitions';\n\nexport class CapacitorAudioRecorderWeb extends WebPlugin implements CapacitorAudioRecorderPlugin {\n private mediaRecorder: MediaRecorder | null = null;\n private mediaStream: MediaStream | null = null;\n private recordedChunks: BlobPart[] = [];\n private status: RecordingStatus = RecordingStatus.Inactive;\n private startTimestamp: number | null = null;\n private pausedTimestamp: number | null = null;\n private accumulatedPauseDuration = 0;\n private stopResolver: ((result: StopRecordingResult) => void) | null = null;\n private stopRejector: ((reason?: any) => void) | null = null;\n\n async startRecording(_options?: StartRecordingOptions): Promise<void> {\n if (this.status === RecordingStatus.Recording || this.status === RecordingStatus.Paused) {\n throw this.unavailable('Recording already in progress.');\n }\n\n await this.ensurePermission(true);\n\n try {\n this.mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });\n } catch (error) {\n this.handleError(`Unable to acquire microphone: ${(error as Error)?.message ?? error}`);\n throw error;\n }\n\n const mimeType = this.pickMimeType();\n try {\n this.mediaRecorder = new MediaRecorder(this.mediaStream, mimeType ? { mimeType } : undefined);\n } catch (error) {\n this.cleanupMediaStream();\n this.handleError(`Unable to initialise MediaRecorder: ${(error as Error)?.message ?? error}`);\n throw error;\n }\n\n this.recordedChunks = [];\n this.startTimestamp = Date.now();\n this.accumulatedPauseDuration = 0;\n this.pausedTimestamp = null;\n\n this.mediaRecorder.addEventListener('dataavailable', (event: BlobEvent) => {\n if (event.data.size > 0) {\n this.recordedChunks.push(event.data);\n }\n });\n\n this.mediaRecorder.addEventListener('stop', () => {\n const result = this.buildStopResult();\n if (this.stopResolver) {\n this.stopResolver(result);\n }\n this.notifyListeners('recordingStopped', result as RecordingStoppedEvent);\n this.resetStopHandlers();\n this.resetState();\n });\n\n this.mediaRecorder.addEventListener('error', (event: Event) => {\n const message = (event as any)?.error?.message ?? 'Recording error.';\n this.handleError(message);\n if (this.stopRejector) {\n this.stopRejector(new Error(message));\n }\n this.resetStopHandlers();\n this.resetState();\n });\n\n this.mediaRecorder.start();\n this.status = RecordingStatus.Recording;\n }\n\n async pauseRecording(): Promise<void> {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Recording) {\n throw this.unavailable('No active recording to pause.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.pause();\n this.status = RecordingStatus.Paused;\n this.pausedTimestamp = Date.now();\n this.notifyListeners('recordingPaused', {});\n } else {\n throw this.unavailable('Pausing recordings is not supported in this browser.');\n }\n }\n\n async resumeRecording(): Promise<void> {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Paused) {\n throw this.unavailable('No paused recording to resume.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.resume();\n if (this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n }\n this.pausedTimestamp = null;\n this.status = RecordingStatus.Recording;\n } else {\n throw this.unavailable('Resuming recordings is not supported in this browser.');\n }\n }\n\n async stopRecording(): Promise<StopRecordingResult> {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n throw this.unavailable('No active recording to stop.');\n }\n\n if (this.status === RecordingStatus.Paused && this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n this.pausedTimestamp = null;\n }\n\n const stopPromise = new Promise<StopRecordingResult>((resolve, reject) => {\n this.stopResolver = resolve;\n this.stopRejector = reject;\n });\n\n try {\n this.mediaRecorder.stop();\n } catch (error) {\n this.resetStopHandlers();\n this.resetState();\n this.handleError(`Unable to stop recorder: ${(error as Error)?.message ?? error}`);\n throw error;\n }\n\n return stopPromise;\n }\n\n async cancelRecording(): Promise<void> {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n this.resetState();\n return;\n }\n\n try {\n this.mediaRecorder.stop();\n } catch {\n // Ignored.\n }\n\n this.resetStopHandlers();\n this.resetState();\n }\n\n async getRecordingStatus(): Promise<{ status: RecordingStatus }> {\n return { status: this.status };\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n const state = await this.getPermissionState();\n return { recordAudio: state };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n const state = await this.ensurePermission(true);\n return { recordAudio: state };\n }\n\n async addListener<T extends 'recordingError' | 'recordingPaused' | 'recordingStopped'>(\n eventName: T,\n listenerFunc: T extends 'recordingError'\n ? (event: RecordingErrorEvent) => void\n : T extends 'recordingStopped'\n ? (event: RecordingStoppedEvent) => void\n : () => void,\n ): Promise<PluginListenerHandle> {\n return super.addListener(eventName, listenerFunc as any);\n }\n\n async removeAllListeners(): Promise<void> {\n await super.removeAllListeners();\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n\n // Helpers\n\n private supportsRecorderPause(): boolean {\n return (\n !!this.mediaRecorder &&\n typeof this.mediaRecorder.pause === 'function' &&\n typeof this.mediaRecorder.resume === 'function'\n );\n }\n\n private pickMimeType(): string | undefined {\n const preferred = ['audio/webm;codecs=opus', 'audio/ogg;codecs=opus', 'audio/mp4'];\n for (const type of preferred) {\n if ((window as any).MediaRecorder && MediaRecorder.isTypeSupported && MediaRecorder.isTypeSupported(type)) {\n return type;\n }\n }\n return undefined;\n }\n\n private buildStopResult(): StopRecordingResult {\n const blob =\n this.recordedChunks.length > 0\n ? new Blob(this.recordedChunks, { type: this.pickMimeType() || 'audio/webm' })\n : undefined;\n let duration: number | undefined;\n if (this.startTimestamp) {\n duration = Date.now() - this.startTimestamp - this.accumulatedPauseDuration;\n }\n return {\n blob,\n duration,\n };\n }\n\n private resetStopHandlers(): void {\n this.stopResolver = null;\n this.stopRejector = null;\n }\n\n private resetState(): void {\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.recordedChunks = [];\n this.cleanupMediaStream();\n if (this.mediaRecorder) {\n const recorder = this.mediaRecorder;\n recorder.ondataavailable = null;\n recorder.onstop = null;\n recorder.onerror = null;\n }\n this.mediaRecorder = null;\n }\n\n private cleanupMediaStream(): void {\n if (this.mediaStream) {\n this.mediaStream.getTracks().forEach((track) => track.stop());\n }\n this.mediaStream = null;\n }\n\n private async ensurePermission(request: boolean): Promise<PermissionState> {\n const currentState = await this.getPermissionState();\n if (currentState === 'granted' || !request) {\n return currentState;\n }\n\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n stream.getTracks().forEach((track) => track.stop());\n return 'granted';\n } catch (error) {\n return 'denied';\n }\n }\n\n private async getPermissionState(): Promise<PermissionState> {\n if (!navigator.permissions?.query) {\n return 'prompt';\n }\n\n try {\n const result = await navigator.permissions.query({ name: 'microphone' as PermissionName });\n switch (result.state) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n } catch {\n return 'prompt';\n }\n }\n\n private handleError(message: string): void {\n this.status = RecordingStatus.Inactive;\n this.notifyListeners('recordingError', { message });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA6B,MAAM,iBAAiB,CAAC;AAYvE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IAAxD;;QACU,kBAAa,GAAyB,IAAI,CAAC;QAC3C,gBAAW,GAAuB,IAAI,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C;gBACnB,KAAK,QAAQ;oBACX,OAAO,QAAQ,CAAC;gBAClB;oBACE,OAAO,QAAQ,CAAC;YACpB,CAAC;QACH,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAEO,WAAW,CAAC,OAAe;QACjC,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC;QACvC,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin, type PluginListenerHandle } from '@capacitor/core';\n\nimport type {\n CapacitorAudioRecorderPlugin,\n GetCurrentAmplitudeResult,\n PermissionState,\n PermissionStatus,\n RecordingErrorEvent,\n RecordingStoppedEvent,\n StartRecordingOptions,\n StopRecordingResult,\n} from './definitions';\nimport { RecordingStatus } from './definitions';\n\nexport class CapacitorAudioRecorderWeb extends WebPlugin implements CapacitorAudioRecorderPlugin {\n private mediaRecorder: MediaRecorder | null = null;\n private mediaStream: MediaStream | null = null;\n private recordedChunks: BlobPart[] = [];\n private status: RecordingStatus = RecordingStatus.Inactive;\n private startTimestamp: number | null = null;\n private pausedTimestamp: number | null = null;\n private accumulatedPauseDuration = 0;\n private stopResolver: ((result: StopRecordingResult) => void) | null = null;\n private stopRejector: ((reason?: any) => void) | null = null;\n private audioContext: AudioContext | null = null;\n private analyser: AnalyserNode | null = null;\n private analyserBuffer: Float32Array<ArrayBuffer> | null = null;\n\n async startRecording(_options?: StartRecordingOptions): Promise<void> {\n if (this.status === RecordingStatus.Recording || this.status === RecordingStatus.Paused) {\n throw this.unavailable('Recording already in progress.');\n }\n\n await this.ensurePermission(true);\n\n try {\n this.mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });\n } catch (error) {\n this.handleError(`Unable to acquire microphone: ${(error as Error)?.message ?? error}`);\n throw error;\n }\n\n const mimeType = this.pickMimeType();\n try {\n this.mediaRecorder = new MediaRecorder(this.mediaStream, mimeType ? { mimeType } : undefined);\n } catch (error) {\n this.cleanupMediaStream();\n this.handleError(`Unable to initialise MediaRecorder: ${(error as Error)?.message ?? error}`);\n throw error;\n }\n\n this.recordedChunks = [];\n this.startTimestamp = Date.now();\n this.accumulatedPauseDuration = 0;\n this.pausedTimestamp = null;\n\n this.mediaRecorder.addEventListener('dataavailable', (event: BlobEvent) => {\n if (event.data.size > 0) {\n this.recordedChunks.push(event.data);\n }\n });\n\n this.mediaRecorder.addEventListener('stop', () => {\n const result = this.buildStopResult();\n if (this.stopResolver) {\n this.stopResolver(result);\n }\n this.notifyListeners('recordingStopped', result as RecordingStoppedEvent);\n this.resetStopHandlers();\n this.resetState();\n });\n\n this.mediaRecorder.addEventListener('error', (event: Event) => {\n const message = (event as any)?.error?.message ?? 'Recording error.';\n this.handleError(message);\n if (this.stopRejector) {\n this.stopRejector(new Error(message));\n }\n this.resetStopHandlers();\n this.resetState();\n });\n\n this.setupAnalyser();\n\n this.mediaRecorder.start();\n this.status = RecordingStatus.Recording;\n }\n\n async pauseRecording(): Promise<void> {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Recording) {\n throw this.unavailable('No active recording to pause.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.pause();\n this.status = RecordingStatus.Paused;\n this.pausedTimestamp = Date.now();\n this.notifyListeners('recordingPaused', {});\n } else {\n throw this.unavailable('Pausing recordings is not supported in this browser.');\n }\n }\n\n async resumeRecording(): Promise<void> {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Paused) {\n throw this.unavailable('No paused recording to resume.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.resume();\n if (this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n }\n this.pausedTimestamp = null;\n this.status = RecordingStatus.Recording;\n } else {\n throw this.unavailable('Resuming recordings is not supported in this browser.');\n }\n }\n\n async stopRecording(): Promise<StopRecordingResult> {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n throw this.unavailable('No active recording to stop.');\n }\n\n if (this.status === RecordingStatus.Paused && this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n this.pausedTimestamp = null;\n }\n\n const stopPromise = new Promise<StopRecordingResult>((resolve, reject) => {\n this.stopResolver = resolve;\n this.stopRejector = reject;\n });\n\n try {\n this.mediaRecorder.stop();\n } catch (error) {\n this.resetStopHandlers();\n this.resetState();\n this.handleError(`Unable to stop recorder: ${(error as Error)?.message ?? error}`);\n throw error;\n }\n\n return stopPromise;\n }\n\n async cancelRecording(): Promise<void> {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n this.resetState();\n return;\n }\n\n try {\n this.mediaRecorder.stop();\n } catch {\n // Ignored.\n }\n\n this.resetStopHandlers();\n this.resetState();\n }\n\n async getRecordingStatus(): Promise<{ status: RecordingStatus }> {\n return { status: this.status };\n }\n\n async getCurrentAmplitude(): Promise<GetCurrentAmplitudeResult> {\n if (this.status !== RecordingStatus.Recording || !this.analyser || !this.analyserBuffer) {\n return { value: 0 };\n }\n this.analyser.getFloatTimeDomainData(this.analyserBuffer);\n let sumOfSquares = 0;\n for (const sample of this.analyserBuffer) {\n sumOfSquares += sample * sample;\n }\n const rms = Math.sqrt(sumOfSquares / this.analyserBuffer.length);\n return { value: Math.max(0, Math.min(1, rms)) };\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n const state = await this.getPermissionState();\n return { recordAudio: state };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n const state = await this.ensurePermission(true);\n return { recordAudio: state };\n }\n\n async addListener<T extends 'recordingError' | 'recordingPaused' | 'recordingStopped'>(\n eventName: T,\n listenerFunc: T extends 'recordingError'\n ? (event: RecordingErrorEvent) => void\n : T extends 'recordingStopped'\n ? (event: RecordingStoppedEvent) => void\n : () => void,\n ): Promise<PluginListenerHandle> {\n return super.addListener(eventName, listenerFunc as any);\n }\n\n async removeAllListeners(): Promise<void> {\n await super.removeAllListeners();\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n\n // Helpers\n\n private supportsRecorderPause(): boolean {\n return (\n !!this.mediaRecorder &&\n typeof this.mediaRecorder.pause === 'function' &&\n typeof this.mediaRecorder.resume === 'function'\n );\n }\n\n private pickMimeType(): string | undefined {\n const preferred = ['audio/webm;codecs=opus', 'audio/ogg;codecs=opus', 'audio/mp4'];\n for (const type of preferred) {\n if ((window as any).MediaRecorder && MediaRecorder.isTypeSupported && MediaRecorder.isTypeSupported(type)) {\n return type;\n }\n }\n return undefined;\n }\n\n private buildStopResult(): StopRecordingResult {\n const blob =\n this.recordedChunks.length > 0\n ? new Blob(this.recordedChunks, { type: this.pickMimeType() || 'audio/webm' })\n : undefined;\n let duration: number | undefined;\n if (this.startTimestamp) {\n duration = Date.now() - this.startTimestamp - this.accumulatedPauseDuration;\n }\n return {\n blob,\n duration,\n };\n }\n\n private resetStopHandlers(): void {\n this.stopResolver = null;\n this.stopRejector = null;\n }\n\n private resetState(): void {\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.recordedChunks = [];\n this.teardownAnalyser();\n this.cleanupMediaStream();\n if (this.mediaRecorder) {\n const recorder = this.mediaRecorder;\n recorder.ondataavailable = null;\n recorder.onstop = null;\n recorder.onerror = null;\n }\n this.mediaRecorder = null;\n }\n\n private setupAnalyser(): void {\n if (!this.mediaStream) {\n return;\n }\n try {\n const AudioContextCtor: typeof AudioContext | undefined =\n typeof AudioContext !== 'undefined'\n ? AudioContext\n : (globalThis as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;\n if (!AudioContextCtor) {\n return;\n }\n const context = new AudioContextCtor();\n this.audioContext = context;\n const source = context.createMediaStreamSource(this.mediaStream);\n const analyser = context.createAnalyser();\n analyser.fftSize = 1024;\n source.connect(analyser);\n this.analyser = analyser;\n this.analyserBuffer = new Float32Array(new ArrayBuffer(analyser.fftSize * Float32Array.BYTES_PER_ELEMENT));\n } catch {\n this.teardownAnalyser();\n }\n }\n\n private teardownAnalyser(): void {\n if (this.analyser) {\n try {\n this.analyser.disconnect();\n } catch {\n // Ignored.\n }\n }\n this.analyser = null;\n this.analyserBuffer = null;\n if (this.audioContext) {\n void this.audioContext.close().catch(() => {\n // Ignored.\n });\n }\n this.audioContext = null;\n }\n\n private cleanupMediaStream(): void {\n if (this.mediaStream) {\n this.mediaStream.getTracks().forEach((track) => track.stop());\n }\n this.mediaStream = null;\n }\n\n private async ensurePermission(request: boolean): Promise<PermissionState> {\n const currentState = await this.getPermissionState();\n if (currentState === 'granted' || !request) {\n return currentState;\n }\n\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n stream.getTracks().forEach((track) => track.stop());\n return 'granted';\n } catch (error) {\n return 'denied';\n }\n }\n\n private async getPermissionState(): Promise<PermissionState> {\n if (!navigator.permissions?.query) {\n return 'prompt';\n }\n\n try {\n const result = await navigator.permissions.query({ name: 'microphone' as PermissionName });\n switch (result.state) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n } catch {\n return 'prompt';\n }\n }\n\n private handleError(message: string): void {\n this.status = RecordingStatus.Inactive;\n this.notifyListeners('recordingError', { message });\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -61,6 +61,9 @@ class CapacitorAudioRecorderWeb extends core.WebPlugin {
|
|
|
61
61
|
this.accumulatedPauseDuration = 0;
|
|
62
62
|
this.stopResolver = null;
|
|
63
63
|
this.stopRejector = null;
|
|
64
|
+
this.audioContext = null;
|
|
65
|
+
this.analyser = null;
|
|
66
|
+
this.analyserBuffer = null;
|
|
64
67
|
}
|
|
65
68
|
async startRecording(_options) {
|
|
66
69
|
var _a, _b;
|
|
@@ -112,6 +115,7 @@ class CapacitorAudioRecorderWeb extends core.WebPlugin {
|
|
|
112
115
|
this.resetStopHandlers();
|
|
113
116
|
this.resetState();
|
|
114
117
|
});
|
|
118
|
+
this.setupAnalyser();
|
|
115
119
|
this.mediaRecorder.start();
|
|
116
120
|
this.status = exports.RecordingStatus.Recording;
|
|
117
121
|
}
|
|
@@ -186,6 +190,18 @@ class CapacitorAudioRecorderWeb extends core.WebPlugin {
|
|
|
186
190
|
async getRecordingStatus() {
|
|
187
191
|
return { status: this.status };
|
|
188
192
|
}
|
|
193
|
+
async getCurrentAmplitude() {
|
|
194
|
+
if (this.status !== exports.RecordingStatus.Recording || !this.analyser || !this.analyserBuffer) {
|
|
195
|
+
return { value: 0 };
|
|
196
|
+
}
|
|
197
|
+
this.analyser.getFloatTimeDomainData(this.analyserBuffer);
|
|
198
|
+
let sumOfSquares = 0;
|
|
199
|
+
for (const sample of this.analyserBuffer) {
|
|
200
|
+
sumOfSquares += sample * sample;
|
|
201
|
+
}
|
|
202
|
+
const rms = Math.sqrt(sumOfSquares / this.analyserBuffer.length);
|
|
203
|
+
return { value: Math.max(0, Math.min(1, rms)) };
|
|
204
|
+
}
|
|
189
205
|
async checkPermissions() {
|
|
190
206
|
const state = await this.getPermissionState();
|
|
191
207
|
return { recordAudio: state };
|
|
@@ -241,6 +257,7 @@ class CapacitorAudioRecorderWeb extends core.WebPlugin {
|
|
|
241
257
|
this.pausedTimestamp = null;
|
|
242
258
|
this.accumulatedPauseDuration = 0;
|
|
243
259
|
this.recordedChunks = [];
|
|
260
|
+
this.teardownAnalyser();
|
|
244
261
|
this.cleanupMediaStream();
|
|
245
262
|
if (this.mediaRecorder) {
|
|
246
263
|
const recorder = this.mediaRecorder;
|
|
@@ -250,6 +267,48 @@ class CapacitorAudioRecorderWeb extends core.WebPlugin {
|
|
|
250
267
|
}
|
|
251
268
|
this.mediaRecorder = null;
|
|
252
269
|
}
|
|
270
|
+
setupAnalyser() {
|
|
271
|
+
if (!this.mediaStream) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
const AudioContextCtor = typeof AudioContext !== 'undefined'
|
|
276
|
+
? AudioContext
|
|
277
|
+
: globalThis.webkitAudioContext;
|
|
278
|
+
if (!AudioContextCtor) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const context = new AudioContextCtor();
|
|
282
|
+
this.audioContext = context;
|
|
283
|
+
const source = context.createMediaStreamSource(this.mediaStream);
|
|
284
|
+
const analyser = context.createAnalyser();
|
|
285
|
+
analyser.fftSize = 1024;
|
|
286
|
+
source.connect(analyser);
|
|
287
|
+
this.analyser = analyser;
|
|
288
|
+
this.analyserBuffer = new Float32Array(new ArrayBuffer(analyser.fftSize * Float32Array.BYTES_PER_ELEMENT));
|
|
289
|
+
}
|
|
290
|
+
catch (_a) {
|
|
291
|
+
this.teardownAnalyser();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
teardownAnalyser() {
|
|
295
|
+
if (this.analyser) {
|
|
296
|
+
try {
|
|
297
|
+
this.analyser.disconnect();
|
|
298
|
+
}
|
|
299
|
+
catch (_a) {
|
|
300
|
+
// Ignored.
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
this.analyser = null;
|
|
304
|
+
this.analyserBuffer = null;
|
|
305
|
+
if (this.audioContext) {
|
|
306
|
+
void this.audioContext.close().catch(() => {
|
|
307
|
+
// Ignored.
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
this.audioContext = null;
|
|
311
|
+
}
|
|
253
312
|
cleanupMediaStream() {
|
|
254
313
|
if (this.mediaStream) {
|
|
255
314
|
this.mediaStream.getTracks().forEach((track) => track.stop());
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The recording status.\n *\n * @since 1.0.0\n */\nexport var RecordingStatus;\n(function (RecordingStatus) {\n RecordingStatus[\"Inactive\"] = \"INACTIVE\";\n RecordingStatus[\"Recording\"] = \"RECORDING\";\n RecordingStatus[\"Paused\"] = \"PAUSED\";\n})(RecordingStatus || (RecordingStatus = {}));\n/**\n * Audio session category options available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionCategoryOption;\n(function (AudioSessionCategoryOption) {\n AudioSessionCategoryOption[\"AllowAirPlay\"] = \"ALLOW_AIR_PLAY\";\n AudioSessionCategoryOption[\"AllowBluetooth\"] = \"ALLOW_BLUETOOTH\";\n AudioSessionCategoryOption[\"AllowBluetoothA2DP\"] = \"ALLOW_BLUETOOTH_A2DP\";\n AudioSessionCategoryOption[\"DefaultToSpeaker\"] = \"DEFAULT_TO_SPEAKER\";\n AudioSessionCategoryOption[\"DuckOthers\"] = \"DUCK_OTHERS\";\n AudioSessionCategoryOption[\"InterruptSpokenAudioAndMixWithOthers\"] = \"INTERRUPT_SPOKEN_AUDIO_AND_MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"MixWithOthers\"] = \"MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"OverrideMutedMicrophoneInterruption\"] = \"OVERRIDE_MUTED_MICROPHONE_INTERRUPTION\";\n})(AudioSessionCategoryOption || (AudioSessionCategoryOption = {}));\n/**\n * Audio session modes available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionMode;\n(function (AudioSessionMode) {\n AudioSessionMode[\"Default\"] = \"DEFAULT\";\n AudioSessionMode[\"GameChat\"] = \"GAME_CHAT\";\n AudioSessionMode[\"Measurement\"] = \"MEASUREMENT\";\n AudioSessionMode[\"SpokenAudio\"] = \"SPOKEN_AUDIO\";\n AudioSessionMode[\"VideoChat\"] = \"VIDEO_CHAT\";\n AudioSessionMode[\"VideoRecording\"] = \"VIDEO_RECORDING\";\n AudioSessionMode[\"VoiceChat\"] = \"VOICE_CHAT\";\n})(AudioSessionMode || (AudioSessionMode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudioRecorder = registerPlugin('CapacitorAudioRecorder', {\n web: () => import('./web').then((m) => new m.CapacitorAudioRecorderWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudioRecorder };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { RecordingStatus } from './definitions';\nexport class CapacitorAudioRecorderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.mediaRecorder = null;\n this.mediaStream = null;\n this.recordedChunks = [];\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.stopResolver = null;\n this.stopRejector = null;\n }\n async startRecording(_options) {\n var _a, _b;\n if (this.status === RecordingStatus.Recording || this.status === RecordingStatus.Paused) {\n throw this.unavailable('Recording already in progress.');\n }\n await this.ensurePermission(true);\n try {\n this.mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });\n }\n catch (error) {\n this.handleError(`Unable to acquire microphone: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n const mimeType = this.pickMimeType();\n try {\n this.mediaRecorder = new MediaRecorder(this.mediaStream, mimeType ? { mimeType } : undefined);\n }\n catch (error) {\n this.cleanupMediaStream();\n this.handleError(`Unable to initialise MediaRecorder: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);\n throw error;\n }\n this.recordedChunks = [];\n this.startTimestamp = Date.now();\n this.accumulatedPauseDuration = 0;\n this.pausedTimestamp = null;\n this.mediaRecorder.addEventListener('dataavailable', (event) => {\n if (event.data.size > 0) {\n this.recordedChunks.push(event.data);\n }\n });\n this.mediaRecorder.addEventListener('stop', () => {\n const result = this.buildStopResult();\n if (this.stopResolver) {\n this.stopResolver(result);\n }\n this.notifyListeners('recordingStopped', result);\n this.resetStopHandlers();\n this.resetState();\n });\n this.mediaRecorder.addEventListener('error', (event) => {\n var _a, _b;\n const message = (_b = (_a = event === null || event === void 0 ? void 0 : event.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Recording error.';\n this.handleError(message);\n if (this.stopRejector) {\n this.stopRejector(new Error(message));\n }\n this.resetStopHandlers();\n this.resetState();\n });\n this.mediaRecorder.start();\n this.status = RecordingStatus.Recording;\n }\n async pauseRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Recording) {\n throw this.unavailable('No active recording to pause.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.pause();\n this.status = RecordingStatus.Paused;\n this.pausedTimestamp = Date.now();\n this.notifyListeners('recordingPaused', {});\n }\n else {\n throw this.unavailable('Pausing recordings is not supported in this browser.');\n }\n }\n async resumeRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Paused) {\n throw this.unavailable('No paused recording to resume.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.resume();\n if (this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n }\n this.pausedTimestamp = null;\n this.status = RecordingStatus.Recording;\n }\n else {\n throw this.unavailable('Resuming recordings is not supported in this browser.');\n }\n }\n async stopRecording() {\n var _a;\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n throw this.unavailable('No active recording to stop.');\n }\n if (this.status === RecordingStatus.Paused && this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n this.pausedTimestamp = null;\n }\n const stopPromise = new Promise((resolve, reject) => {\n this.stopResolver = resolve;\n this.stopRejector = reject;\n });\n try {\n this.mediaRecorder.stop();\n }\n catch (error) {\n this.resetStopHandlers();\n this.resetState();\n this.handleError(`Unable to stop recorder: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n return stopPromise;\n }\n async cancelRecording() {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n this.resetState();\n return;\n }\n try {\n this.mediaRecorder.stop();\n }\n catch (_a) {\n // Ignored.\n }\n this.resetStopHandlers();\n this.resetState();\n }\n async getRecordingStatus() {\n return { status: this.status };\n }\n async checkPermissions() {\n const state = await this.getPermissionState();\n return { recordAudio: state };\n }\n async requestPermissions() {\n const state = await this.ensurePermission(true);\n return { recordAudio: state };\n }\n async addListener(eventName, listenerFunc) {\n return super.addListener(eventName, listenerFunc);\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n // Helpers\n supportsRecorderPause() {\n return (!!this.mediaRecorder &&\n typeof this.mediaRecorder.pause === 'function' &&\n typeof this.mediaRecorder.resume === 'function');\n }\n pickMimeType() {\n const preferred = ['audio/webm;codecs=opus', 'audio/ogg;codecs=opus', 'audio/mp4'];\n for (const type of preferred) {\n if (window.MediaRecorder && MediaRecorder.isTypeSupported && MediaRecorder.isTypeSupported(type)) {\n return type;\n }\n }\n return undefined;\n }\n buildStopResult() {\n const blob = this.recordedChunks.length > 0\n ? new Blob(this.recordedChunks, { type: this.pickMimeType() || 'audio/webm' })\n : undefined;\n let duration;\n if (this.startTimestamp) {\n duration = Date.now() - this.startTimestamp - this.accumulatedPauseDuration;\n }\n return {\n blob,\n duration,\n };\n }\n resetStopHandlers() {\n this.stopResolver = null;\n this.stopRejector = null;\n }\n resetState() {\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.recordedChunks = [];\n this.cleanupMediaStream();\n if (this.mediaRecorder) {\n const recorder = this.mediaRecorder;\n recorder.ondataavailable = null;\n recorder.onstop = null;\n recorder.onerror = null;\n }\n this.mediaRecorder = null;\n }\n cleanupMediaStream() {\n if (this.mediaStream) {\n this.mediaStream.getTracks().forEach((track) => track.stop());\n }\n this.mediaStream = null;\n }\n async ensurePermission(request) {\n const currentState = await this.getPermissionState();\n if (currentState === 'granted' || !request) {\n return currentState;\n }\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n stream.getTracks().forEach((track) => track.stop());\n return 'granted';\n }\n catch (error) {\n return 'denied';\n }\n }\n async getPermissionState() {\n var _a;\n if (!((_a = navigator.permissions) === null || _a === void 0 ? void 0 : _a.query)) {\n return 'prompt';\n }\n try {\n const result = await navigator.permissions.query({ name: 'microphone' });\n switch (result.state) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n catch (_b) {\n return 'prompt';\n }\n }\n handleError(message) {\n this.status = RecordingStatus.Inactive;\n this.notifyListeners('recordingError', { message });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["RecordingStatus","AudioSessionCategoryOption","AudioSessionMode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACWA;AACX,CAAC,UAAU,eAAe,EAAE;AAC5B,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU;AAC5C,IAAI,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW;AAC9C,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACxC,CAAC,EAAEA,uBAAe,KAAKA,uBAAe,GAAG,EAAE,CAAC,CAAC;AAC7C;AACA;AACA;AACA;AACA;AACWC;AACX,CAAC,UAAU,0BAA0B,EAAE;AACvC,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,gBAAgB;AACjE,IAAI,0BAA0B,CAAC,gBAAgB,CAAC,GAAG,iBAAiB;AACpE,IAAI,0BAA0B,CAAC,oBAAoB,CAAC,GAAG,sBAAsB;AAC7E,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,oBAAoB;AACzE,IAAI,0BAA0B,CAAC,YAAY,CAAC,GAAG,aAAa;AAC5D,IAAI,0BAA0B,CAAC,sCAAsC,CAAC,GAAG,4CAA4C;AACrH,IAAI,0BAA0B,CAAC,eAAe,CAAC,GAAG,iBAAiB;AACnE,IAAI,0BAA0B,CAAC,qCAAqC,CAAC,GAAG,wCAAwC;AAChH,CAAC,EAAEA,kCAA0B,KAAKA,kCAA0B,GAAG,EAAE,CAAC,CAAC;AACnE;AACA;AACA;AACA;AACA;AACWC;AACX,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O,EAAE,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The recording status.\n *\n * @since 1.0.0\n */\nexport var RecordingStatus;\n(function (RecordingStatus) {\n RecordingStatus[\"Inactive\"] = \"INACTIVE\";\n RecordingStatus[\"Recording\"] = \"RECORDING\";\n RecordingStatus[\"Paused\"] = \"PAUSED\";\n})(RecordingStatus || (RecordingStatus = {}));\n/**\n * Audio session category options available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionCategoryOption;\n(function (AudioSessionCategoryOption) {\n AudioSessionCategoryOption[\"AllowAirPlay\"] = \"ALLOW_AIR_PLAY\";\n AudioSessionCategoryOption[\"AllowBluetooth\"] = \"ALLOW_BLUETOOTH\";\n AudioSessionCategoryOption[\"AllowBluetoothA2DP\"] = \"ALLOW_BLUETOOTH_A2DP\";\n AudioSessionCategoryOption[\"DefaultToSpeaker\"] = \"DEFAULT_TO_SPEAKER\";\n AudioSessionCategoryOption[\"DuckOthers\"] = \"DUCK_OTHERS\";\n AudioSessionCategoryOption[\"InterruptSpokenAudioAndMixWithOthers\"] = \"INTERRUPT_SPOKEN_AUDIO_AND_MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"MixWithOthers\"] = \"MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"OverrideMutedMicrophoneInterruption\"] = \"OVERRIDE_MUTED_MICROPHONE_INTERRUPTION\";\n})(AudioSessionCategoryOption || (AudioSessionCategoryOption = {}));\n/**\n * Audio session modes available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionMode;\n(function (AudioSessionMode) {\n AudioSessionMode[\"Default\"] = \"DEFAULT\";\n AudioSessionMode[\"GameChat\"] = \"GAME_CHAT\";\n AudioSessionMode[\"Measurement\"] = \"MEASUREMENT\";\n AudioSessionMode[\"SpokenAudio\"] = \"SPOKEN_AUDIO\";\n AudioSessionMode[\"VideoChat\"] = \"VIDEO_CHAT\";\n AudioSessionMode[\"VideoRecording\"] = \"VIDEO_RECORDING\";\n AudioSessionMode[\"VoiceChat\"] = \"VOICE_CHAT\";\n})(AudioSessionMode || (AudioSessionMode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudioRecorder = registerPlugin('CapacitorAudioRecorder', {\n web: () => import('./web').then((m) => new m.CapacitorAudioRecorderWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudioRecorder };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { RecordingStatus } from './definitions';\nexport class CapacitorAudioRecorderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.mediaRecorder = null;\n this.mediaStream = null;\n this.recordedChunks = [];\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.stopResolver = null;\n this.stopRejector = null;\n this.audioContext = null;\n this.analyser = null;\n this.analyserBuffer = null;\n }\n async startRecording(_options) {\n var _a, _b;\n if (this.status === RecordingStatus.Recording || this.status === RecordingStatus.Paused) {\n throw this.unavailable('Recording already in progress.');\n }\n await this.ensurePermission(true);\n try {\n this.mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });\n }\n catch (error) {\n this.handleError(`Unable to acquire microphone: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n const mimeType = this.pickMimeType();\n try {\n this.mediaRecorder = new MediaRecorder(this.mediaStream, mimeType ? { mimeType } : undefined);\n }\n catch (error) {\n this.cleanupMediaStream();\n this.handleError(`Unable to initialise MediaRecorder: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);\n throw error;\n }\n this.recordedChunks = [];\n this.startTimestamp = Date.now();\n this.accumulatedPauseDuration = 0;\n this.pausedTimestamp = null;\n this.mediaRecorder.addEventListener('dataavailable', (event) => {\n if (event.data.size > 0) {\n this.recordedChunks.push(event.data);\n }\n });\n this.mediaRecorder.addEventListener('stop', () => {\n const result = this.buildStopResult();\n if (this.stopResolver) {\n this.stopResolver(result);\n }\n this.notifyListeners('recordingStopped', result);\n this.resetStopHandlers();\n this.resetState();\n });\n this.mediaRecorder.addEventListener('error', (event) => {\n var _a, _b;\n const message = (_b = (_a = event === null || event === void 0 ? void 0 : event.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Recording error.';\n this.handleError(message);\n if (this.stopRejector) {\n this.stopRejector(new Error(message));\n }\n this.resetStopHandlers();\n this.resetState();\n });\n this.setupAnalyser();\n this.mediaRecorder.start();\n this.status = RecordingStatus.Recording;\n }\n async pauseRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Recording) {\n throw this.unavailable('No active recording to pause.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.pause();\n this.status = RecordingStatus.Paused;\n this.pausedTimestamp = Date.now();\n this.notifyListeners('recordingPaused', {});\n }\n else {\n throw this.unavailable('Pausing recordings is not supported in this browser.');\n }\n }\n async resumeRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Paused) {\n throw this.unavailable('No paused recording to resume.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.resume();\n if (this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n }\n this.pausedTimestamp = null;\n this.status = RecordingStatus.Recording;\n }\n else {\n throw this.unavailable('Resuming recordings is not supported in this browser.');\n }\n }\n async stopRecording() {\n var _a;\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n throw this.unavailable('No active recording to stop.');\n }\n if (this.status === RecordingStatus.Paused && this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n this.pausedTimestamp = null;\n }\n const stopPromise = new Promise((resolve, reject) => {\n this.stopResolver = resolve;\n this.stopRejector = reject;\n });\n try {\n this.mediaRecorder.stop();\n }\n catch (error) {\n this.resetStopHandlers();\n this.resetState();\n this.handleError(`Unable to stop recorder: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n return stopPromise;\n }\n async cancelRecording() {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n this.resetState();\n return;\n }\n try {\n this.mediaRecorder.stop();\n }\n catch (_a) {\n // Ignored.\n }\n this.resetStopHandlers();\n this.resetState();\n }\n async getRecordingStatus() {\n return { status: this.status };\n }\n async getCurrentAmplitude() {\n if (this.status !== RecordingStatus.Recording || !this.analyser || !this.analyserBuffer) {\n return { value: 0 };\n }\n this.analyser.getFloatTimeDomainData(this.analyserBuffer);\n let sumOfSquares = 0;\n for (const sample of this.analyserBuffer) {\n sumOfSquares += sample * sample;\n }\n const rms = Math.sqrt(sumOfSquares / this.analyserBuffer.length);\n return { value: Math.max(0, Math.min(1, rms)) };\n }\n async checkPermissions() {\n const state = await this.getPermissionState();\n return { recordAudio: state };\n }\n async requestPermissions() {\n const state = await this.ensurePermission(true);\n return { recordAudio: state };\n }\n async addListener(eventName, listenerFunc) {\n return super.addListener(eventName, listenerFunc);\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n // Helpers\n supportsRecorderPause() {\n return (!!this.mediaRecorder &&\n typeof this.mediaRecorder.pause === 'function' &&\n typeof this.mediaRecorder.resume === 'function');\n }\n pickMimeType() {\n const preferred = ['audio/webm;codecs=opus', 'audio/ogg;codecs=opus', 'audio/mp4'];\n for (const type of preferred) {\n if (window.MediaRecorder && MediaRecorder.isTypeSupported && MediaRecorder.isTypeSupported(type)) {\n return type;\n }\n }\n return undefined;\n }\n buildStopResult() {\n const blob = this.recordedChunks.length > 0\n ? new Blob(this.recordedChunks, { type: this.pickMimeType() || 'audio/webm' })\n : undefined;\n let duration;\n if (this.startTimestamp) {\n duration = Date.now() - this.startTimestamp - this.accumulatedPauseDuration;\n }\n return {\n blob,\n duration,\n };\n }\n resetStopHandlers() {\n this.stopResolver = null;\n this.stopRejector = null;\n }\n resetState() {\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.recordedChunks = [];\n this.teardownAnalyser();\n this.cleanupMediaStream();\n if (this.mediaRecorder) {\n const recorder = this.mediaRecorder;\n recorder.ondataavailable = null;\n recorder.onstop = null;\n recorder.onerror = null;\n }\n this.mediaRecorder = null;\n }\n setupAnalyser() {\n if (!this.mediaStream) {\n return;\n }\n try {\n const AudioContextCtor = typeof AudioContext !== 'undefined'\n ? AudioContext\n : globalThis.webkitAudioContext;\n if (!AudioContextCtor) {\n return;\n }\n const context = new AudioContextCtor();\n this.audioContext = context;\n const source = context.createMediaStreamSource(this.mediaStream);\n const analyser = context.createAnalyser();\n analyser.fftSize = 1024;\n source.connect(analyser);\n this.analyser = analyser;\n this.analyserBuffer = new Float32Array(new ArrayBuffer(analyser.fftSize * Float32Array.BYTES_PER_ELEMENT));\n }\n catch (_a) {\n this.teardownAnalyser();\n }\n }\n teardownAnalyser() {\n if (this.analyser) {\n try {\n this.analyser.disconnect();\n }\n catch (_a) {\n // Ignored.\n }\n }\n this.analyser = null;\n this.analyserBuffer = null;\n if (this.audioContext) {\n void this.audioContext.close().catch(() => {\n // Ignored.\n });\n }\n this.audioContext = null;\n }\n cleanupMediaStream() {\n if (this.mediaStream) {\n this.mediaStream.getTracks().forEach((track) => track.stop());\n }\n this.mediaStream = null;\n }\n async ensurePermission(request) {\n const currentState = await this.getPermissionState();\n if (currentState === 'granted' || !request) {\n return currentState;\n }\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n stream.getTracks().forEach((track) => track.stop());\n return 'granted';\n }\n catch (error) {\n return 'denied';\n }\n }\n async getPermissionState() {\n var _a;\n if (!((_a = navigator.permissions) === null || _a === void 0 ? void 0 : _a.query)) {\n return 'prompt';\n }\n try {\n const result = await navigator.permissions.query({ name: 'microphone' });\n switch (result.state) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n catch (_b) {\n return 'prompt';\n }\n }\n handleError(message) {\n this.status = RecordingStatus.Inactive;\n this.notifyListeners('recordingError', { message });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["RecordingStatus","AudioSessionCategoryOption","AudioSessionMode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACWA;AACX,CAAC,UAAU,eAAe,EAAE;AAC5B,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU;AAC5C,IAAI,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW;AAC9C,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACxC,CAAC,EAAEA,uBAAe,KAAKA,uBAAe,GAAG,EAAE,CAAC,CAAC;AAC7C;AACA;AACA;AACA;AACA;AACWC;AACX,CAAC,UAAU,0BAA0B,EAAE;AACvC,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,gBAAgB;AACjE,IAAI,0BAA0B,CAAC,gBAAgB,CAAC,GAAG,iBAAiB;AACpE,IAAI,0BAA0B,CAAC,oBAAoB,CAAC,GAAG,sBAAsB;AAC7E,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,oBAAoB;AACzE,IAAI,0BAA0B,CAAC,YAAY,CAAC,GAAG,aAAa;AAC5D,IAAI,0BAA0B,CAAC,sCAAsC,CAAC,GAAG,4CAA4C;AACrH,IAAI,0BAA0B,CAAC,eAAe,CAAC,GAAG,iBAAiB;AACnE,IAAI,0BAA0B,CAAC,qCAAqC,CAAC,GAAG,wCAAwC;AAChH,CAAC,EAAEA,kCAA0B,KAAKA,kCAA0B,GAAG,EAAE,CAAC,CAAC;AACnE;AACA;AACA;AACA;AACA;AACWC;AACX,CAAC,UAAU,gBAAgB,EAAE;AAC7B,IAAI,gBAAgB,CAAC,SAAS,CAAC,GA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ector = null;
|
|
63
|
+
this.audioContext = null;
|
|
64
|
+
this.analyser = null;
|
|
65
|
+
this.analyserBuffer = null;
|
|
63
66
|
}
|
|
64
67
|
async startRecording(_options) {
|
|
65
68
|
var _a, _b;
|
|
@@ -111,6 +114,7 @@ var capacitorCapacitorAudioRecorder = (function (exports, core) {
|
|
|
111
114
|
this.resetStopHandlers();
|
|
112
115
|
this.resetState();
|
|
113
116
|
});
|
|
117
|
+
this.setupAnalyser();
|
|
114
118
|
this.mediaRecorder.start();
|
|
115
119
|
this.status = exports.RecordingStatus.Recording;
|
|
116
120
|
}
|
|
@@ -185,6 +189,18 @@ var capacitorCapacitorAudioRecorder = (function (exports, core) {
|
|
|
185
189
|
async getRecordingStatus() {
|
|
186
190
|
return { status: this.status };
|
|
187
191
|
}
|
|
192
|
+
async getCurrentAmplitude() {
|
|
193
|
+
if (this.status !== exports.RecordingStatus.Recording || !this.analyser || !this.analyserBuffer) {
|
|
194
|
+
return { value: 0 };
|
|
195
|
+
}
|
|
196
|
+
this.analyser.getFloatTimeDomainData(this.analyserBuffer);
|
|
197
|
+
let sumOfSquares = 0;
|
|
198
|
+
for (const sample of this.analyserBuffer) {
|
|
199
|
+
sumOfSquares += sample * sample;
|
|
200
|
+
}
|
|
201
|
+
const rms = Math.sqrt(sumOfSquares / this.analyserBuffer.length);
|
|
202
|
+
return { value: Math.max(0, Math.min(1, rms)) };
|
|
203
|
+
}
|
|
188
204
|
async checkPermissions() {
|
|
189
205
|
const state = await this.getPermissionState();
|
|
190
206
|
return { recordAudio: state };
|
|
@@ -240,6 +256,7 @@ var capacitorCapacitorAudioRecorder = (function (exports, core) {
|
|
|
240
256
|
this.pausedTimestamp = null;
|
|
241
257
|
this.accumulatedPauseDuration = 0;
|
|
242
258
|
this.recordedChunks = [];
|
|
259
|
+
this.teardownAnalyser();
|
|
243
260
|
this.cleanupMediaStream();
|
|
244
261
|
if (this.mediaRecorder) {
|
|
245
262
|
const recorder = this.mediaRecorder;
|
|
@@ -249,6 +266,48 @@ var capacitorCapacitorAudioRecorder = (function (exports, core) {
|
|
|
249
266
|
}
|
|
250
267
|
this.mediaRecorder = null;
|
|
251
268
|
}
|
|
269
|
+
setupAnalyser() {
|
|
270
|
+
if (!this.mediaStream) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const AudioContextCtor = typeof AudioContext !== 'undefined'
|
|
275
|
+
? AudioContext
|
|
276
|
+
: globalThis.webkitAudioContext;
|
|
277
|
+
if (!AudioContextCtor) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const context = new AudioContextCtor();
|
|
281
|
+
this.audioContext = context;
|
|
282
|
+
const source = context.createMediaStreamSource(this.mediaStream);
|
|
283
|
+
const analyser = context.createAnalyser();
|
|
284
|
+
analyser.fftSize = 1024;
|
|
285
|
+
source.connect(analyser);
|
|
286
|
+
this.analyser = analyser;
|
|
287
|
+
this.analyserBuffer = new Float32Array(new ArrayBuffer(analyser.fftSize * Float32Array.BYTES_PER_ELEMENT));
|
|
288
|
+
}
|
|
289
|
+
catch (_a) {
|
|
290
|
+
this.teardownAnalyser();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
teardownAnalyser() {
|
|
294
|
+
if (this.analyser) {
|
|
295
|
+
try {
|
|
296
|
+
this.analyser.disconnect();
|
|
297
|
+
}
|
|
298
|
+
catch (_a) {
|
|
299
|
+
// Ignored.
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
this.analyser = null;
|
|
303
|
+
this.analyserBuffer = null;
|
|
304
|
+
if (this.audioContext) {
|
|
305
|
+
void this.audioContext.close().catch(() => {
|
|
306
|
+
// Ignored.
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
this.audioContext = null;
|
|
310
|
+
}
|
|
252
311
|
cleanupMediaStream() {
|
|
253
312
|
if (this.mediaStream) {
|
|
254
313
|
this.mediaStream.getTracks().forEach((track) => track.stop());
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The recording status.\n *\n * @since 1.0.0\n */\nexport var RecordingStatus;\n(function (RecordingStatus) {\n RecordingStatus[\"Inactive\"] = \"INACTIVE\";\n RecordingStatus[\"Recording\"] = \"RECORDING\";\n RecordingStatus[\"Paused\"] = \"PAUSED\";\n})(RecordingStatus || (RecordingStatus = {}));\n/**\n * Audio session category options available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionCategoryOption;\n(function (AudioSessionCategoryOption) {\n AudioSessionCategoryOption[\"AllowAirPlay\"] = \"ALLOW_AIR_PLAY\";\n AudioSessionCategoryOption[\"AllowBluetooth\"] = \"ALLOW_BLUETOOTH\";\n AudioSessionCategoryOption[\"AllowBluetoothA2DP\"] = \"ALLOW_BLUETOOTH_A2DP\";\n AudioSessionCategoryOption[\"DefaultToSpeaker\"] = \"DEFAULT_TO_SPEAKER\";\n AudioSessionCategoryOption[\"DuckOthers\"] = \"DUCK_OTHERS\";\n AudioSessionCategoryOption[\"InterruptSpokenAudioAndMixWithOthers\"] = \"INTERRUPT_SPOKEN_AUDIO_AND_MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"MixWithOthers\"] = \"MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"OverrideMutedMicrophoneInterruption\"] = \"OVERRIDE_MUTED_MICROPHONE_INTERRUPTION\";\n})(AudioSessionCategoryOption || (AudioSessionCategoryOption = {}));\n/**\n * Audio session modes available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionMode;\n(function (AudioSessionMode) {\n AudioSessionMode[\"Default\"] = \"DEFAULT\";\n AudioSessionMode[\"GameChat\"] = \"GAME_CHAT\";\n AudioSessionMode[\"Measurement\"] = \"MEASUREMENT\";\n AudioSessionMode[\"SpokenAudio\"] = \"SPOKEN_AUDIO\";\n AudioSessionMode[\"VideoChat\"] = \"VIDEO_CHAT\";\n AudioSessionMode[\"VideoRecording\"] = \"VIDEO_RECORDING\";\n AudioSessionMode[\"VoiceChat\"] = \"VOICE_CHAT\";\n})(AudioSessionMode || (AudioSessionMode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudioRecorder = registerPlugin('CapacitorAudioRecorder', {\n web: () => import('./web').then((m) => new m.CapacitorAudioRecorderWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudioRecorder };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { RecordingStatus } from './definitions';\nexport class CapacitorAudioRecorderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.mediaRecorder = null;\n this.mediaStream = null;\n this.recordedChunks = [];\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.stopResolver = null;\n this.stopRejector = null;\n }\n async startRecording(_options) {\n var _a, _b;\n if (this.status === RecordingStatus.Recording || this.status === RecordingStatus.Paused) {\n throw this.unavailable('Recording already in progress.');\n }\n await this.ensurePermission(true);\n try {\n this.mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });\n }\n catch (error) {\n this.handleError(`Unable to acquire microphone: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n const mimeType = this.pickMimeType();\n try {\n this.mediaRecorder = new MediaRecorder(this.mediaStream, mimeType ? { mimeType } : undefined);\n }\n catch (error) {\n this.cleanupMediaStream();\n this.handleError(`Unable to initialise MediaRecorder: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);\n throw error;\n }\n this.recordedChunks = [];\n this.startTimestamp = Date.now();\n this.accumulatedPauseDuration = 0;\n this.pausedTimestamp = null;\n this.mediaRecorder.addEventListener('dataavailable', (event) => {\n if (event.data.size > 0) {\n this.recordedChunks.push(event.data);\n }\n });\n this.mediaRecorder.addEventListener('stop', () => {\n const result = this.buildStopResult();\n if (this.stopResolver) {\n this.stopResolver(result);\n }\n this.notifyListeners('recordingStopped', result);\n this.resetStopHandlers();\n this.resetState();\n });\n this.mediaRecorder.addEventListener('error', (event) => {\n var _a, _b;\n const message = (_b = (_a = event === null || event === void 0 ? void 0 : event.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Recording error.';\n this.handleError(message);\n if (this.stopRejector) {\n this.stopRejector(new Error(message));\n }\n this.resetStopHandlers();\n this.resetState();\n });\n this.mediaRecorder.start();\n this.status = RecordingStatus.Recording;\n }\n async pauseRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Recording) {\n throw this.unavailable('No active recording to pause.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.pause();\n this.status = RecordingStatus.Paused;\n this.pausedTimestamp = Date.now();\n this.notifyListeners('recordingPaused', {});\n }\n else {\n throw this.unavailable('Pausing recordings is not supported in this browser.');\n }\n }\n async resumeRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Paused) {\n throw this.unavailable('No paused recording to resume.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.resume();\n if (this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n }\n this.pausedTimestamp = null;\n this.status = RecordingStatus.Recording;\n }\n else {\n throw this.unavailable('Resuming recordings is not supported in this browser.');\n }\n }\n async stopRecording() {\n var _a;\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n throw this.unavailable('No active recording to stop.');\n }\n if (this.status === RecordingStatus.Paused && this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n this.pausedTimestamp = null;\n }\n const stopPromise = new Promise((resolve, reject) => {\n this.stopResolver = resolve;\n this.stopRejector = reject;\n });\n try {\n this.mediaRecorder.stop();\n }\n catch (error) {\n this.resetStopHandlers();\n this.resetState();\n this.handleError(`Unable to stop recorder: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n return stopPromise;\n }\n async cancelRecording() {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n this.resetState();\n return;\n }\n try {\n this.mediaRecorder.stop();\n }\n catch (_a) {\n // Ignored.\n }\n this.resetStopHandlers();\n this.resetState();\n }\n async getRecordingStatus() {\n return { status: this.status };\n }\n async checkPermissions() {\n const state = await this.getPermissionState();\n return { recordAudio: state };\n }\n async requestPermissions() {\n const state = await this.ensurePermission(true);\n return { recordAudio: state };\n }\n async addListener(eventName, listenerFunc) {\n return super.addListener(eventName, listenerFunc);\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n // Helpers\n supportsRecorderPause() {\n return (!!this.mediaRecorder &&\n typeof this.mediaRecorder.pause === 'function' &&\n typeof this.mediaRecorder.resume === 'function');\n }\n pickMimeType() {\n const preferred = ['audio/webm;codecs=opus', 'audio/ogg;codecs=opus', 'audio/mp4'];\n for (const type of preferred) {\n if (window.MediaRecorder && MediaRecorder.isTypeSupported && MediaRecorder.isTypeSupported(type)) {\n return type;\n }\n }\n return undefined;\n }\n buildStopResult() {\n const blob = this.recordedChunks.length > 0\n ? new Blob(this.recordedChunks, { type: this.pickMimeType() || 'audio/webm' })\n : undefined;\n let duration;\n if (this.startTimestamp) {\n duration = Date.now() - this.startTimestamp - this.accumulatedPauseDuration;\n }\n return {\n blob,\n duration,\n };\n }\n resetStopHandlers() {\n this.stopResolver = null;\n this.stopRejector = null;\n }\n resetState() {\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.recordedChunks = [];\n this.cleanupMediaStream();\n if (this.mediaRecorder) {\n const recorder = this.mediaRecorder;\n recorder.ondataavailable = null;\n recorder.onstop = null;\n recorder.onerror = null;\n }\n this.mediaRecorder = null;\n }\n cleanupMediaStream() {\n if (this.mediaStream) {\n this.mediaStream.getTracks().forEach((track) => track.stop());\n }\n this.mediaStream = null;\n }\n async ensurePermission(request) {\n const currentState = await this.getPermissionState();\n if (currentState === 'granted' || !request) {\n return currentState;\n }\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n stream.getTracks().forEach((track) => track.stop());\n return 'granted';\n }\n catch (error) {\n return 'denied';\n }\n }\n async getPermissionState() {\n var _a;\n if (!((_a = navigator.permissions) === null || _a === void 0 ? void 0 : _a.query)) {\n return 'prompt';\n }\n try {\n const result = await navigator.permissions.query({ name: 'microphone' });\n switch (result.state) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n catch (_b) {\n return 'prompt';\n }\n }\n handleError(message) {\n this.status = RecordingStatus.Inactive;\n this.notifyListeners('recordingError', { message });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["RecordingStatus","AudioSessionCategoryOption","AudioSessionMode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;IACA;AACWA;IACX,CAAC,UAAU,eAAe,EAAE;IAC5B,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU;IAC5C,IAAI,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW;IAC9C,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACxC,CAAC,EAAEA,uBAAe,KAAKA,uBAAe,GAAG,EAAE,CAAC,CAAC;IAC7C;IACA;IACA;IACA;IACA;AACWC;IACX,CAAC,UAAU,0BAA0B,EAAE;IACvC,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,gBAAgB;IACjE,IAAI,0BAA0B,CAAC,gBAAgB,CAAC,GAAG,iBAAiB;IACpE,IAAI,0BAA0B,CAAC,oBAAoB,CAAC,GAAG,sBAAsB;IAC7E,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,oBAAoB;IACzE,IAAI,0BAA0B,CAAC,YAAY,CAAC,GAAG,aAAa;IAC5D,IAAI,0BA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;IACA,QAAQ;IACR,QAAQ,OAAO,EAAE,EAAE;IACnB,YAAY,OAAO,QAAQ;IAC3B,QAAQ;IACR,IAAI;IACJ,IAAI,WAAW,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,CAAC,MAAM,GAAGA,uBAAe,CAAC,QAAQ;IAC9C,QAAQ,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The recording status.\n *\n * @since 1.0.0\n */\nexport var RecordingStatus;\n(function (RecordingStatus) {\n RecordingStatus[\"Inactive\"] = \"INACTIVE\";\n RecordingStatus[\"Recording\"] = \"RECORDING\";\n RecordingStatus[\"Paused\"] = \"PAUSED\";\n})(RecordingStatus || (RecordingStatus = {}));\n/**\n * Audio session category options available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionCategoryOption;\n(function (AudioSessionCategoryOption) {\n AudioSessionCategoryOption[\"AllowAirPlay\"] = \"ALLOW_AIR_PLAY\";\n AudioSessionCategoryOption[\"AllowBluetooth\"] = \"ALLOW_BLUETOOTH\";\n AudioSessionCategoryOption[\"AllowBluetoothA2DP\"] = \"ALLOW_BLUETOOTH_A2DP\";\n AudioSessionCategoryOption[\"DefaultToSpeaker\"] = \"DEFAULT_TO_SPEAKER\";\n AudioSessionCategoryOption[\"DuckOthers\"] = \"DUCK_OTHERS\";\n AudioSessionCategoryOption[\"InterruptSpokenAudioAndMixWithOthers\"] = \"INTERRUPT_SPOKEN_AUDIO_AND_MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"MixWithOthers\"] = \"MIX_WITH_OTHERS\";\n AudioSessionCategoryOption[\"OverrideMutedMicrophoneInterruption\"] = \"OVERRIDE_MUTED_MICROPHONE_INTERRUPTION\";\n})(AudioSessionCategoryOption || (AudioSessionCategoryOption = {}));\n/**\n * Audio session modes available on iOS.\n *\n * @since 1.0.0\n */\nexport var AudioSessionMode;\n(function (AudioSessionMode) {\n AudioSessionMode[\"Default\"] = \"DEFAULT\";\n AudioSessionMode[\"GameChat\"] = \"GAME_CHAT\";\n AudioSessionMode[\"Measurement\"] = \"MEASUREMENT\";\n AudioSessionMode[\"SpokenAudio\"] = \"SPOKEN_AUDIO\";\n AudioSessionMode[\"VideoChat\"] = \"VIDEO_CHAT\";\n AudioSessionMode[\"VideoRecording\"] = \"VIDEO_RECORDING\";\n AudioSessionMode[\"VoiceChat\"] = \"VOICE_CHAT\";\n})(AudioSessionMode || (AudioSessionMode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudioRecorder = registerPlugin('CapacitorAudioRecorder', {\n web: () => import('./web').then((m) => new m.CapacitorAudioRecorderWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudioRecorder };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { RecordingStatus } from './definitions';\nexport class CapacitorAudioRecorderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.mediaRecorder = null;\n this.mediaStream = null;\n this.recordedChunks = [];\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.stopResolver = null;\n this.stopRejector = null;\n this.audioContext = null;\n this.analyser = null;\n this.analyserBuffer = null;\n }\n async startRecording(_options) {\n var _a, _b;\n if (this.status === RecordingStatus.Recording || this.status === RecordingStatus.Paused) {\n throw this.unavailable('Recording already in progress.');\n }\n await this.ensurePermission(true);\n try {\n this.mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });\n }\n catch (error) {\n this.handleError(`Unable to acquire microphone: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n const mimeType = this.pickMimeType();\n try {\n this.mediaRecorder = new MediaRecorder(this.mediaStream, mimeType ? { mimeType } : undefined);\n }\n catch (error) {\n this.cleanupMediaStream();\n this.handleError(`Unable to initialise MediaRecorder: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);\n throw error;\n }\n this.recordedChunks = [];\n this.startTimestamp = Date.now();\n this.accumulatedPauseDuration = 0;\n this.pausedTimestamp = null;\n this.mediaRecorder.addEventListener('dataavailable', (event) => {\n if (event.data.size > 0) {\n this.recordedChunks.push(event.data);\n }\n });\n this.mediaRecorder.addEventListener('stop', () => {\n const result = this.buildStopResult();\n if (this.stopResolver) {\n this.stopResolver(result);\n }\n this.notifyListeners('recordingStopped', result);\n this.resetStopHandlers();\n this.resetState();\n });\n this.mediaRecorder.addEventListener('error', (event) => {\n var _a, _b;\n const message = (_b = (_a = event === null || event === void 0 ? void 0 : event.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Recording error.';\n this.handleError(message);\n if (this.stopRejector) {\n this.stopRejector(new Error(message));\n }\n this.resetStopHandlers();\n this.resetState();\n });\n this.setupAnalyser();\n this.mediaRecorder.start();\n this.status = RecordingStatus.Recording;\n }\n async pauseRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Recording) {\n throw this.unavailable('No active recording to pause.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.pause();\n this.status = RecordingStatus.Paused;\n this.pausedTimestamp = Date.now();\n this.notifyListeners('recordingPaused', {});\n }\n else {\n throw this.unavailable('Pausing recordings is not supported in this browser.');\n }\n }\n async resumeRecording() {\n if (!this.mediaRecorder || this.status !== RecordingStatus.Paused) {\n throw this.unavailable('No paused recording to resume.');\n }\n if (this.supportsRecorderPause()) {\n this.mediaRecorder.resume();\n if (this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n }\n this.pausedTimestamp = null;\n this.status = RecordingStatus.Recording;\n }\n else {\n throw this.unavailable('Resuming recordings is not supported in this browser.');\n }\n }\n async stopRecording() {\n var _a;\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n throw this.unavailable('No active recording to stop.');\n }\n if (this.status === RecordingStatus.Paused && this.pausedTimestamp) {\n this.accumulatedPauseDuration += Date.now() - this.pausedTimestamp;\n this.pausedTimestamp = null;\n }\n const stopPromise = new Promise((resolve, reject) => {\n this.stopResolver = resolve;\n this.stopRejector = reject;\n });\n try {\n this.mediaRecorder.stop();\n }\n catch (error) {\n this.resetStopHandlers();\n this.resetState();\n this.handleError(`Unable to stop recorder: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);\n throw error;\n }\n return stopPromise;\n }\n async cancelRecording() {\n if (!this.mediaRecorder || this.status === RecordingStatus.Inactive) {\n this.resetState();\n return;\n }\n try {\n this.mediaRecorder.stop();\n }\n catch (_a) {\n // Ignored.\n }\n this.resetStopHandlers();\n this.resetState();\n }\n async getRecordingStatus() {\n return { status: this.status };\n }\n async getCurrentAmplitude() {\n if (this.status !== RecordingStatus.Recording || !this.analyser || !this.analyserBuffer) {\n return { value: 0 };\n }\n this.analyser.getFloatTimeDomainData(this.analyserBuffer);\n let sumOfSquares = 0;\n for (const sample of this.analyserBuffer) {\n sumOfSquares += sample * sample;\n }\n const rms = Math.sqrt(sumOfSquares / this.analyserBuffer.length);\n return { value: Math.max(0, Math.min(1, rms)) };\n }\n async checkPermissions() {\n const state = await this.getPermissionState();\n return { recordAudio: state };\n }\n async requestPermissions() {\n const state = await this.ensurePermission(true);\n return { recordAudio: state };\n }\n async addListener(eventName, listenerFunc) {\n return super.addListener(eventName, listenerFunc);\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n // Helpers\n supportsRecorderPause() {\n return (!!this.mediaRecorder &&\n typeof this.mediaRecorder.pause === 'function' &&\n typeof this.mediaRecorder.resume === 'function');\n }\n pickMimeType() {\n const preferred = ['audio/webm;codecs=opus', 'audio/ogg;codecs=opus', 'audio/mp4'];\n for (const type of preferred) {\n if (window.MediaRecorder && MediaRecorder.isTypeSupported && MediaRecorder.isTypeSupported(type)) {\n return type;\n }\n }\n return undefined;\n }\n buildStopResult() {\n const blob = this.recordedChunks.length > 0\n ? new Blob(this.recordedChunks, { type: this.pickMimeType() || 'audio/webm' })\n : undefined;\n let duration;\n if (this.startTimestamp) {\n duration = Date.now() - this.startTimestamp - this.accumulatedPauseDuration;\n }\n return {\n blob,\n duration,\n };\n }\n resetStopHandlers() {\n this.stopResolver = null;\n this.stopRejector = null;\n }\n resetState() {\n this.status = RecordingStatus.Inactive;\n this.startTimestamp = null;\n this.pausedTimestamp = null;\n this.accumulatedPauseDuration = 0;\n this.recordedChunks = [];\n this.teardownAnalyser();\n this.cleanupMediaStream();\n if (this.mediaRecorder) {\n const recorder = this.mediaRecorder;\n recorder.ondataavailable = null;\n recorder.onstop = null;\n recorder.onerror = null;\n }\n this.mediaRecorder = null;\n }\n setupAnalyser() {\n if (!this.mediaStream) {\n return;\n }\n try {\n const AudioContextCtor = typeof AudioContext !== 'undefined'\n ? AudioContext\n : globalThis.webkitAudioContext;\n if (!AudioContextCtor) {\n return;\n }\n const context = new AudioContextCtor();\n this.audioContext = context;\n const source = context.createMediaStreamSource(this.mediaStream);\n const analyser = context.createAnalyser();\n analyser.fftSize = 1024;\n source.connect(analyser);\n this.analyser = analyser;\n this.analyserBuffer = new Float32Array(new ArrayBuffer(analyser.fftSize * Float32Array.BYTES_PER_ELEMENT));\n }\n catch (_a) {\n this.teardownAnalyser();\n }\n }\n teardownAnalyser() {\n if (this.analyser) {\n try {\n this.analyser.disconnect();\n }\n catch (_a) {\n // Ignored.\n }\n }\n this.analyser = null;\n this.analyserBuffer = null;\n if (this.audioContext) {\n void this.audioContext.close().catch(() => {\n // Ignored.\n });\n }\n this.audioContext = null;\n }\n cleanupMediaStream() {\n if (this.mediaStream) {\n this.mediaStream.getTracks().forEach((track) => track.stop());\n }\n this.mediaStream = null;\n }\n async ensurePermission(request) {\n const currentState = await this.getPermissionState();\n if (currentState === 'granted' || !request) {\n return currentState;\n }\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n stream.getTracks().forEach((track) => track.stop());\n return 'granted';\n }\n catch (error) {\n return 'denied';\n }\n }\n async getPermissionState() {\n var _a;\n if (!((_a = navigator.permissions) === null || _a === void 0 ? void 0 : _a.query)) {\n return 'prompt';\n }\n try {\n const result = await navigator.permissions.query({ name: 'microphone' });\n switch (result.state) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n catch (_b) {\n return 'prompt';\n }\n }\n handleError(message) {\n this.status = RecordingStatus.Inactive;\n this.notifyListeners('recordingError', { message });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["RecordingStatus","AudioSessionCategoryOption","AudioSessionMode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;IACA;AACWA;IACX,CAAC,UAAU,eAAe,EAAE;IAC5B,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU;IAC5C,IAAI,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW;IAC9C,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACxC,CAAC,EAAEA,uBAAe,KAAKA,uBAAe,GAAG,EAAE,CAAC,CAAC;IAC7C;IACA;IACA;IACA;IACA;AACWC;IACX,CAAC,UAAU,0BAA0B,EAAE;IACvC,IAAI,0BAA0B,CAAC,cAAc,CAAC,GAAG,gBAAgB;IACjE,IAAI,0BAA0B,CAAC,gBAAgB,CAAC,GAAG,iBAAiB;IACpE,IAAI,0BAA0B,CAAC,oBAAoB,CAAC,GAAG,sBAAsB;IAC7E,IAAI,0BAA0B,CAAC,kBAAkB,CAAC,GAAG,oBAAoB;IACzE,IAAI,0BAA0B,CAAC,YAAY,CAAC,GAAG,aAAa;IAC5D,IAAI,0BAA0B,CAAC,sCAAsC,CAAC,GAAG,4CAA4C;IACrH,IAAI,0BAA0B,CAAC,e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AAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -4,7 +4,7 @@ import Foundation
|
|
|
4
4
|
|
|
5
5
|
@objc(CapacitorAudioRecorderPlugin)
|
|
6
6
|
public class CapacitorAudioRecorderPlugin: CAPPlugin, CAPBridgedPlugin, AVAudioRecorderDelegate {
|
|
7
|
-
private let pluginVersion: String = "8.0
|
|
7
|
+
private let pluginVersion: String = "8.1.0"
|
|
8
8
|
public let identifier = "CapacitorAudioRecorderPlugin"
|
|
9
9
|
public let jsName = "CapacitorAudioRecorder"
|
|
10
10
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -14,6 +14,7 @@ public class CapacitorAudioRecorderPlugin: CAPPlugin, CAPBridgedPlugin, AVAudioR
|
|
|
14
14
|
CAPPluginMethod(name: "stopRecording", returnType: CAPPluginReturnPromise),
|
|
15
15
|
CAPPluginMethod(name: "cancelRecording", returnType: CAPPluginReturnPromise),
|
|
16
16
|
CAPPluginMethod(name: "getRecordingStatus", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "getCurrentAmplitude", returnType: CAPPluginReturnPromise),
|
|
17
18
|
CAPPluginMethod(name: "checkPermissions", returnType: CAPPluginReturnPromise),
|
|
18
19
|
CAPPluginMethod(name: "requestPermissions", returnType: CAPPluginReturnPromise),
|
|
19
20
|
CAPPluginMethod(name: "removeAllListeners", returnType: CAPPluginReturnPromise),
|
|
@@ -129,6 +130,18 @@ public class CapacitorAudioRecorderPlugin: CAPPlugin, CAPBridgedPlugin, AVAudioR
|
|
|
129
130
|
call.resolve(["status": status.rawValue])
|
|
130
131
|
}
|
|
131
132
|
|
|
133
|
+
@objc func getCurrentAmplitude(_ call: CAPPluginCall) {
|
|
134
|
+
guard let recorder = audioRecorder, status == .recording else {
|
|
135
|
+
call.resolve(["value": 0.0])
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
recorder.updateMeters()
|
|
139
|
+
let averagePowerDb = Double(recorder.averagePower(forChannel: 0))
|
|
140
|
+
let linear: Double = averagePowerDb.isFinite ? pow(10.0, averagePowerDb / 20.0) : 0.0
|
|
141
|
+
let value = max(0.0, min(1.0, linear))
|
|
142
|
+
call.resolve(["value": value])
|
|
143
|
+
}
|
|
144
|
+
|
|
132
145
|
@objc override public func checkPermissions(_ call: CAPPluginCall) {
|
|
133
146
|
call.resolve(["recordAudio": microphonePermissionState()])
|
|
134
147
|
}
|
|
@@ -210,6 +223,7 @@ public class CapacitorAudioRecorderPlugin: CAPPlugin, CAPBridgedPlugin, AVAudioR
|
|
|
210
223
|
|
|
211
224
|
let recorder = try AVAudioRecorder(url: fileURL, settings: settings)
|
|
212
225
|
recorder.delegate = self
|
|
226
|
+
recorder.isMeteringEnabled = true
|
|
213
227
|
recorder.prepareToRecord()
|
|
214
228
|
recorder.record()
|
|
215
229
|
|