nosnia-audio-recorder 0.9.10 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,6 @@
17
17
  BOOL _isRecording;
18
18
  NSTimer *_progressTimer;
19
19
  BOOL _hasListeners;
20
- double _elapsedTimeMs;
21
20
  }
22
21
 
23
22
  RCT_EXPORT_MODULE(NosniaAudioRecorder)
@@ -51,48 +50,69 @@ RCT_EXPORT_MODULE(NosniaAudioRecorder)
51
50
  }
52
51
 
53
52
  - (void)startProgressTimer {
53
+ // Invalidate existing timer
54
54
  if (_progressTimer) {
55
55
  [_progressTimer invalidate];
56
+ _progressTimer = nil;
56
57
  }
57
58
 
58
59
  NSLog(@"[NosniaAudioRecorder] Starting progress timer");
59
- _elapsedTimeMs = 0.0;
60
60
 
61
- // Send initial duration event immediately
62
- if (_audioRecorder && _isRecording) {
63
- dispatch_async(dispatch_get_main_queue(), ^{
64
- [self sendEventWithName:@"onRecordingProgress"
65
- body:@{
66
- @"duration": @(0.0),
67
- @"isRecording": @(self->_audioRecorder.isRecording)
68
- }];
69
- });
61
+ // Ensure timer is created on main thread and added to main run loop
62
+ dispatch_async(dispatch_get_main_queue(), ^{
63
+ // Send initial duration event
64
+ [self sendEventWithName:@"onRecordingProgress"
65
+ body:@{
66
+ @"duration": @(0.0),
67
+ @"isRecording": @(self->_audioRecorder && self->_audioRecorder.isRecording)
68
+ }];
69
+
70
+ // Create and schedule timer on main run loop
71
+ self->_progressTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
72
+ target:self
73
+ selector:@selector(onProgressTimerTick:)
74
+ userInfo:nil
75
+ repeats:YES];
76
+
77
+ // Ensure timer fires on main run loop
78
+ [[NSRunLoop mainRunLoop] addTimer:self->_progressTimer forMode:NSRunLoopCommonModes];
79
+
80
+ NSLog(@"[NosniaAudioRecorder] Progress timer scheduled on main thread");
81
+ });
82
+ }
83
+
84
+ - (void)onProgressTimerTick:(NSTimer *)timer {
85
+ if (!_audioRecorder || !_isRecording) {
86
+ [self stopProgressTimer];
87
+ return;
70
88
  }
71
89
 
72
- _progressTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
73
- repeats:YES
74
- block:^(NSTimer * _Nonnull timer) {
75
- if (self->_audioRecorder && self->_isRecording) {
76
- // Simply increment by 100ms (the interval)
77
- self->_elapsedTimeMs += 100.0;
78
-
79
- NSLog(@"[NosniaAudioRecorder] Sending duration: %.0f ms", self->_elapsedTimeMs);
80
-
81
- dispatch_async(dispatch_get_main_queue(), ^{
82
- [self sendEventWithName:@"onRecordingProgress"
83
- body:@{
84
- @"duration": @(self->_elapsedTimeMs),
85
- @"isRecording": @(self->_audioRecorder.isRecording)
86
- }];
87
- });
88
- }
89
- }];
90
+ // Update meters to ensure accurate currentTime reading
91
+ [_audioRecorder updateMeters];
92
+
93
+ // Use the recorder's currentTime directly
94
+ double durationMs = _audioRecorder.currentTime * 1000.0;
95
+
96
+ NSLog(@"[NosniaAudioRecorder] Duration: %.0f ms (currentTime: %.4f seconds)",
97
+ durationMs, _audioRecorder.currentTime);
98
+
99
+ dispatch_async(dispatch_get_main_queue(), ^{
100
+ [self sendEventWithName:@"onRecordingProgress"
101
+ body:@{
102
+ @"duration": @(durationMs),
103
+ @"isRecording": @(self->_audioRecorder.isRecording)
104
+ }];
105
+ });
90
106
  }
91
107
 
92
108
  - (void)stopProgressTimer {
93
109
  if (_progressTimer) {
94
- [_progressTimer invalidate];
95
- _progressTimer = nil;
110
+ dispatch_async(dispatch_get_main_queue(), ^{
111
+ if (self->_progressTimer) {
112
+ [self->_progressTimer invalidate];
113
+ self->_progressTimer = nil;
114
+ }
115
+ });
96
116
  }
97
117
  }
98
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.9.10",
3
+ "version": "0.9.12",
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",