mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
feat(state): add state for videos/audios/sub/rend
This commit is contained in:
@@ -24,6 +24,10 @@ namespace margelo::nitro::omni {
|
||||
prototype.registerHybridMethod("removeCastStatusListener", &HybridOmniEventMapSpec::removeCastStatusListener);
|
||||
prototype.registerHybridMethod("addSourceListener", &HybridOmniEventMapSpec::addSourceListener);
|
||||
prototype.registerHybridMethod("removeSourceListener", &HybridOmniEventMapSpec::removeSourceListener);
|
||||
prototype.registerHybridMethod("addTracksListener", &HybridOmniEventMapSpec::addTracksListener);
|
||||
prototype.registerHybridMethod("removeTracksListener", &HybridOmniEventMapSpec::removeTracksListener);
|
||||
prototype.registerHybridMethod("addRenditionsListener", &HybridOmniEventMapSpec::addRenditionsListener);
|
||||
prototype.registerHybridMethod("removeRenditionsListener", &HybridOmniEventMapSpec::removeRenditionsListener);
|
||||
prototype.registerHybridMethod("addOnEndListener", &HybridOmniEventMapSpec::addOnEndListener);
|
||||
prototype.registerHybridMethod("removeOnEndListener", &HybridOmniEventMapSpec::removeOnEndListener);
|
||||
prototype.registerHybridMethod("addOnPrevListener", &HybridOmniEventMapSpec::addOnPrevListener);
|
||||
|
||||
+9
-1
@@ -23,6 +23,8 @@ namespace margelo::nitro::omni { enum class PlayerStatus; }
|
||||
namespace margelo::nitro::omni { enum class CastStatus; }
|
||||
// Forward declaration of `Source` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Source; }
|
||||
// Forward declaration of `TrackProperty` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { enum class TrackProperty; }
|
||||
// Forward declaration of `Track` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Track; }
|
||||
// Forward declaration of `Rendition` to properly resolve imports.
|
||||
@@ -35,9 +37,11 @@ namespace margelo::nitro::omni { struct Rendition; }
|
||||
#include "CastStatus.hpp"
|
||||
#include "Source.hpp"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include "TrackProperty.hpp"
|
||||
#include "Track.hpp"
|
||||
#include <vector>
|
||||
#include "Rendition.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
@@ -80,6 +84,10 @@ namespace margelo::nitro::omni {
|
||||
virtual void removeCastStatusListener(const std::function<void(CastStatus /* value */)>& cb) = 0;
|
||||
virtual void addSourceListener(const std::function<void(const std::optional<Source>& /* value */)>& cb) = 0;
|
||||
virtual void removeSourceListener(const std::function<void(const std::optional<Source>& /* value */)>& cb) = 0;
|
||||
virtual void addTracksListener(TrackProperty key, const std::function<void(const std::vector<Track>& /* value */)>& cb) = 0;
|
||||
virtual void removeTracksListener(TrackProperty key, const std::function<void(const std::vector<Track>& /* value */)>& cb) = 0;
|
||||
virtual void addRenditionsListener(const std::function<void(const std::vector<Rendition>& /* value */)>& cb) = 0;
|
||||
virtual void removeRenditionsListener(const std::function<void(const std::vector<Rendition>& /* value */)>& cb) = 0;
|
||||
virtual void addOnEndListener(const std::function<void()>& cb) = 0;
|
||||
virtual void removeOnEndListener(const std::function<void()>& cb) = 0;
|
||||
virtual void addOnPrevListener(const std::function<void()>& cb) = 0;
|
||||
|
||||
+4
-4
@@ -19,10 +19,6 @@ namespace margelo::nitro::omni {
|
||||
prototype.registerHybridSetter("showNotification", &HybridOmniPlayerSpec::setShowNotification);
|
||||
prototype.registerHybridGetter("hasPrev", &HybridOmniPlayerSpec::getHasPrev);
|
||||
prototype.registerHybridGetter("hasNext", &HybridOmniPlayerSpec::getHasNext);
|
||||
prototype.registerHybridGetter("videos", &HybridOmniPlayerSpec::getVideos);
|
||||
prototype.registerHybridGetter("audios", &HybridOmniPlayerSpec::getAudios);
|
||||
prototype.registerHybridGetter("subtitles", &HybridOmniPlayerSpec::getSubtitles);
|
||||
prototype.registerHybridGetter("rendition", &HybridOmniPlayerSpec::getRendition);
|
||||
prototype.registerHybridGetter("source", &HybridOmniPlayerSpec::getSource);
|
||||
prototype.registerHybridSetter("source", &HybridOmniPlayerSpec::setSource);
|
||||
prototype.registerHybridGetter("status", &HybridOmniPlayerSpec::getStatus);
|
||||
@@ -39,6 +35,10 @@ namespace margelo::nitro::omni {
|
||||
prototype.registerHybridSetter("muted", &HybridOmniPlayerSpec::setMuted);
|
||||
prototype.registerHybridGetter("isAutoQuality", &HybridOmniPlayerSpec::getIsAutoQuality);
|
||||
prototype.registerHybridGetter("castStatus", &HybridOmniPlayerSpec::getCastStatus);
|
||||
prototype.registerHybridGetter("videos", &HybridOmniPlayerSpec::getVideos);
|
||||
prototype.registerHybridGetter("audios", &HybridOmniPlayerSpec::getAudios);
|
||||
prototype.registerHybridGetter("subtitles", &HybridOmniPlayerSpec::getSubtitles);
|
||||
prototype.registerHybridGetter("renditions", &HybridOmniPlayerSpec::getRenditions);
|
||||
prototype.registerHybridMethod("play", &HybridOmniPlayerSpec::play);
|
||||
prototype.registerHybridMethod("pause", &HybridOmniPlayerSpec::pause);
|
||||
prototype.registerHybridMethod("seekBy", &HybridOmniPlayerSpec::seekBy);
|
||||
|
||||
+11
-11
@@ -15,26 +15,26 @@
|
||||
|
||||
// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { class HybridOmniEventMapSpec; }
|
||||
// Forward declaration of `Track` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Track; }
|
||||
// Forward declaration of `Rendition` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Rendition; }
|
||||
// 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 `CastStatus` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { enum class CastStatus; }
|
||||
// Forward declaration of `Track` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Track; }
|
||||
// Forward declaration of `Rendition` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Rendition; }
|
||||
|
||||
#include <memory>
|
||||
#include "HybridOmniEventMapSpec.hpp"
|
||||
#include <optional>
|
||||
#include "Track.hpp"
|
||||
#include <vector>
|
||||
#include "Rendition.hpp"
|
||||
#include "Source.hpp"
|
||||
#include "PlayerStatus.hpp"
|
||||
#include "CastStatus.hpp"
|
||||
#include "Track.hpp"
|
||||
#include <vector>
|
||||
#include "Rendition.hpp"
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
@@ -68,10 +68,6 @@ namespace margelo::nitro::omni {
|
||||
virtual void setShowNotification(std::optional<bool> showNotification) = 0;
|
||||
virtual bool getHasPrev() = 0;
|
||||
virtual bool getHasNext() = 0;
|
||||
virtual std::vector<Track> getVideos() = 0;
|
||||
virtual std::vector<Track> getAudios() = 0;
|
||||
virtual std::vector<Track> getSubtitles() = 0;
|
||||
virtual std::vector<Rendition> getRendition() = 0;
|
||||
virtual std::optional<Source> getSource() = 0;
|
||||
virtual void setSource(const std::optional<Source>& source) = 0;
|
||||
virtual PlayerStatus getStatus() = 0;
|
||||
@@ -88,6 +84,10 @@ namespace margelo::nitro::omni {
|
||||
virtual void setMuted(bool muted) = 0;
|
||||
virtual bool getIsAutoQuality() = 0;
|
||||
virtual CastStatus getCastStatus() = 0;
|
||||
virtual std::vector<Track> getVideos() = 0;
|
||||
virtual std::vector<Track> getAudios() = 0;
|
||||
virtual std::vector<Track> getSubtitles() = 0;
|
||||
virtual std::vector<Rendition> getRenditions() = 0;
|
||||
|
||||
public:
|
||||
// Methods
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
///
|
||||
/// TrackProperty.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/NitroHash.hpp>)
|
||||
#include <NitroModules/NitroHash.hpp>
|
||||
#else
|
||||
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
||||
#endif
|
||||
#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
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
/**
|
||||
* An enum which can be represented as a JavaScript union (TrackProperty).
|
||||
*/
|
||||
enum class TrackProperty {
|
||||
VIDEOS SWIFT_NAME(videos) = 0,
|
||||
AUDIOS SWIFT_NAME(audios) = 1,
|
||||
SUBTITLES SWIFT_NAME(subtitles) = 2,
|
||||
} CLOSED_ENUM;
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
|
||||
namespace margelo::nitro {
|
||||
|
||||
// C++ TrackProperty <> JS TrackProperty (union)
|
||||
template <>
|
||||
struct JSIConverter<margelo::nitro::omni::TrackProperty> final {
|
||||
static inline margelo::nitro::omni::TrackProperty fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
||||
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
||||
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
||||
case hashString("videos"): return margelo::nitro::omni::TrackProperty::VIDEOS;
|
||||
case hashString("audios"): return margelo::nitro::omni::TrackProperty::AUDIOS;
|
||||
case hashString("subtitles"): return margelo::nitro::omni::TrackProperty::SUBTITLES;
|
||||
default: [[unlikely]]
|
||||
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum TrackProperty - invalid value!");
|
||||
}
|
||||
}
|
||||
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::omni::TrackProperty arg) {
|
||||
switch (arg) {
|
||||
case margelo::nitro::omni::TrackProperty::VIDEOS: return JSIConverter<std::string>::toJSI(runtime, "videos");
|
||||
case margelo::nitro::omni::TrackProperty::AUDIOS: return JSIConverter<std::string>::toJSI(runtime, "audios");
|
||||
case margelo::nitro::omni::TrackProperty::SUBTITLES: return JSIConverter<std::string>::toJSI(runtime, "subtitles");
|
||||
default: [[unlikely]]
|
||||
throw std::invalid_argument("Cannot convert TrackProperty to JS - invalid value: "
|
||||
+ std::to_string(static_cast<int>(arg)) + "!");
|
||||
}
|
||||
}
|
||||
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
||||
if (!value.isString()) {
|
||||
return false;
|
||||
}
|
||||
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
||||
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
||||
case hashString("videos"):
|
||||
case hashString("audios"):
|
||||
case hashString("subtitles"):
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace margelo::nitro
|
||||
Reference in New Issue
Block a user