Cleanup source handling

This commit is contained in:
2026-04-10 19:20:45 +02:00
parent 7a5f495b39
commit fd40915bc9
26 changed files with 415 additions and 450 deletions
@@ -15,12 +15,12 @@
// Forward declaration of `HybridOmniPlayerSpec` to properly resolve imports.
namespace margelo::nitro::omni { class HybridOmniPlayerSpec; }
// Forward declaration of `HybridOmniPlayerPropsSpec` to properly resolve imports.
namespace margelo::nitro::omni { class HybridOmniPlayerPropsSpec; }
// Forward declaration of `Source` to properly resolve imports.
namespace margelo::nitro::omni { struct Source; }
#include <memory>
#include "HybridOmniPlayerSpec.hpp"
#include "HybridOmniPlayerPropsSpec.hpp"
#include "Source.hpp"
namespace margelo::nitro::omni {
@@ -53,7 +53,7 @@ namespace margelo::nitro::omni {
public:
// Methods
virtual std::shared_ptr<HybridOmniPlayerSpec> createPlayer(const std::shared_ptr<HybridOmniPlayerPropsSpec>& props) = 0;
virtual std::shared_ptr<HybridOmniPlayerSpec> createPlayer(const Source& props) = 0;
protected:
// Hybrid Setup
@@ -1,30 +0,0 @@
///
/// HybridOmniPlayerPropsSpec.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#include "HybridOmniPlayerPropsSpec.hpp"
namespace margelo::nitro::omni {
void HybridOmniPlayerPropsSpec::loadHybridMethods() {
// load base methods/properties
HybridObject::loadHybridMethods();
// load custom methods/properties
registerHybrids(this, [](Prototype& prototype) {
prototype.registerHybridGetter("src", &HybridOmniPlayerPropsSpec::getSrc);
prototype.registerHybridSetter("src", &HybridOmniPlayerPropsSpec::setSrc);
prototype.registerHybridGetter("startTime", &HybridOmniPlayerPropsSpec::getStartTime);
prototype.registerHybridSetter("startTime", &HybridOmniPlayerPropsSpec::setStartTime);
prototype.registerHybridGetter("subtitles", &HybridOmniPlayerPropsSpec::getSubtitles);
prototype.registerHybridSetter("subtitles", &HybridOmniPlayerPropsSpec::setSubtitles);
prototype.registerHybridGetter("metadata", &HybridOmniPlayerPropsSpec::getMetadata);
prototype.registerHybridSetter("metadata", &HybridOmniPlayerPropsSpec::setMetadata);
prototype.registerHybridGetter("mixAudio", &HybridOmniPlayerPropsSpec::getMixAudio);
prototype.registerHybridSetter("mixAudio", &HybridOmniPlayerPropsSpec::setMixAudio);
});
}
} // namespace margelo::nitro::omni
@@ -1,83 +0,0 @@
///
/// HybridOmniPlayerPropsSpec.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#if __has_include(<NitroModules/HybridObject.hpp>)
#include <NitroModules/HybridObject.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
// Forward declaration of `VideoSrc` to properly resolve imports.
namespace margelo::nitro::omni { struct VideoSrc; }
// Forward declaration of `Subtitle` to properly resolve imports.
namespace margelo::nitro::omni { struct Subtitle; }
// Forward declaration of `Metadata` to properly resolve imports.
namespace margelo::nitro::omni { struct Metadata; }
// Forward declaration of `MixAudioMode` to properly resolve imports.
namespace margelo::nitro::omni { enum class MixAudioMode; }
#include "VideoSrc.hpp"
#include <vector>
#include <optional>
#include "Subtitle.hpp"
#include "Metadata.hpp"
#include "MixAudioMode.hpp"
namespace margelo::nitro::omni {
using namespace margelo::nitro;
/**
* An abstract base class for `OmniPlayerProps`
* Inherit this class to create instances of `HybridOmniPlayerPropsSpec` in C++.
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
* @example
* ```cpp
* class HybridOmniPlayerProps: public HybridOmniPlayerPropsSpec {
* public:
* HybridOmniPlayerProps(...): HybridObject(TAG) { ... }
* // ...
* };
* ```
*/
class HybridOmniPlayerPropsSpec: public virtual HybridObject {
public:
// Constructor
explicit HybridOmniPlayerPropsSpec(): HybridObject(TAG) { }
// Destructor
~HybridOmniPlayerPropsSpec() override = default;
public:
// Properties
virtual std::vector<VideoSrc> getSrc() = 0;
virtual void setSrc(const std::vector<VideoSrc>& src) = 0;
virtual std::optional<double> getStartTime() = 0;
virtual void setStartTime(std::optional<double> startTime) = 0;
virtual std::vector<Subtitle> getSubtitles() = 0;
virtual void setSubtitles(const std::vector<Subtitle>& subtitles) = 0;
virtual std::optional<Metadata> getMetadata() = 0;
virtual void setMetadata(const std::optional<Metadata>& metadata) = 0;
virtual std::optional<MixAudioMode> getMixAudio() = 0;
virtual void setMixAudio(std::optional<MixAudioMode> mixAudio) = 0;
public:
// Methods
protected:
// Hybrid Setup
void loadHybridMethods() override;
protected:
// Tag for logging
static constexpr auto TAG = "OmniPlayerProps";
};
} // namespace margelo::nitro::omni
+2
View File
@@ -14,6 +14,8 @@ namespace margelo::nitro::omni {
HybridObject::loadHybridMethods();
// load custom methods/properties
registerHybrids(this, [](Prototype& prototype) {
prototype.registerHybridGetter("source", &HybridOmniPlayerSpec::getSource);
prototype.registerHybridSetter("source", &HybridOmniPlayerSpec::setSource);
prototype.registerHybridGetter("hasPrev", &HybridOmniPlayerSpec::getHasPrev);
prototype.registerHybridGetter("hasNext", &HybridOmniPlayerSpec::getHasNext);
prototype.registerHybridGetter("status", &HybridOmniPlayerSpec::getStatus);
+5
View File
@@ -13,6 +13,8 @@
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
// Forward declaration of `Source` to properly resolve imports.
namespace margelo::nitro::omni { struct Source; }
// Forward declaration of `PlayerStatus` to properly resolve imports.
namespace margelo::nitro::omni { enum class PlayerStatus; }
// Forward declaration of `Track` to properly resolve imports.
@@ -20,6 +22,7 @@ namespace margelo::nitro::omni { struct Track; }
// Forward declaration of `Rendition` to properly resolve imports.
namespace margelo::nitro::omni { struct Rendition; }
#include "Source.hpp"
#include "PlayerStatus.hpp"
#include "Track.hpp"
#include <vector>
@@ -53,6 +56,8 @@ namespace margelo::nitro::omni {
public:
// Properties
virtual Source getSource() = 0;
virtual void setSource(const Source& source) = 0;
virtual bool getHasPrev() = 0;
virtual bool getHasNext() = 0;
virtual PlayerStatus getStatus() = 0;
+111
View File
@@ -0,0 +1,111 @@
///
/// Source.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#if __has_include(<NitroModules/JSIConverter.hpp>)
#include <NitroModules/JSIConverter.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/NitroDefines.hpp>)
#include <NitroModules/NitroDefines.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/JSIHelpers.hpp>)
#include <NitroModules/JSIHelpers.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
#include <NitroModules/PropNameIDCache.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
// Forward declaration of `VideoSrc` to properly resolve imports.
namespace margelo::nitro::omni { struct VideoSrc; }
// Forward declaration of `Subtitle` to properly resolve imports.
namespace margelo::nitro::omni { struct Subtitle; }
// Forward declaration of `Metadata` to properly resolve imports.
namespace margelo::nitro::omni { struct Metadata; }
// Forward declaration of `MixAudioMode` to properly resolve imports.
namespace margelo::nitro::omni { enum class MixAudioMode; }
#include "VideoSrc.hpp"
#include <vector>
#include <optional>
#include "Subtitle.hpp"
#include "Metadata.hpp"
#include "MixAudioMode.hpp"
namespace margelo::nitro::omni {
/**
* A struct which can be represented as a JavaScript object (Source).
*/
struct Source final {
public:
std::vector<VideoSrc> src SWIFT_PRIVATE;
std::optional<double> startTime SWIFT_PRIVATE;
std::vector<Subtitle> subtitles SWIFT_PRIVATE;
std::optional<Metadata> metadata SWIFT_PRIVATE;
std::optional<MixAudioMode> mixAudio SWIFT_PRIVATE;
public:
Source() = default;
explicit Source(std::vector<VideoSrc> src, std::optional<double> startTime, std::vector<Subtitle> subtitles, std::optional<Metadata> metadata, std::optional<MixAudioMode> mixAudio): src(src), startTime(startTime), subtitles(subtitles), metadata(metadata), mixAudio(mixAudio) {}
public:
friend bool operator==(const Source& lhs, const Source& rhs) = default;
};
} // namespace margelo::nitro::omni
namespace margelo::nitro {
// C++ Source <> JS Source (object)
template <>
struct JSIConverter<margelo::nitro::omni::Source> final {
static inline margelo::nitro::omni::Source fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
jsi::Object obj = arg.asObject(runtime);
return margelo::nitro::omni::Source(
JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src"))),
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime"))),
JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles"))),
JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata"))),
JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mixAudio")))
);
}
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::Source& arg) {
jsi::Object obj(runtime);
obj.setProperty(runtime, PropNameIDCache::get(runtime, "src"), JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::toJSI(runtime, arg.src));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "startTime"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.startTime));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "subtitles"), JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::toJSI(runtime, arg.subtitles));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "metadata"), JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::toJSI(runtime, arg.metadata));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "mixAudio"), JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::toJSI(runtime, arg.mixAudio));
return obj;
}
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
if (!value.isObject()) {
return false;
}
jsi::Object obj = value.getObject(runtime);
if (!nitro::isPlainObject(runtime, obj)) {
return false;
}
if (!JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src")))) return false;
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime")))) return false;
if (!JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles")))) return false;
if (!JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata")))) return false;
if (!JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mixAudio")))) return false;
return true;
}
};
} // namespace margelo::nitro