react-native-webrtc-nitro 1.0.0 → 1.2.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/android/src/main/java/com/webrtc/HybridCamera.kt +0 -1
- package/android/src/main/java/com/webrtc/HybridMicrophone.kt +0 -1
- package/android/src/main/java/com/webrtc/HybridPermissions.kt +95 -0
- package/cpp/FFmpeg/Muxer.cpp +1 -1
- package/cpp/Hybrid/HybridMediaDevices.cpp +23 -19
- package/cpp/Hybrid/HybridMediaRecorder.cpp +118 -0
- package/cpp/Hybrid/HybridMediaRecorder.hpp +36 -0
- package/cpp/__tests__/FFmpeg/testMuxer.cpp +18 -32
- package/ios/HybridCamera.swift +1 -3
- package/ios/HybridMicrophone.swift +1 -3
- package/ios/HybridPermissions.swift +63 -0
- package/lib/commonjs/index.js +22 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/MediaRecorder.nitro.js +16 -0
- package/lib/commonjs/specs/MediaRecorder.nitro.js.map +1 -0
- package/lib/commonjs/specs/Permissions.nitro.js +9 -0
- package/lib/commonjs/specs/Permissions.nitro.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/MediaRecorder.nitro.js +13 -0
- package/lib/module/specs/MediaRecorder.nitro.js.map +1 -0
- package/lib/module/specs/Permissions.nitro.js +6 -0
- package/lib/module/specs/Permissions.nitro.js.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/MediaRecorder.nitro.d.ts +17 -0
- package/lib/typescript/src/specs/MediaRecorder.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/Permissions.nitro.d.ts +17 -0
- package/lib/typescript/src/specs/Permissions.nitro.d.ts.map +1 -0
- package/nitro.json +7 -0
- package/nitrogen/generated/android/Webrtc+autolinking.cmake +3 -0
- package/nitrogen/generated/android/WebrtcOnLoad.cpp +20 -0
- package/nitrogen/generated/android/c++/JHybridPermissionsSpec.cpp +91 -0
- package/nitrogen/generated/android/c++/JHybridPermissionsSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JPermissionDescriptor.hpp +58 -0
- package/nitrogen/generated/android/c++/JPermissionName.hpp +59 -0
- package/nitrogen/generated/android/c++/JPermissionState.hpp +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/webrtc/HybridPermissionsSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/webrtc/PermissionDescriptor.kt +38 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/webrtc/PermissionName.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/webrtc/PermissionState.kt +22 -0
- package/nitrogen/generated/ios/Webrtc-Swift-Cxx-Bridge.cpp +25 -0
- package/nitrogen/generated/ios/Webrtc-Swift-Cxx-Bridge.hpp +63 -0
- package/nitrogen/generated/ios/Webrtc-Swift-Cxx-Umbrella.hpp +14 -0
- package/nitrogen/generated/ios/WebrtcAutolinking.mm +18 -0
- package/nitrogen/generated/ios/WebrtcAutolinking.swift +15 -0
- package/nitrogen/generated/ios/c++/HybridPermissionsSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridPermissionsSpecSwift.hpp +92 -0
- package/nitrogen/generated/ios/swift/Func_void_PermissionState.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridPermissionsSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridPermissionsSpec_cxx.swift +157 -0
- package/nitrogen/generated/ios/swift/PermissionDescriptor.swift +36 -0
- package/nitrogen/generated/ios/swift/PermissionName.swift +40 -0
- package/nitrogen/generated/ios/swift/PermissionState.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridMediaRecorderSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridMediaRecorderSpec.hpp +69 -0
- package/nitrogen/generated/shared/c++/HybridPermissionsSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridPermissionsSpec.hpp +68 -0
- package/nitrogen/generated/shared/c++/PermissionDescriptor.hpp +76 -0
- package/nitrogen/generated/shared/c++/PermissionName.hpp +76 -0
- package/nitrogen/generated/shared/c++/PermissionState.hpp +80 -0
- package/package.json +4 -5
- package/src/index.ts +2 -0
- package/src/specs/MediaRecorder.nitro.ts +24 -0
- package/src/specs/Permissions.nitro.ts +22 -0
- package/android/src/main/java/com/webrtc/Permission.kt +0 -58
- package/ios/Permission.swift +0 -26
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMediaRecorderSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridMediaRecorderSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::webrtc {
|
|
11
|
+
|
|
12
|
+
void HybridMediaRecorderSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("stream", &HybridMediaRecorderSpec::getStream);
|
|
18
|
+
prototype.registerHybridSetter("stream", &HybridMediaRecorderSpec::setStream);
|
|
19
|
+
prototype.registerHybridMethod("takePhoto", &HybridMediaRecorderSpec::takePhoto);
|
|
20
|
+
prototype.registerHybridMethod("startRecording", &HybridMediaRecorderSpec::startRecording);
|
|
21
|
+
prototype.registerHybridMethod("stopRecording", &HybridMediaRecorderSpec::stopRecording);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace margelo::nitro::webrtc
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMediaRecorderSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `HybridMediaStreamSpec` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::webrtc { class HybridMediaStreamSpec; }
|
|
18
|
+
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include "HybridMediaStreamSpec.hpp"
|
|
21
|
+
#include <NitroModules/Promise.hpp>
|
|
22
|
+
#include <string>
|
|
23
|
+
|
|
24
|
+
namespace margelo::nitro::webrtc {
|
|
25
|
+
|
|
26
|
+
using namespace margelo::nitro;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An abstract base class for `MediaRecorder`
|
|
30
|
+
* Inherit this class to create instances of `HybridMediaRecorderSpec` in C++.
|
|
31
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
32
|
+
* @example
|
|
33
|
+
* ```cpp
|
|
34
|
+
* class HybridMediaRecorder: public HybridMediaRecorderSpec {
|
|
35
|
+
* public:
|
|
36
|
+
* HybridMediaRecorder(...): HybridObject(TAG) { ... }
|
|
37
|
+
* // ...
|
|
38
|
+
* };
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
class HybridMediaRecorderSpec: public virtual HybridObject {
|
|
42
|
+
public:
|
|
43
|
+
// Constructor
|
|
44
|
+
explicit HybridMediaRecorderSpec(): HybridObject(TAG) { }
|
|
45
|
+
|
|
46
|
+
// Destructor
|
|
47
|
+
~HybridMediaRecorderSpec() override = default;
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
// Properties
|
|
51
|
+
virtual std::shared_ptr<HybridMediaStreamSpec> getStream() = 0;
|
|
52
|
+
virtual void setStream(const std::shared_ptr<HybridMediaStreamSpec>& stream) = 0;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Methods
|
|
56
|
+
virtual std::shared_ptr<Promise<void>> takePhoto(const std::string& file) = 0;
|
|
57
|
+
virtual void startRecording(const std::string& file) = 0;
|
|
58
|
+
virtual void stopRecording() = 0;
|
|
59
|
+
|
|
60
|
+
protected:
|
|
61
|
+
// Hybrid Setup
|
|
62
|
+
void loadHybridMethods() override;
|
|
63
|
+
|
|
64
|
+
protected:
|
|
65
|
+
// Tag for logging
|
|
66
|
+
static constexpr auto TAG = "MediaRecorder";
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace margelo::nitro::webrtc
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPermissionsSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridPermissionsSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::webrtc {
|
|
11
|
+
|
|
12
|
+
void HybridPermissionsSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("query", &HybridPermissionsSpec::query);
|
|
18
|
+
prototype.registerHybridMethod("request", &HybridPermissionsSpec::request);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace margelo::nitro::webrtc
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPermissionsSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `PermissionState` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::webrtc { enum class PermissionState; }
|
|
18
|
+
// Forward declaration of `PermissionDescriptor` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::webrtc { struct PermissionDescriptor; }
|
|
20
|
+
|
|
21
|
+
#include "PermissionState.hpp"
|
|
22
|
+
#include <NitroModules/Promise.hpp>
|
|
23
|
+
#include "PermissionDescriptor.hpp"
|
|
24
|
+
|
|
25
|
+
namespace margelo::nitro::webrtc {
|
|
26
|
+
|
|
27
|
+
using namespace margelo::nitro;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An abstract base class for `Permissions`
|
|
31
|
+
* Inherit this class to create instances of `HybridPermissionsSpec` in C++.
|
|
32
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
33
|
+
* @example
|
|
34
|
+
* ```cpp
|
|
35
|
+
* class HybridPermissions: public HybridPermissionsSpec {
|
|
36
|
+
* public:
|
|
37
|
+
* HybridPermissions(...): HybridObject(TAG) { ... }
|
|
38
|
+
* // ...
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
class HybridPermissionsSpec: public virtual HybridObject {
|
|
43
|
+
public:
|
|
44
|
+
// Constructor
|
|
45
|
+
explicit HybridPermissionsSpec(): HybridObject(TAG) { }
|
|
46
|
+
|
|
47
|
+
// Destructor
|
|
48
|
+
~HybridPermissionsSpec() override = default;
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
// Properties
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Methods
|
|
56
|
+
virtual std::shared_ptr<Promise<PermissionState>> query(const PermissionDescriptor& permissionDesc) = 0;
|
|
57
|
+
virtual std::shared_ptr<Promise<PermissionState>> request(const PermissionDescriptor& permissionDesc) = 0;
|
|
58
|
+
|
|
59
|
+
protected:
|
|
60
|
+
// Hybrid Setup
|
|
61
|
+
void loadHybridMethods() override;
|
|
62
|
+
|
|
63
|
+
protected:
|
|
64
|
+
// Tag for logging
|
|
65
|
+
static constexpr auto TAG = "Permissions";
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace margelo::nitro::webrtc
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PermissionDescriptor.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 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
|
+
|
|
26
|
+
// Forward declaration of `PermissionName` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::webrtc { enum class PermissionName; }
|
|
28
|
+
|
|
29
|
+
#include "PermissionName.hpp"
|
|
30
|
+
|
|
31
|
+
namespace margelo::nitro::webrtc {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A struct which can be represented as a JavaScript object (PermissionDescriptor).
|
|
35
|
+
*/
|
|
36
|
+
struct PermissionDescriptor {
|
|
37
|
+
public:
|
|
38
|
+
PermissionName name SWIFT_PRIVATE;
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
PermissionDescriptor() = default;
|
|
42
|
+
explicit PermissionDescriptor(PermissionName name): name(name) {}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
} // namespace margelo::nitro::webrtc
|
|
46
|
+
|
|
47
|
+
namespace margelo::nitro {
|
|
48
|
+
|
|
49
|
+
// C++ PermissionDescriptor <> JS PermissionDescriptor (object)
|
|
50
|
+
template <>
|
|
51
|
+
struct JSIConverter<margelo::nitro::webrtc::PermissionDescriptor> final {
|
|
52
|
+
static inline margelo::nitro::webrtc::PermissionDescriptor fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
53
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
54
|
+
return margelo::nitro::webrtc::PermissionDescriptor(
|
|
55
|
+
JSIConverter<margelo::nitro::webrtc::PermissionName>::fromJSI(runtime, obj.getProperty(runtime, "name"))
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::webrtc::PermissionDescriptor& arg) {
|
|
59
|
+
jsi::Object obj(runtime);
|
|
60
|
+
obj.setProperty(runtime, "name", JSIConverter<margelo::nitro::webrtc::PermissionName>::toJSI(runtime, arg.name));
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
64
|
+
if (!value.isObject()) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
jsi::Object obj = value.getObject(runtime);
|
|
68
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (!JSIConverter<margelo::nitro::webrtc::PermissionName>::canConvert(runtime, obj.getProperty(runtime, "name"))) return false;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PermissionName.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::webrtc {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (PermissionName).
|
|
30
|
+
*/
|
|
31
|
+
enum class PermissionName {
|
|
32
|
+
CAMERA SWIFT_NAME(camera) = 0,
|
|
33
|
+
MICROPHONE SWIFT_NAME(microphone) = 1,
|
|
34
|
+
} CLOSED_ENUM;
|
|
35
|
+
|
|
36
|
+
} // namespace margelo::nitro::webrtc
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro {
|
|
39
|
+
|
|
40
|
+
// C++ PermissionName <> JS PermissionName (union)
|
|
41
|
+
template <>
|
|
42
|
+
struct JSIConverter<margelo::nitro::webrtc::PermissionName> final {
|
|
43
|
+
static inline margelo::nitro::webrtc::PermissionName fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
44
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
45
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
46
|
+
case hashString("camera"): return margelo::nitro::webrtc::PermissionName::CAMERA;
|
|
47
|
+
case hashString("microphone"): return margelo::nitro::webrtc::PermissionName::MICROPHONE;
|
|
48
|
+
default: [[unlikely]]
|
|
49
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PermissionName - invalid value!");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::webrtc::PermissionName arg) {
|
|
53
|
+
switch (arg) {
|
|
54
|
+
case margelo::nitro::webrtc::PermissionName::CAMERA: return JSIConverter<std::string>::toJSI(runtime, "camera");
|
|
55
|
+
case margelo::nitro::webrtc::PermissionName::MICROPHONE: return JSIConverter<std::string>::toJSI(runtime, "microphone");
|
|
56
|
+
default: [[unlikely]]
|
|
57
|
+
throw std::invalid_argument("Cannot convert PermissionName to JS - invalid value: "
|
|
58
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
62
|
+
if (!value.isString()) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
66
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
67
|
+
case hashString("camera"):
|
|
68
|
+
case hashString("microphone"):
|
|
69
|
+
return true;
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PermissionState.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::webrtc {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (PermissionState).
|
|
30
|
+
*/
|
|
31
|
+
enum class PermissionState {
|
|
32
|
+
DENIED SWIFT_NAME(denied) = 0,
|
|
33
|
+
GRANTED SWIFT_NAME(granted) = 1,
|
|
34
|
+
PROMPT SWIFT_NAME(prompt) = 2,
|
|
35
|
+
} CLOSED_ENUM;
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro::webrtc
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro {
|
|
40
|
+
|
|
41
|
+
// C++ PermissionState <> JS PermissionState (union)
|
|
42
|
+
template <>
|
|
43
|
+
struct JSIConverter<margelo::nitro::webrtc::PermissionState> final {
|
|
44
|
+
static inline margelo::nitro::webrtc::PermissionState fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
45
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
46
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
47
|
+
case hashString("denied"): return margelo::nitro::webrtc::PermissionState::DENIED;
|
|
48
|
+
case hashString("granted"): return margelo::nitro::webrtc::PermissionState::GRANTED;
|
|
49
|
+
case hashString("prompt"): return margelo::nitro::webrtc::PermissionState::PROMPT;
|
|
50
|
+
default: [[unlikely]]
|
|
51
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PermissionState - invalid value!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::webrtc::PermissionState arg) {
|
|
55
|
+
switch (arg) {
|
|
56
|
+
case margelo::nitro::webrtc::PermissionState::DENIED: return JSIConverter<std::string>::toJSI(runtime, "denied");
|
|
57
|
+
case margelo::nitro::webrtc::PermissionState::GRANTED: return JSIConverter<std::string>::toJSI(runtime, "granted");
|
|
58
|
+
case margelo::nitro::webrtc::PermissionState::PROMPT: return JSIConverter<std::string>::toJSI(runtime, "prompt");
|
|
59
|
+
default: [[unlikely]]
|
|
60
|
+
throw std::invalid_argument("Cannot convert PermissionState to JS - invalid value: "
|
|
61
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
65
|
+
if (!value.isString()) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
69
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
70
|
+
case hashString("denied"):
|
|
71
|
+
case hashString("granted"):
|
|
72
|
+
case hashString("prompt"):
|
|
73
|
+
return true;
|
|
74
|
+
default:
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-webrtc-nitro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Nitro WebRTC module for React Native",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"build": "pnpm run typecheck && bob build",
|
|
15
15
|
"codegen": "nitrogen --logLevel=\"debug\" && pnpm run build && node post-script.js",
|
|
16
16
|
"lint": "pnpm run lint:cpp",
|
|
17
|
-
"lint:cpp": "find cpp -path cpp/__tests__/build -prune -o \\( -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.hpp\" \\) -type f -print0 | xargs -0 clang-format -n --Werror -style=file"
|
|
18
|
-
"outtt": "which clang-format"
|
|
17
|
+
"lint:cpp": "find cpp -path cpp/__tests__/build -prune -o \\( -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.hpp\" \\) -type f -print0 | xargs -0 clang-format -n --Werror -style=file"
|
|
19
18
|
},
|
|
20
19
|
"keywords": [
|
|
21
20
|
"react-native",
|
|
@@ -61,8 +60,8 @@
|
|
|
61
60
|
"clang-format-node": "^2.0.5",
|
|
62
61
|
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
63
62
|
"nitrogen": "0.31.10",
|
|
64
|
-
"react": "19.
|
|
65
|
-
"react-native": "0.
|
|
63
|
+
"react": "19.1.1",
|
|
64
|
+
"react-native": "0.82.1",
|
|
66
65
|
"react-native-builder-bob": "^0.40.16",
|
|
67
66
|
"react-native-nitro-modules": "0.31.10",
|
|
68
67
|
"semantic-release": "^25.0.2",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './views/WebrtcView'
|
|
2
|
+
export * from './specs/Permissions.nitro'
|
|
2
3
|
export * from './specs/MediaDevices.nitro'
|
|
3
4
|
export * from './specs/MediaStream.nitro'
|
|
4
5
|
export * from './specs/MediaStreamTrack.nitro'
|
|
@@ -6,3 +7,4 @@ export * from './specs/RTCPeerConnection.nitro'
|
|
|
6
7
|
export * from './specs/RTCRtpSender.nitro'
|
|
7
8
|
export * from './specs/RTCRtpReceiver.nitro'
|
|
8
9
|
export * from './specs/RTCRtpTransceiver.nitro'
|
|
10
|
+
export * from './specs/MediaRecorder.nitro'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type HybridObject } from 'react-native-nitro-modules'
|
|
2
|
+
import { getHybridObjectConstructor } from 'react-native-nitro-modules'
|
|
3
|
+
import { MediaStream } from './MediaStream.nitro'
|
|
4
|
+
|
|
5
|
+
interface MediaRecorder extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
6
|
+
stream: MediaStream
|
|
7
|
+
takePhoto(file: string): Promise<void>
|
|
8
|
+
startRecording(file: string): void
|
|
9
|
+
stopRecording(): void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const MediaRecorderConstructor =
|
|
13
|
+
getHybridObjectConstructor<MediaRecorder>('MediaRecorder')
|
|
14
|
+
|
|
15
|
+
const MediaRecorderExport = new Proxy(MediaRecorderConstructor, {
|
|
16
|
+
construct(target, args) {
|
|
17
|
+
const instance = new target()
|
|
18
|
+
instance.stream = args[0] as MediaStream
|
|
19
|
+
return instance
|
|
20
|
+
},
|
|
21
|
+
}) as { new (stream: MediaStream): MediaRecorder }
|
|
22
|
+
|
|
23
|
+
type MediaRecorderExport = MediaRecorder
|
|
24
|
+
export { MediaRecorderExport as MediaRecorder }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type HybridObject } from 'react-native-nitro-modules'
|
|
2
|
+
import { NitroModules } from 'react-native-nitro-modules'
|
|
3
|
+
|
|
4
|
+
export type PermissionState = 'denied' | 'granted' | 'prompt'
|
|
5
|
+
type PermissionName = 'camera' | 'microphone'
|
|
6
|
+
|
|
7
|
+
export interface PermissionDescriptor {
|
|
8
|
+
name: PermissionName
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Permissions extends HybridObject<{
|
|
12
|
+
ios: 'swift'
|
|
13
|
+
android: 'kotlin'
|
|
14
|
+
}> {
|
|
15
|
+
query(permissionDesc: PermissionDescriptor): Promise<PermissionState>
|
|
16
|
+
request(permissionDesc: PermissionDescriptor): Promise<PermissionState>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const PermissionsExport =
|
|
20
|
+
NitroModules.createHybridObject<Permissions>('Permissions')
|
|
21
|
+
type PermissionsExport = Permissions
|
|
22
|
+
export { PermissionsExport as Permissions }
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
package com.webrtc
|
|
2
|
-
|
|
3
|
-
import android.content.pm.PackageManager
|
|
4
|
-
import androidx.core.content.ContextCompat
|
|
5
|
-
import com.facebook.react.modules.core.PermissionAwareActivity
|
|
6
|
-
import com.facebook.react.modules.core.PermissionListener
|
|
7
|
-
import kotlin.random.Random
|
|
8
|
-
import kotlinx.coroutines.CompletableDeferred
|
|
9
|
-
import com.margelo.nitro.NitroModules
|
|
10
|
-
|
|
11
|
-
suspend fun requestPermission(permission: String) {
|
|
12
|
-
val context = NitroModules.applicationContext
|
|
13
|
-
?: throw RuntimeException("ReactApplicationContext is not available")
|
|
14
|
-
|
|
15
|
-
val currentActivity = context.currentActivity
|
|
16
|
-
?: throw RuntimeException("No current Activity")
|
|
17
|
-
|
|
18
|
-
if (ContextCompat.checkSelfPermission(context, permission)
|
|
19
|
-
== PackageManager.PERMISSION_GRANTED
|
|
20
|
-
) {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (currentActivity !is PermissionAwareActivity) {
|
|
25
|
-
throw RuntimeException("Current activity doesn't support permissions")
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
val code = Random.nextInt(0, 65535)
|
|
29
|
-
val deferred = CompletableDeferred<Unit>()
|
|
30
|
-
|
|
31
|
-
val listener = object : PermissionListener {
|
|
32
|
-
override fun onRequestPermissionsResult(
|
|
33
|
-
requestCode: Int,
|
|
34
|
-
permissions: Array<String>,
|
|
35
|
-
grantResults: IntArray
|
|
36
|
-
): Boolean {
|
|
37
|
-
if (requestCode != code) return false
|
|
38
|
-
|
|
39
|
-
if (permissions.isEmpty() || grantResults.isEmpty() ||
|
|
40
|
-
grantResults[0] != PackageManager.PERMISSION_GRANTED
|
|
41
|
-
) {
|
|
42
|
-
deferred.completeExceptionally(
|
|
43
|
-
RuntimeException("Permission denied by user")
|
|
44
|
-
)
|
|
45
|
-
} else {
|
|
46
|
-
deferred.complete(Unit)
|
|
47
|
-
}
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
currentActivity.requestPermissions(
|
|
53
|
-
arrayOf(permission),
|
|
54
|
-
code,
|
|
55
|
-
listener
|
|
56
|
-
)
|
|
57
|
-
deferred.await()
|
|
58
|
-
}
|
package/ios/Permission.swift
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import AVFoundation
|
|
2
|
-
import Foundation
|
|
3
|
-
import NitroModules
|
|
4
|
-
|
|
5
|
-
public func requestPermission(for mediaType: AVMediaType) async throws {
|
|
6
|
-
let status = AVCaptureDevice.authorizationStatus(for: mediaType)
|
|
7
|
-
switch status {
|
|
8
|
-
case .authorized:
|
|
9
|
-
return
|
|
10
|
-
case .notDetermined:
|
|
11
|
-
let granted = await withCheckedContinuation { (continuation) in
|
|
12
|
-
AVCaptureDevice.requestAccess(for: mediaType) { ok in
|
|
13
|
-
continuation.resume(returning: ok)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if granted {
|
|
17
|
-
return
|
|
18
|
-
} else {
|
|
19
|
-
throw RuntimeError.error(withMessage: "Permission not allowed")
|
|
20
|
-
}
|
|
21
|
-
case .denied, .restricted:
|
|
22
|
-
throw RuntimeError.error(withMessage: "Permission not allowed")
|
|
23
|
-
@unknown default:
|
|
24
|
-
throw RuntimeError.error(withMessage: "Permission not allowed")
|
|
25
|
-
}
|
|
26
|
-
}
|