@clarionhq/recorder 0.0.1 → 0.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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +110 -0
  3. package/android/build.gradle +97 -0
  4. package/android/gradle.properties +4 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/cpp/cpp-adapter.cpp +7 -0
  7. package/android/src/main/java/com/clarionhq/recorder/AudioLevelMeter.kt +38 -0
  8. package/android/src/main/java/com/clarionhq/recorder/ClarionRecorderPackage.kt +27 -0
  9. package/android/src/main/java/com/clarionhq/recorder/EncodeFile.kt +62 -0
  10. package/android/src/main/java/com/clarionhq/recorder/RecorderConfig.kt +33 -0
  11. package/android/src/main/java/com/clarionhq/recorder/RecorderConstants.kt +16 -0
  12. package/android/src/main/java/com/clarionhq/recorder/RecorderSession.kt +336 -0
  13. package/android/src/main/java/com/clarionhq/recorder/RecorderTypes.kt +29 -0
  14. package/android/src/main/java/com/margelo/nitro/clarion/recorder/HybridClarionRecorder.kt +174 -0
  15. package/clarionhq-recorder.podspec +31 -0
  16. package/ios/AudioLevelMeter.swift +37 -0
  17. package/ios/EncodeFile.swift +69 -0
  18. package/ios/HybridClarionRecorder.swift +186 -0
  19. package/ios/RecorderConstants.swift +11 -0
  20. package/ios/RecorderSession.swift +278 -0
  21. package/ios/RecorderTypes.swift +41 -0
  22. package/lib/RecorderEngine.d.ts +31 -0
  23. package/lib/RecorderEngine.d.ts.map +1 -0
  24. package/lib/RecorderEngine.js +245 -0
  25. package/lib/RecorderEngine.js.map +1 -0
  26. package/lib/index.d.ts +4 -0
  27. package/lib/index.d.ts.map +1 -0
  28. package/lib/index.js +2 -0
  29. package/lib/index.js.map +1 -0
  30. package/lib/native.d.ts +3 -0
  31. package/lib/native.d.ts.map +1 -0
  32. package/lib/native.js +3 -0
  33. package/lib/native.js.map +1 -0
  34. package/lib/specs/ClarionRecorder.nitro.d.ts +49 -0
  35. package/lib/specs/ClarionRecorder.nitro.d.ts.map +1 -0
  36. package/lib/specs/ClarionRecorder.nitro.js +2 -0
  37. package/lib/specs/ClarionRecorder.nitro.js.map +1 -0
  38. package/nitro.json +24 -0
  39. package/nitrogen/generated/android/ClarionRecorder+autolinking.cmake +81 -0
  40. package/nitrogen/generated/android/ClarionRecorder+autolinking.gradle +27 -0
  41. package/nitrogen/generated/android/ClarionRecorderOnLoad.cpp +62 -0
  42. package/nitrogen/generated/android/ClarionRecorderOnLoad.hpp +34 -0
  43. package/nitrogen/generated/android/c++/JFunc_void_NativeRecorderError.hpp +78 -0
  44. package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +75 -0
  45. package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
  46. package/nitrogen/generated/android/c++/JFunc_void_std__string_double_double_double.hpp +76 -0
  47. package/nitrogen/generated/android/c++/JHybridClarionRecorderSpec.cpp +207 -0
  48. package/nitrogen/generated/android/c++/JHybridClarionRecorderSpec.hpp +75 -0
  49. package/nitrogen/generated/android/c++/JNativeRecorderConfig.hpp +90 -0
  50. package/nitrogen/generated/android/c++/JNativeRecorderError.hpp +65 -0
  51. package/nitrogen/generated/android/c++/JNativeRecorderResult.hpp +77 -0
  52. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/ClarionRecorderOnLoad.kt +35 -0
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/Func_void_NativeRecorderError.kt +80 -0
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/Func_void_double_double.kt +80 -0
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/Func_void_std__string.kt +80 -0
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/Func_void_std__string_double_double_double.kt +80 -0
  57. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/HybridClarionRecorderSpec.kt +125 -0
  58. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/NativeRecorderConfig.kt +91 -0
  59. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/NativeRecorderError.kt +61 -0
  60. package/nitrogen/generated/android/kotlin/com/margelo/nitro/clarion/recorder/NativeRecorderResult.kt +76 -0
  61. package/nitrogen/generated/ios/ClarionRecorder+autolinking.rb +62 -0
  62. package/nitrogen/generated/ios/ClarionRecorder-Swift-Cxx-Bridge.cpp +89 -0
  63. package/nitrogen/generated/ios/ClarionRecorder-Swift-Cxx-Bridge.hpp +297 -0
  64. package/nitrogen/generated/ios/ClarionRecorder-Swift-Cxx-Umbrella.hpp +56 -0
  65. package/nitrogen/generated/ios/ClarionRecorderAutolinking.mm +33 -0
  66. package/nitrogen/generated/ios/ClarionRecorderAutolinking.swift +26 -0
  67. package/nitrogen/generated/ios/c++/HybridClarionRecorderSpecSwift.cpp +11 -0
  68. package/nitrogen/generated/ios/c++/HybridClarionRecorderSpecSwift.hpp +188 -0
  69. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  70. package/nitrogen/generated/ios/swift/Func_void_NativeRecorderError.swift +46 -0
  71. package/nitrogen/generated/ios/swift/Func_void_NativeRecorderResult.swift +46 -0
  72. package/nitrogen/generated/ios/swift/Func_void_double_double.swift +46 -0
  73. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  74. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
  75. package/nitrogen/generated/ios/swift/Func_void_std__string_double_double_double.swift +46 -0
  76. package/nitrogen/generated/ios/swift/HybridClarionRecorderSpec.swift +67 -0
  77. package/nitrogen/generated/ios/swift/HybridClarionRecorderSpec_cxx.swift +354 -0
  78. package/nitrogen/generated/ios/swift/NativeRecorderConfig.swift +108 -0
  79. package/nitrogen/generated/ios/swift/NativeRecorderError.swift +39 -0
  80. package/nitrogen/generated/ios/swift/NativeRecorderResult.swift +54 -0
  81. package/nitrogen/generated/shared/c++/HybridClarionRecorderSpec.cpp +34 -0
  82. package/nitrogen/generated/shared/c++/HybridClarionRecorderSpec.hpp +84 -0
  83. package/nitrogen/generated/shared/c++/NativeRecorderConfig.hpp +116 -0
  84. package/nitrogen/generated/shared/c++/NativeRecorderError.hpp +91 -0
  85. package/nitrogen/generated/shared/c++/NativeRecorderResult.hpp +103 -0
  86. package/package.json +66 -8
  87. package/src/RecorderEngine.ts +298 -0
  88. package/src/index.ts +8 -0
  89. package/src/native.ts +5 -0
  90. package/src/specs/ClarionRecorder.nitro.ts +58 -0
  91. package/index.js +0 -1
