@shamilovtim/react-native-nitro-sse 2.3.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/LICENSE +21 -0
- package/NitroSse.podspec +37 -0
- package/README.md +144 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +124 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/cpp/cpp-adapter.cpp +10 -0
- package/android/src/main/java/com/margelo/nitro/nitrosse/NetworkInspector.kt +94 -0
- package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +889 -0
- package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSsePackage.kt +22 -0
- package/ios/NitroSse.swift +760 -0
- package/ios/NitroSseNetworkInspector.h +24 -0
- package/ios/NitroSseNetworkInspector.mm +68 -0
- package/lib/module/NitroSse.nitro.js +4 -0
- package/lib/module/NitroSse.nitro.js.map +1 -0
- package/lib/module/NitroSseClient.js +244 -0
- package/lib/module/NitroSseClient.js.map +1 -0
- package/lib/module/SseInterface.js +4 -0
- package/lib/module/SseInterface.js.map +1 -0
- package/lib/module/index.js +26 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NitroSse.nitro.d.ts +48 -0
- package/lib/typescript/src/NitroSse.nitro.d.ts.map +1 -0
- package/lib/typescript/src/NitroSseClient.d.ts +26 -0
- package/lib/typescript/src/NitroSseClient.d.ts.map +1 -0
- package/lib/typescript/src/SseInterface.d.ts +237 -0
- package/lib/typescript/src/SseInterface.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp +138 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_SseEvent_.hpp +102 -0
- package/nitrogen/generated/android/c++/JHttpMethod.hpp +58 -0
- package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +134 -0
- package/nitrogen/generated/android/c++/JHybridNitroSseSpec.hpp +71 -0
- package/nitrogen/generated/android/c++/JSseConfig.hpp +162 -0
- package/nitrogen/generated/android/c++/JSseEvent.hpp +90 -0
- package/nitrogen/generated/android/c++/JSseEventType.hpp +67 -0
- package/nitrogen/generated/android/c++/JSseMockConfig.hpp +101 -0
- package/nitrogen/generated/android/c++/JSseMockEvent.hpp +94 -0
- package/nitrogen/generated/android/c++/JSseMockMode.hpp +58 -0
- package/nitrogen/generated/android/c++/JSseStats.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/Func_void_std__vector_SseEvent_.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/HttpMethod.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/HybridNitroSseSpec.kt +91 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +135 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +86 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEventType.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockConfig.kt +71 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockEvent.kt +91 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockMode.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseStats.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/nitrosseOnLoad.kt +35 -0
- package/nitrogen/generated/android/nitrosse+autolinking.cmake +81 -0
- package/nitrogen/generated/android/nitrosse+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nitrosseOnLoad.cpp +58 -0
- package/nitrogen/generated/android/nitrosseOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/NitroSse+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +74 -0
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +415 -0
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +74 -0
- package/nitrogen/generated/ios/NitroSseAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroSseAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +161 -0
- package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.swift +67 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___.swift +66 -0
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_SseEvent_.swift +46 -0
- package/nitrogen/generated/ios/swift/HttpMethod.swift +40 -0
- package/nitrogen/generated/ios/swift/HybridNitroSseSpec.swift +63 -0
- package/nitrogen/generated/ios/swift/HybridNitroSseSpec_cxx.swift +246 -0
- package/nitrogen/generated/ios/swift/SseConfig.swift +346 -0
- package/nitrogen/generated/ios/swift/SseEvent.swift +155 -0
- package/nitrogen/generated/ios/swift/SseEventType.swift +52 -0
- package/nitrogen/generated/ios/swift/SseMockConfig.swift +94 -0
- package/nitrogen/generated/ios/swift/SseMockEvent.swift +179 -0
- package/nitrogen/generated/ios/swift/SseMockMode.swift +40 -0
- package/nitrogen/generated/ios/swift/SseStats.swift +70 -0
- package/nitrogen/generated/shared/c++/HttpMethod.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridNitroSseSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridNitroSseSpec.hpp +81 -0
- package/nitrogen/generated/shared/c++/SseConfig.hpp +156 -0
- package/nitrogen/generated/shared/c++/SseEvent.hpp +115 -0
- package/nitrogen/generated/shared/c++/SseEventType.hpp +88 -0
- package/nitrogen/generated/shared/c++/SseMockConfig.hpp +105 -0
- package/nitrogen/generated/shared/c++/SseMockEvent.hpp +119 -0
- package/nitrogen/generated/shared/c++/SseMockMode.hpp +76 -0
- package/nitrogen/generated/shared/c++/SseStats.hpp +96 -0
- package/package.json +186 -0
- package/src/NitroSse.nitro.ts +53 -0
- package/src/NitroSseClient.ts +297 -0
- package/src/SseInterface.ts +248 -0
- package/src/index.ts +31 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// SseMockEvent.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
|
+
// Forward declaration of `SseEventType` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::nitrosse { enum class SseEventType; }
|
|
33
|
+
|
|
34
|
+
#include "SseEventType.hpp"
|
|
35
|
+
#include <optional>
|
|
36
|
+
#include <string>
|
|
37
|
+
#include <NitroModules/AnyMap.hpp>
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::nitrosse {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (SseMockEvent).
|
|
43
|
+
*/
|
|
44
|
+
struct SseMockEvent final {
|
|
45
|
+
public:
|
|
46
|
+
std::optional<SseEventType> type SWIFT_PRIVATE;
|
|
47
|
+
std::optional<std::string> data SWIFT_PRIVATE;
|
|
48
|
+
std::optional<std::shared_ptr<AnyMap>> parsedData SWIFT_PRIVATE;
|
|
49
|
+
std::optional<std::string> id SWIFT_PRIVATE;
|
|
50
|
+
std::optional<std::string> event SWIFT_PRIVATE;
|
|
51
|
+
std::optional<std::string> message SWIFT_PRIVATE;
|
|
52
|
+
std::optional<double> statusCode SWIFT_PRIVATE;
|
|
53
|
+
std::optional<double> retry SWIFT_PRIVATE;
|
|
54
|
+
std::optional<double> delayMs SWIFT_PRIVATE;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
SseMockEvent() = default;
|
|
58
|
+
explicit SseMockEvent(std::optional<SseEventType> type, std::optional<std::string> data, std::optional<std::shared_ptr<AnyMap>> parsedData, std::optional<std::string> id, std::optional<std::string> event, std::optional<std::string> message, std::optional<double> statusCode, std::optional<double> retry, std::optional<double> delayMs): type(type), data(data), parsedData(parsedData), id(id), event(event), message(message), statusCode(statusCode), retry(retry), delayMs(delayMs) {}
|
|
59
|
+
|
|
60
|
+
public:
|
|
61
|
+
friend bool operator==(const SseMockEvent& lhs, const SseMockEvent& rhs) = default;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace margelo::nitro::nitrosse
|
|
65
|
+
|
|
66
|
+
namespace margelo::nitro {
|
|
67
|
+
|
|
68
|
+
// C++ SseMockEvent <> JS SseMockEvent (object)
|
|
69
|
+
template <>
|
|
70
|
+
struct JSIConverter<margelo::nitro::nitrosse::SseMockEvent> final {
|
|
71
|
+
static inline margelo::nitro::nitrosse::SseMockEvent fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
72
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
73
|
+
return margelo::nitro::nitrosse::SseMockEvent(
|
|
74
|
+
JSIConverter<std::optional<margelo::nitro::nitrosse::SseEventType>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type"))),
|
|
75
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data"))),
|
|
76
|
+
JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parsedData"))),
|
|
77
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
|
|
78
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event"))),
|
|
79
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message"))),
|
|
80
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode"))),
|
|
81
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry"))),
|
|
82
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "delayMs")))
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseMockEvent& arg) {
|
|
86
|
+
jsi::Object obj(runtime);
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "type"), JSIConverter<std::optional<margelo::nitro::nitrosse::SseEventType>>::toJSI(runtime, arg.type));
|
|
88
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "data"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.data));
|
|
89
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "parsedData"), JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::toJSI(runtime, arg.parsedData));
|
|
90
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.id));
|
|
91
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "event"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.event));
|
|
92
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "message"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.message));
|
|
93
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "statusCode"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.statusCode));
|
|
94
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "retry"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.retry));
|
|
95
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "delayMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.delayMs));
|
|
96
|
+
return obj;
|
|
97
|
+
}
|
|
98
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
99
|
+
if (!value.isObject()) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
jsi::Object obj = value.getObject(runtime);
|
|
103
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (!JSIConverter<std::optional<margelo::nitro::nitrosse::SseEventType>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type")))) return false;
|
|
107
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))) return false;
|
|
108
|
+
if (!JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parsedData")))) return false;
|
|
109
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id")))) return false;
|
|
110
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event")))) return false;
|
|
111
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))) return false;
|
|
112
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode")))) return false;
|
|
113
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))) return false;
|
|
114
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "delayMs")))) return false;
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// SseMockMode.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/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::nitrosse {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (SseMockMode).
|
|
30
|
+
*/
|
|
31
|
+
enum class SseMockMode {
|
|
32
|
+
REPLACE SWIFT_NAME(replace) = 0,
|
|
33
|
+
INJECT SWIFT_NAME(inject) = 1,
|
|
34
|
+
} CLOSED_ENUM;
|
|
35
|
+
|
|
36
|
+
} // namespace margelo::nitro::nitrosse
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro {
|
|
39
|
+
|
|
40
|
+
// C++ SseMockMode <> JS SseMockMode (union)
|
|
41
|
+
template <>
|
|
42
|
+
struct JSIConverter<margelo::nitro::nitrosse::SseMockMode> final {
|
|
43
|
+
static inline margelo::nitro::nitrosse::SseMockMode 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("replace"): return margelo::nitro::nitrosse::SseMockMode::REPLACE;
|
|
47
|
+
case hashString("inject"): return margelo::nitro::nitrosse::SseMockMode::INJECT;
|
|
48
|
+
default: [[unlikely]]
|
|
49
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum SseMockMode - invalid value!");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrosse::SseMockMode arg) {
|
|
53
|
+
switch (arg) {
|
|
54
|
+
case margelo::nitro::nitrosse::SseMockMode::REPLACE: return JSIConverter<std::string>::toJSI(runtime, "replace");
|
|
55
|
+
case margelo::nitro::nitrosse::SseMockMode::INJECT: return JSIConverter<std::string>::toJSI(runtime, "inject");
|
|
56
|
+
default: [[unlikely]]
|
|
57
|
+
throw std::invalid_argument("Cannot convert SseMockMode 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("replace"):
|
|
68
|
+
case hashString("inject"):
|
|
69
|
+
return true;
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// SseStats.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 <optional>
|
|
34
|
+
#include <string>
|
|
35
|
+
|
|
36
|
+
namespace margelo::nitro::nitrosse {
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A struct which can be represented as a JavaScript object (SseStats).
|
|
40
|
+
*/
|
|
41
|
+
struct SseStats final {
|
|
42
|
+
public:
|
|
43
|
+
double totalBytesReceived SWIFT_PRIVATE;
|
|
44
|
+
double reconnectCount SWIFT_PRIVATE;
|
|
45
|
+
std::optional<double> lastErrorTime SWIFT_PRIVATE;
|
|
46
|
+
std::optional<std::string> lastErrorCode SWIFT_PRIVATE;
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
SseStats() = default;
|
|
50
|
+
explicit SseStats(double totalBytesReceived, double reconnectCount, std::optional<double> lastErrorTime, std::optional<std::string> lastErrorCode): totalBytesReceived(totalBytesReceived), reconnectCount(reconnectCount), lastErrorTime(lastErrorTime), lastErrorCode(lastErrorCode) {}
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
friend bool operator==(const SseStats& lhs, const SseStats& rhs) = default;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
} // namespace margelo::nitro::nitrosse
|
|
57
|
+
|
|
58
|
+
namespace margelo::nitro {
|
|
59
|
+
|
|
60
|
+
// C++ SseStats <> JS SseStats (object)
|
|
61
|
+
template <>
|
|
62
|
+
struct JSIConverter<margelo::nitro::nitrosse::SseStats> final {
|
|
63
|
+
static inline margelo::nitro::nitrosse::SseStats fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
64
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
65
|
+
return margelo::nitro::nitrosse::SseStats(
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "totalBytesReceived"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "reconnectCount"))),
|
|
68
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastErrorTime"))),
|
|
69
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastErrorCode")))
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseStats& arg) {
|
|
73
|
+
jsi::Object obj(runtime);
|
|
74
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "totalBytesReceived"), JSIConverter<double>::toJSI(runtime, arg.totalBytesReceived));
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "reconnectCount"), JSIConverter<double>::toJSI(runtime, arg.reconnectCount));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "lastErrorTime"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.lastErrorTime));
|
|
77
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "lastErrorCode"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.lastErrorCode));
|
|
78
|
+
return obj;
|
|
79
|
+
}
|
|
80
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
81
|
+
if (!value.isObject()) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
jsi::Object obj = value.getObject(runtime);
|
|
85
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "totalBytesReceived")))) return false;
|
|
89
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "reconnectCount")))) return false;
|
|
90
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastErrorTime")))) return false;
|
|
91
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastErrorCode")))) return false;
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
} // namespace margelo::nitro
|
package/package.json
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shamilovtim/react-native-nitro-sse",
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "High-performance Server-Sent Events (SSE) for React Native, powered by Nitro Modules.",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"nitrogen",
|
|
22
|
+
"nitro.json",
|
|
23
|
+
"*.podspec",
|
|
24
|
+
"react-native.config.js",
|
|
25
|
+
"!ios/build",
|
|
26
|
+
"!ios/Tests",
|
|
27
|
+
"!android/build",
|
|
28
|
+
"!android/src/test",
|
|
29
|
+
"!android/gradle",
|
|
30
|
+
"!android/gradlew",
|
|
31
|
+
"!android/gradlew.bat",
|
|
32
|
+
"!android/local.properties",
|
|
33
|
+
"!**/__tests__",
|
|
34
|
+
"!**/__fixtures__",
|
|
35
|
+
"!**/__mocks__",
|
|
36
|
+
"!**/.*"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"example": "yarn workspace react-native-nitro-sse-example",
|
|
40
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
41
|
+
"prepare": "bob build",
|
|
42
|
+
"nitrogen": "nitrogen",
|
|
43
|
+
"typecheck": "tsc",
|
|
44
|
+
"test": "jest",
|
|
45
|
+
"test:android": "cd example/android && ./gradlew :react-native-nitro-sse:testDebugUnitTest",
|
|
46
|
+
"test:ios": "cd example/ios && xcodebuild test -workspace NitroSseExample.xcworkspace -scheme NitroSse -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16'",
|
|
47
|
+
"test:native": "yarn test:android && yarn test:ios",
|
|
48
|
+
"release": "release-it --only-version",
|
|
49
|
+
"server": "node example/sse-server.js",
|
|
50
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\""
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"react-native",
|
|
54
|
+
"ios",
|
|
55
|
+
"android",
|
|
56
|
+
"sse",
|
|
57
|
+
"server-sent-events",
|
|
58
|
+
"streaming",
|
|
59
|
+
"nitro",
|
|
60
|
+
"jsi"
|
|
61
|
+
],
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "git+https://github.com/shamilovtim/react-native-nitro-sse.git"
|
|
65
|
+
},
|
|
66
|
+
"author": "IAmTester35 <maithanhnam141@gmail.com> (https://github.com/IAmTester35)",
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/shamilovtim/react-native-nitro-sse/issues"
|
|
70
|
+
},
|
|
71
|
+
"homepage": "https://github.com/shamilovtim/react-native-nitro-sse#readme",
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"registry": "https://registry.npmjs.org/",
|
|
74
|
+
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
78
|
+
"@eslint/compat": "^1.3.2",
|
|
79
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
80
|
+
"@eslint/js": "^9.35.0",
|
|
81
|
+
"@react-native/babel-preset": "0.83.4",
|
|
82
|
+
"@react-native/eslint-config": "0.83.4",
|
|
83
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
84
|
+
"@types/jest": "^29.5.14",
|
|
85
|
+
"@types/react": "^19.2.0",
|
|
86
|
+
"commitlint": "^19.8.1",
|
|
87
|
+
"del-cli": "^6.0.0",
|
|
88
|
+
"eslint": "^9.35.0",
|
|
89
|
+
"eslint-config-prettier": "^10.1.8",
|
|
90
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
91
|
+
"jest": "^29.7.0",
|
|
92
|
+
"lefthook": "^2.0.3",
|
|
93
|
+
"nitrogen": "0.35.6",
|
|
94
|
+
"prettier": "^2.8.8",
|
|
95
|
+
"react": "19.2.0",
|
|
96
|
+
"react-native": "0.83.4",
|
|
97
|
+
"react-native-builder-bob": "^0.40.17",
|
|
98
|
+
"react-native-nitro-modules": "0.35.6",
|
|
99
|
+
"release-it": "^19.0.4",
|
|
100
|
+
"turbo": "^2.5.6",
|
|
101
|
+
"typescript": "^5.9.2"
|
|
102
|
+
},
|
|
103
|
+
"peerDependencies": {
|
|
104
|
+
"react": "*",
|
|
105
|
+
"react-native": "*",
|
|
106
|
+
"react-native-nitro-modules": ">= 0.35.6"
|
|
107
|
+
},
|
|
108
|
+
"workspaces": [
|
|
109
|
+
"example"
|
|
110
|
+
],
|
|
111
|
+
"packageManager": "yarn@4.11.0",
|
|
112
|
+
"react-native-builder-bob": {
|
|
113
|
+
"source": "src",
|
|
114
|
+
"output": "lib",
|
|
115
|
+
"targets": [
|
|
116
|
+
[
|
|
117
|
+
"custom",
|
|
118
|
+
{
|
|
119
|
+
"script": "nitrogen",
|
|
120
|
+
"clean": "nitrogen/"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
"module",
|
|
125
|
+
{
|
|
126
|
+
"esm": true
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
"typescript",
|
|
131
|
+
{
|
|
132
|
+
"project": "tsconfig.build.json"
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
"jest": {
|
|
138
|
+
"preset": "react-native",
|
|
139
|
+
"modulePathIgnorePatterns": [
|
|
140
|
+
"<rootDir>/example/node_modules",
|
|
141
|
+
"<rootDir>/lib/"
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
"commitlint": {
|
|
145
|
+
"extends": [
|
|
146
|
+
"@commitlint/config-conventional"
|
|
147
|
+
]
|
|
148
|
+
},
|
|
149
|
+
"release-it": {
|
|
150
|
+
"git": {
|
|
151
|
+
"commitMessage": "chore: release ${version}",
|
|
152
|
+
"tagName": "v${version}"
|
|
153
|
+
},
|
|
154
|
+
"npm": {
|
|
155
|
+
"publish": true
|
|
156
|
+
},
|
|
157
|
+
"github": {
|
|
158
|
+
"release": true
|
|
159
|
+
},
|
|
160
|
+
"plugins": {
|
|
161
|
+
"@release-it/conventional-changelog": {
|
|
162
|
+
"preset": {
|
|
163
|
+
"name": "angular"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"prettier": {
|
|
169
|
+
"quoteProps": "consistent",
|
|
170
|
+
"singleQuote": true,
|
|
171
|
+
"tabWidth": 2,
|
|
172
|
+
"trailingComma": "es5",
|
|
173
|
+
"useTabs": false
|
|
174
|
+
},
|
|
175
|
+
"create-react-native-library": {
|
|
176
|
+
"type": "nitro-module",
|
|
177
|
+
"languages": "kotlin-swift",
|
|
178
|
+
"tools": [
|
|
179
|
+
"jest",
|
|
180
|
+
"lefthook",
|
|
181
|
+
"release-it",
|
|
182
|
+
"eslint"
|
|
183
|
+
],
|
|
184
|
+
"version": "0.57.0"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
import type { SseConfig, SseEvent, SseStats } from './SseInterface';
|
|
3
|
+
|
|
4
|
+
export interface NitroSse
|
|
5
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
6
|
+
/**
|
|
7
|
+
* Configure SSE and setup event callback.
|
|
8
|
+
*/
|
|
9
|
+
setup(config: SseConfig, onEvent: (events: SseEvent[]) => void): void;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Start the SSE connection.
|
|
13
|
+
*/
|
|
14
|
+
start(): void;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Stop the SSE connection.
|
|
18
|
+
*/
|
|
19
|
+
stop(): void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Set the last processed event ID.
|
|
23
|
+
* Native will use this ID to resume connection if interrupted.
|
|
24
|
+
*/
|
|
25
|
+
setLastProcessedId(id: string): void;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Update HTTP headers dynamically (e.g., when token expires).
|
|
29
|
+
* These headers will be used for subsequent connection/reconnection attempts.
|
|
30
|
+
*/
|
|
31
|
+
updateHeaders(headers: Record<string, string>): void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get connection statistics.
|
|
35
|
+
*/
|
|
36
|
+
getStats(): SseStats;
|
|
37
|
+
/**
|
|
38
|
+
* Manually flush the event buffer.
|
|
39
|
+
* Useful when batching is enabled but you need to process pending events immediately.
|
|
40
|
+
*/
|
|
41
|
+
flush(): void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Force a reconnection.
|
|
45
|
+
* This resets the connection state and attempts to reconnect immediately.
|
|
46
|
+
*/
|
|
47
|
+
restart(): void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Check if the connection is currently active.
|
|
51
|
+
*/
|
|
52
|
+
isConnected(): boolean;
|
|
53
|
+
}
|