nosnia-audio-recorder 0.9.5 → 0.9.6

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.
@@ -1,5 +1,6 @@
1
1
  #import "NosniaAudioRecorder.h"
2
2
  #import <AVFoundation/AVFoundation.h>
3
+ #import <CoreMedia/CoreMedia.h>
3
4
  #import <React/RCTBridgeModule.h>
4
5
  #import <React/RCTEventEmitter.h>
5
6
  #import <React/RCTLog.h>
@@ -17,6 +18,7 @@
17
18
  BOOL _isRecording;
18
19
  NSTimer *_progressTimer;
19
20
  BOOL _hasListeners;
21
+ CFTimeInterval _recordingStartTime;
20
22
  }
21
23
 
22
24
  RCT_EXPORT_MODULE(NosniaAudioRecorder)
@@ -58,17 +60,20 @@ RCT_EXPORT_MODULE(NosniaAudioRecorder)
58
60
  NSLog(@"[NosniaAudioRecorder] hasListeners: %d, isRecording: %d, audioRecorder: %@",
59
61
  _hasListeners, _isRecording, _audioRecorder ? @"YES" : @"NO");
60
62
 
63
+ // Record the start time for elapsed time calculation
64
+ _recordingStartTime = CACurrentMediaTime();
65
+
61
66
  // Send initial duration event immediately
62
67
  if (_audioRecorder && _isRecording) {
63
- NSTimeInterval currentTime = _audioRecorder.currentTime;
68
+ double durationMs = 0.0;
64
69
  NSLog(@"[NosniaAudioRecorder] Sending initial progress: duration=%f ms (hasListeners=%d)",
65
- currentTime * 1000, _hasListeners);
70
+ durationMs, _hasListeners);
66
71
 
67
72
  dispatch_async(dispatch_get_main_queue(), ^{
68
73
  NSLog(@"[NosniaAudioRecorder] About to send initial event on main thread");
69
74
  [self sendEventWithName:@"onRecordingProgress"
70
75
  body:@{
71
- @"duration": @(currentTime * 1000),
76
+ @"duration": @(durationMs),
72
77
  @"isRecording": @(self->_audioRecorder.isRecording)
73
78
  }];
74
79
  NSLog(@"[NosniaAudioRecorder] Initial event sent (hasListeners=%d)", self->_hasListeners);
@@ -82,15 +87,17 @@ RCT_EXPORT_MODULE(NosniaAudioRecorder)
82
87
  self->_hasListeners, self->_audioRecorder ? @"yes" : @"no", self->_isRecording);
83
88
 
84
89
  if (self->_audioRecorder && self->_isRecording) {
85
- NSTimeInterval currentTime = self->_audioRecorder.currentTime;
86
- NSLog(@"[NosniaAudioRecorder] Sending progress: duration=%f ms (hasListeners=%d)",
87
- currentTime * 1000, self->_hasListeners);
90
+ // Use elapsed time instead of currentTime (which doesn't update reliably)
91
+ CFTimeInterval elapsedSeconds = CACurrentMediaTime() - self->_recordingStartTime;
92
+ double durationMs = elapsedSeconds * 1000;
93
+ NSLog(@"[NosniaAudioRecorder] Duration: elapsed=%f seconds, durationMs=%f milliseconds (hasListeners=%d)",
94
+ elapsedSeconds, durationMs, self->_hasListeners);
88
95
 
89
96
  // Ensure event is sent on main thread
90
97
  dispatch_async(dispatch_get_main_queue(), ^{
91
98
  [self sendEventWithName:@"onRecordingProgress"
92
99
  body:@{
93
- @"duration": @(currentTime * 1000),
100
+ @"duration": @(durationMs),
94
101
  @"isRecording": @(self->_audioRecorder.isRecording)
95
102
  }];
96
103
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "This is a modern audio recorder which actually works cross platform",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",