@@ -0,0 +1,116 @@
1
+ ///
2
+ /// NativeRecorderConfig.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+ #include <optional>
35
+
36
+ namespace margelo::nitro::clarion::recorder {
37
+
38
+ /**
39
+ * A struct which can be represented as a JavaScript object (NativeRecorderConfig).
40
+ */
41
+ struct NativeRecorderConfig final {
42
+ public:
43
+ double sampleRate SWIFT_PRIVATE;
44
+ double channels SWIFT_PRIVATE;
45
+ double bitDepth SWIFT_PRIVATE;
46
+ std::optional<std::string> outputDirectory SWIFT_PRIVATE;
47
+ std::optional<std::string> filenamePrefix SWIFT_PRIVATE;
48
+ std::optional<double> rotateAfterMs SWIFT_PRIVATE;
49
+ bool emitAudioLevel SWIFT_PRIVATE;
50
+ double audioLevelIntervalMs SWIFT_PRIVATE;
51
+ double aacBitrate SWIFT_PRIVATE;
52
+
53
+ public:
54
+ NativeRecorderConfig() = default;
55
+ explicit NativeRecorderConfig(double sampleRate, double channels, double bitDepth, std::optional<std::string> outputDirectory, std::optional<std::string> filenamePrefix, std::optional<double> rotateAfterMs, bool emitAudioLevel, double audioLevelIntervalMs, double aacBitrate): sampleRate(sampleRate), channels(channels), bitDepth(bitDepth), outputDirectory(outputDirectory), filenamePrefix(filenamePrefix), rotateAfterMs(rotateAfterMs), emitAudioLevel(emitAudioLevel), audioLevelIntervalMs(audioLevelIntervalMs), aacBitrate(aacBitrate) {}
56
+
57
+ public:
58
+ friend bool operator==(const NativeRecorderConfig& lhs, const NativeRecorderConfig& rhs) = default;
59
+ };
60
+
61
+ } // namespace margelo::nitro::clarion::recorder
62
+
63
+ namespace margelo::nitro {
64
+
65
+ // C++ NativeRecorderConfig <> JS NativeRecorderConfig (object)
66
+ template <>
67
+ struct JSIConverter<margelo::nitro::clarion::recorder::NativeRecorderConfig> final {
68
+ static inline margelo::nitro::clarion::recorder::NativeRecorderConfig fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
69
+ jsi::Object obj = arg.asObject(runtime);
70
+ return margelo::nitro::clarion::recorder::NativeRecorderConfig(
71
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sampleRate"))),
72
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "channels"))),
73
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bitDepth"))),
74
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "outputDirectory"))),
75
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "filenamePrefix"))),
76
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "rotateAfterMs"))),
77
+ JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "emitAudioLevel"))),
78
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audioLevelIntervalMs"))),
79
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "aacBitrate")))
80
+ );
81
+ }
82
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::clarion::recorder::NativeRecorderConfig& arg) {
83
+ jsi::Object obj(runtime);
84
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "sampleRate"), JSIConverter<double>::toJSI(runtime, arg.sampleRate));
85
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "channels"), JSIConverter<double>::toJSI(runtime, arg.channels));
86
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "bitDepth"), JSIConverter<double>::toJSI(runtime, arg.bitDepth));
87
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "outputDirectory"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.outputDirectory));
88
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "filenamePrefix"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.filenamePrefix));
89
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "rotateAfterMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.rotateAfterMs));
90
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "emitAudioLevel"), JSIConverter<bool>::toJSI(runtime, arg.emitAudioLevel));
91
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "audioLevelIntervalMs"), JSIConverter<double>::toJSI(runtime, arg.audioLevelIntervalMs));
92
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "aacBitrate"), JSIConverter<double>::toJSI(runtime, arg.aacBitrate));
93
+ return obj;
94
+ }
95
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
96
+ if (!value.isObject()) {
97
+ return false;
98
+ }
99
+ jsi::Object obj = value.getObject(runtime);
100
+ if (!nitro::isPlainObject(runtime, obj)) {
101
+ return false;
102
+ }
103
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sampleRate")))) return false;
104
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "channels")))) return false;
105
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bitDepth")))) return false;
106
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "outputDirectory")))) return false;
107
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "filenamePrefix")))) return false;
108
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "rotateAfterMs")))) return false;
109
+ if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "emitAudioLevel")))) return false;
110
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audioLevelIntervalMs")))) return false;
111
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "aacBitrate")))) return false;
112
+ return true;
113
+ }
114
+ };
115
+
116
+ } // namespace margelo::nitro
@@ -0,0 +1,91 @@
1
+ ///
2
+ /// NativeRecorderError.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+
35
+ namespace margelo::nitro::clarion::recorder {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (NativeRecorderError).
39
+ */
40
+ struct NativeRecorderError final {
41
+ public:
42
+ std::string code SWIFT_PRIVATE;
43
+ std::string message SWIFT_PRIVATE;
44
+ bool recoverable SWIFT_PRIVATE;
45
+
46
+ public:
47
+ NativeRecorderError() = default;
48
+ explicit NativeRecorderError(std::string code, std::string message, bool recoverable): code(code), message(message), recoverable(recoverable) {}
49
+
50
+ public:
51
+ friend bool operator==(const NativeRecorderError& lhs, const NativeRecorderError& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::clarion::recorder
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ NativeRecorderError <> JS NativeRecorderError (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::clarion::recorder::NativeRecorderError> final {
61
+ static inline margelo::nitro::clarion::recorder::NativeRecorderError fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::clarion::recorder::NativeRecorderError(
64
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "code"))),
65
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message"))),
66
+ JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "recoverable")))
67
+ );
68
+ }
69
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::clarion::recorder::NativeRecorderError& arg) {
70
+ jsi::Object obj(runtime);
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "code"), JSIConverter<std::string>::toJSI(runtime, arg.code));
72
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "message"), JSIConverter<std::string>::toJSI(runtime, arg.message));
73
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "recoverable"), JSIConverter<bool>::toJSI(runtime, arg.recoverable));
74
+ return obj;
75
+ }
76
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
77
+ if (!value.isObject()) {
78
+ return false;
79
+ }
80
+ jsi::Object obj = value.getObject(runtime);
81
+ if (!nitro::isPlainObject(runtime, obj)) {
82
+ return false;
83
+ }
84
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "code")))) return false;
85
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))) return false;
86
+ if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "recoverable")))) return false;
87
+ return true;
88
+ }
89
+ };
90
+
91
+ } // namespace margelo::nitro
@@ -0,0 +1,103 @@
1
+ ///
2
+ /// NativeRecorderResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+
35
+ namespace margelo::nitro::clarion::recorder {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (NativeRecorderResult).
39
+ */
40
+ struct NativeRecorderResult final {
41
+ public:
42
+ std::string uri SWIFT_PRIVATE;
43
+ double durationMs SWIFT_PRIVATE;
44
+ double sizeBytes SWIFT_PRIVATE;
45
+ double sampleRate SWIFT_PRIVATE;
46
+ double channels SWIFT_PRIVATE;
47
+ double bitDepth SWIFT_PRIVATE;
48
+
49
+ public:
50
+ NativeRecorderResult() = default;
51
+ explicit NativeRecorderResult(std::string uri, double durationMs, double sizeBytes, double sampleRate, double channels, double bitDepth): uri(uri), durationMs(durationMs), sizeBytes(sizeBytes), sampleRate(sampleRate), channels(channels), bitDepth(bitDepth) {}
52
+
53
+ public:
54
+ friend bool operator==(const NativeRecorderResult& lhs, const NativeRecorderResult& rhs) = default;
55
+ };
56
+
57
+ } // namespace margelo::nitro::clarion::recorder
58
+
59
+ namespace margelo::nitro {
60
+
61
+ // C++ NativeRecorderResult <> JS NativeRecorderResult (object)
62
+ template <>
63
+ struct JSIConverter<margelo::nitro::clarion::recorder::NativeRecorderResult> final {
64
+ static inline margelo::nitro::clarion::recorder::NativeRecorderResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
65
+ jsi::Object obj = arg.asObject(runtime);
66
+ return margelo::nitro::clarion::recorder::NativeRecorderResult(
67
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uri"))),
68
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "durationMs"))),
69
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sizeBytes"))),
70
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sampleRate"))),
71
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "channels"))),
72
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bitDepth")))
73
+ );
74
+ }
75
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::clarion::recorder::NativeRecorderResult& arg) {
76
+ jsi::Object obj(runtime);
77
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "uri"), JSIConverter<std::string>::toJSI(runtime, arg.uri));
78
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "durationMs"), JSIConverter<double>::toJSI(runtime, arg.durationMs));
79
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "sizeBytes"), JSIConverter<double>::toJSI(runtime, arg.sizeBytes));
80
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "sampleRate"), JSIConverter<double>::toJSI(runtime, arg.sampleRate));
81
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "channels"), JSIConverter<double>::toJSI(runtime, arg.channels));
82
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "bitDepth"), JSIConverter<double>::toJSI(runtime, arg.bitDepth));
83
+ return obj;
84
+ }
85
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
86
+ if (!value.isObject()) {
87
+ return false;
88
+ }
89
+ jsi::Object obj = value.getObject(runtime);
90
+ if (!nitro::isPlainObject(runtime, obj)) {
91
+ return false;
92
+ }
93
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uri")))) return false;
94
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "durationMs")))) return false;
95
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sizeBytes")))) return false;
96
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sampleRate")))) return false;
97
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "channels")))) return false;
98
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bitDepth")))) return false;
99
+ return true;
100
+ }
101
+ };
102
+
103
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,11 +1,69 @@
1
1
  {
2
2
  "name": "@clarionhq/recorder",
3
- "version": "0.0.1",
4
- "description": "Clarion recorder — placeholder, full release coming soon",
5
- "main": "index.js",
3
+ "version": "0.1.0",
4
+ "description": "Clarion recorder — PCM capture to m4a for React Native (offline-first)",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "react-native": "src/index.ts",
8
+ "source": "src/index.ts",
9
+ "files": [
10
+ "lib",
11
+ "src",
12
+ "android/src",
13
+ "android/build.gradle",
14
+ "android/gradle.properties",
15
+ "android/AndroidManifest.xml",
16
+ "ios",
17
+ "nitrogen",
18
+ "nitro.json",
19
+ "clarionhq-recorder.podspec",
20
+ "README.md",
21
+ "LICENSE",
22
+ "!**/__tests__",
23
+ "!**/__fixtures__",
24
+ "!**/.*"
25
+ ],
26
+ "keywords": [
27
+ "react-native",
28
+ "audio",
29
+ "recorder",
30
+ "pcm",
31
+ "m4a",
32
+ "aac",
33
+ "audiorecord",
34
+ "avaudioengine",
35
+ "nitro-modules",
36
+ "turbomodule",
37
+ "fabric",
38
+ "new-architecture"
39
+ ],
40
+ "dependencies": {
41
+ "@clarionhq/core": "0.1.0"
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=18.3.1",
45
+ "react-native": ">=0.77.0",
46
+ "react-native-nitro-modules": ">=0.35.0"
47
+ },
48
+ "devDependencies": {
49
+ "nitrogen": "^0.35.6",
50
+ "react": "18.3.1",
51
+ "react-native": "0.77.3",
52
+ "react-native-nitro-modules": "^0.35.6"
53
+ },
6
54
  "license": "MIT",
7
- "publishConfig": { "access": "public" },
8
- "repository": { "type": "git", "url": "https://github.com/clarionhq/clarion" },
9
- "homepage": "https://github.com/clarionhq/clarion",
10
- "keywords": ["react-native", "audio", "speech", "voice"]
11
- }
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/Th4nderG0d/clarion",
61
+ "directory": "packages/recorder"
62
+ },
63
+ "scripts": {
64
+ "build": "tsc -p tsconfig.json",
65
+ "typecheck": "tsc -p tsconfig.json --noEmit",
66
+ "nitro:codegen": "nitrogen",
67
+ "clean": "rm -rf lib nitrogen"
68
+ }
69
+ }
@@ -0,0 +1,298 @@
1
+ import {
2
+ ClarionEmitter,
3
+ ClarionError,
4
+ DEFAULT_AUDIO_FORMAT,
5
+ assertTransition,
6
+ type ClarionEngine,
7
+ type ClarionEvent,
8
+ type EngineKind,
9
+ type EngineState,
10
+ type Listener,
11
+ type RecorderEngineConfig,
12
+ type RecorderResult,
13
+ type Unsubscribe,
14
+ } from '@clarionhq/core';
15
+
16
+ import { createNativeRecorder } from './native';
17
+ import type {
18
+ ClarionRecorder,
19
+ NativeRecorderConfig,
20
+ NativeRecorderError,
21
+ NativeRecorderResult,
22
+ } from './specs/ClarionRecorder.nitro';
23
+
24
+ const VALID_STATES: readonly EngineState[] = [
25
+ 'idle',
26
+ 'preparing',
27
+ 'ready',
28
+ 'starting',
29
+ 'recording',
30
+ 'paused',
31
+ 'stopping',
32
+ 'error',
33
+ 'released',
34
+ ];
35
+
36
+ const isEngineState = (s: string): s is EngineState =>
37
+ (VALID_STATES as readonly string[]).includes(s);
38
+
39
+ // 32 kbps is the highest AAC-LC bitrate universally supported across iOS
40
+ // (Simulator + device) and Android for 16 kHz mono. Higher bitrates work
41
+ // on Android but iOS's AAC encoder rejects them with
42
+ // kAudioFormatUnsupportedDataFormatError. Callers can override for higher
43
+ // sample rates / stereo where larger values are accepted.
44
+ const DEFAULT_AAC_BITRATE = 32_000;
45
+ const DEFAULT_AUDIO_LEVEL_INTERVAL_MS = 50;
46
+
47
+ export interface RecorderEngineOptions extends RecorderEngineConfig {
48
+ aacBitrate?: number;
49
+ }
50
+
51
+ export class RecorderEngine implements ClarionEngine {
52
+ readonly kind: EngineKind = 'recorder';
53
+
54
+ private readonly emitter = new ClarionEmitter();
55
+ private readonly native: ClarionRecorder;
56
+ private readonly listenerIds: number[] = [];
57
+ private readonly options: RecorderEngineOptions;
58
+
59
+ private currentState: EngineState = 'idle';
60
+
61
+ constructor(options: RecorderEngineOptions = {}) {
62
+ this.options = options;
63
+ this.native = createNativeRecorder();
64
+ this.bindNativeListeners();
65
+ }
66
+
67
+ get state(): EngineState {
68
+ return this.currentState;
69
+ }
70
+
71
+ on(listener: Listener<ClarionEvent>): Unsubscribe {
72
+ return this.emitter.on(listener);
73
+ }
74
+
75
+ async prepare(): Promise<void> {
76
+ this.transitionTo('preparing');
77
+ try {
78
+ const config = this.buildNativeConfig();
79
+ await this.native.prepare(config);
80
+ // Native side fires state='ready' via the state listener — no JS-side transition needed.
81
+ } catch (err) {
82
+ this.handleNativeError(err, 'prepare');
83
+ throw err;
84
+ }
85
+ }
86
+
87
+ async start(): Promise<void> {
88
+ // Auto-recover from a previous error — caller can retry without manual reset.
89
+ if (this.currentState === 'error') {
90
+ this.setState('idle');
91
+ }
92
+ // Auto-prepare if no session yet — callers don't need to know about prepare().
93
+ if (this.currentState === 'idle') {
94
+ await this.prepare();
95
+ }
96
+ if (this.currentState !== 'ready') {
97
+ throw new ClarionError({
98
+ code: 'INVALID_STATE',
99
+ message: `Cannot start from state '${this.currentState}'`,
100
+ });
101
+ }
102
+ this.transitionTo('starting');
103
+ try {
104
+ await this.native.start();
105
+ // Native side fires state='recording' via the state listener.
106
+ } catch (err) {
107
+ this.handleNativeError(err, 'start');
108
+ throw err;
109
+ }
110
+ }
111
+
112
+ async pause(): Promise<void> {
113
+ if (this.currentState !== 'recording') {
114
+ throw new ClarionError({
115
+ code: 'INVALID_STATE',
116
+ message: `Cannot pause from state '${this.currentState}'`,
117
+ });
118
+ }
119
+ try {
120
+ await this.native.pause();
121
+ } catch (err) {
122
+ this.handleNativeError(err, 'pause');
123
+ throw err;
124
+ }
125
+ }
126
+
127
+ async resume(): Promise<void> {
128
+ if (this.currentState !== 'paused') {
129
+ throw new ClarionError({
130
+ code: 'INVALID_STATE',
131
+ message: `Cannot resume from state '${this.currentState}'`,
132
+ });
133
+ }
134
+ try {
135
+ await this.native.resume();
136
+ } catch (err) {
137
+ this.handleNativeError(err, 'resume');
138
+ throw err;
139
+ }
140
+ }
141
+
142
+ async stop(): Promise<void> {
143
+ this.transitionTo('stopping');
144
+ try {
145
+ const result = await this.native.stop();
146
+ this.emitter.emit({
147
+ type: 'recording-complete',
148
+ result: this.toRecorderResult(result),
149
+ });
150
+ } catch (err) {
151
+ this.handleNativeError(err, 'stop');
152
+ throw err;
153
+ }
154
+ }
155
+
156
+ async discard(): Promise<void> {
157
+ try {
158
+ await this.native.discard();
159
+ } catch (err) {
160
+ this.handleNativeError(err, 'discard');
161
+ throw err;
162
+ }
163
+ }
164
+
165
+ async release(): Promise<void> {
166
+ try {
167
+ this.native.removeAllListeners();
168
+ await this.native.release();
169
+ } finally {
170
+ this.listenerIds.length = 0;
171
+ this.emitter.removeAll();
172
+ this.currentState = 'released';
173
+ }
174
+ }
175
+
176
+ private buildNativeConfig(): NativeRecorderConfig {
177
+ const format = DEFAULT_AUDIO_FORMAT;
178
+ const cfg: NativeRecorderConfig = {
179
+ sampleRate: format.sampleRate,
180
+ channels: format.channels,
181
+ bitDepth: format.bitDepth,
182
+ emitAudioLevel: this.options.emitAudioLevel ?? false,
183
+ audioLevelIntervalMs:
184
+ this.options.audioLevelIntervalMs ?? DEFAULT_AUDIO_LEVEL_INTERVAL_MS,
185
+ aacBitrate: this.options.aacBitrate ?? DEFAULT_AAC_BITRATE,
186
+ };
187
+ if (this.options.outputDirectory !== undefined) {
188
+ cfg.outputDirectory = this.options.outputDirectory;
189
+ }
190
+ if (this.options.filenamePrefix !== undefined) {
191
+ cfg.filenamePrefix = this.options.filenamePrefix;
192
+ }
193
+ if (this.options.rotateAfterMs !== undefined) {
194
+ cfg.rotateAfterMs = this.options.rotateAfterMs;
195
+ }
196
+ return cfg;
197
+ }
198
+
199
+ private bindNativeListeners(): void {
200
+ this.listenerIds.push(
201
+ this.native.addStateListener((nativeState) => {
202
+ if (!isEngineState(nativeState)) return;
203
+ this.setState(nativeState);
204
+ }),
205
+ );
206
+
207
+ this.listenerIds.push(
208
+ this.native.addAudioLevelListener((rms, peak) => {
209
+ this.emitter.emit({ type: 'audio-level', rms, peak });
210
+ }),
211
+ );
212
+
213
+ this.listenerIds.push(
214
+ this.native.addChunkListener((uri, startMs, endMs, sizeBytes) => {
215
+ this.emitter.emit({
216
+ type: 'chunk',
217
+ uri,
218
+ startMs,
219
+ endMs,
220
+ sizeBytes,
221
+ });
222
+ }),
223
+ );
224
+
225
+ this.listenerIds.push(
226
+ this.native.addErrorListener((err) => {
227
+ this.emitter.emit({
228
+ type: 'error',
229
+ error: this.toClarionError(err),
230
+ });
231
+ }),
232
+ );
233
+ }
234
+
235
+ private transitionTo(next: EngineState): void {
236
+ if (this.currentState === next) return;
237
+ assertTransition(this.currentState, next);
238
+ this.setState(next);
239
+ }
240
+
241
+ private setState(next: EngineState): void {
242
+ if (this.currentState === next) return;
243
+ this.currentState = next;
244
+ this.emitter.emit({ type: 'state', state: next });
245
+ }
246
+
247
+ private toRecorderResult(r: NativeRecorderResult): RecorderResult {
248
+ return {
249
+ uri: r.uri,
250
+ durationMs: r.durationMs,
251
+ sizeBytes: r.sizeBytes,
252
+ container: 'm4a',
253
+ audioFormat: {
254
+ sampleRate: r.sampleRate as RecorderResult['audioFormat']['sampleRate'],
255
+ channels: r.channels as RecorderResult['audioFormat']['channels'],
256
+ bitDepth: r.bitDepth as RecorderResult['audioFormat']['bitDepth'],
257
+ },
258
+ };
259
+ }
260
+
261
+ private toClarionError(err: NativeRecorderError): ClarionError {
262
+ return new ClarionError({
263
+ code: this.mapErrorCode(err.code),
264
+ message: err.message,
265
+ recoverable: err.recoverable,
266
+ });
267
+ }
268
+
269
+ private mapErrorCode(
270
+ code: string,
271
+ ): ClarionError['code'] {
272
+ const known: Record<string, ClarionError['code']> = {
273
+ PERMISSION_DENIED: 'PERMISSION_DENIED',
274
+ AUDIO_BUSY: 'AUDIO_BUSY',
275
+ IO_ERROR: 'IO_ERROR',
276
+ INTERRUPTED: 'INTERRUPTED',
277
+ CANCELLED: 'CANCELLED',
278
+ ENGINE_NOT_READY: 'ENGINE_NOT_READY',
279
+ INVALID_STATE: 'INVALID_STATE',
280
+ UNSUPPORTED_FORMAT: 'UNSUPPORTED_FORMAT',
281
+ INTERNAL_ERROR: 'INTERNAL_ERROR',
282
+ };
283
+ return known[code] ?? 'UNKNOWN';
284
+ }
285
+
286
+ private handleNativeError(err: unknown, where: string): void {
287
+ const error =
288
+ err instanceof ClarionError
289
+ ? err
290
+ : new ClarionError({
291
+ code: 'INTERNAL_ERROR',
292
+ message: `Recorder ${where} failed: ${String(err)}`,
293
+ cause: err,
294
+ });
295
+ this.emitter.emit({ type: 'error', error });
296
+ this.setState('error');
297
+ }
298
+ }