mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-05 13:46:59 +00:00
wip: Implement events
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
///
|
||||
/// HybridOmniEventMapSpec.cpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#include "HybridOmniEventMapSpec.hpp"
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
void HybridOmniEventMapSpec::loadHybridMethods() {
|
||||
// load base methods/properties
|
||||
HybridObject::loadHybridMethods();
|
||||
// load custom methods/properties
|
||||
registerHybrids(this, [](Prototype& prototype) {
|
||||
prototype.registerHybridMethod("addOnEndListener", &HybridOmniEventMapSpec::addOnEndListener);
|
||||
prototype.registerHybridMethod("removeOnEndListener", &HybridOmniEventMapSpec::removeOnEndListener);
|
||||
prototype.registerHybridMethod("addOnPrevListener", &HybridOmniEventMapSpec::addOnPrevListener);
|
||||
prototype.registerHybridMethod("removeOnPrevListener", &HybridOmniEventMapSpec::removeOnPrevListener);
|
||||
prototype.registerHybridMethod("addOnNextListener", &HybridOmniEventMapSpec::addOnNextListener);
|
||||
prototype.registerHybridMethod("removeOnNextListener", &HybridOmniEventMapSpec::removeOnNextListener);
|
||||
prototype.registerHybridMethod("addOnErrorListener", &HybridOmniEventMapSpec::addOnErrorListener);
|
||||
prototype.registerHybridMethod("removeOnErrorListener", &HybridOmniEventMapSpec::removeOnErrorListener);
|
||||
prototype.registerHybridMethod("addOnAudioFocusChangeListener", &HybridOmniEventMapSpec::addOnAudioFocusChangeListener);
|
||||
prototype.registerHybridMethod("removeOnAudioFocusChangeListener", &HybridOmniEventMapSpec::removeOnAudioFocusChangeListener);
|
||||
prototype.registerHybridMethod("addOnVideoTrackChangeListener", &HybridOmniEventMapSpec::addOnVideoTrackChangeListener);
|
||||
prototype.registerHybridMethod("removeOnVideoTrackChangeListener", &HybridOmniEventMapSpec::removeOnVideoTrackChangeListener);
|
||||
prototype.registerHybridMethod("addOnAudioTrackChangeListener", &HybridOmniEventMapSpec::addOnAudioTrackChangeListener);
|
||||
prototype.registerHybridMethod("removeOnAudioTrackChangeListener", &HybridOmniEventMapSpec::removeOnAudioTrackChangeListener);
|
||||
prototype.registerHybridMethod("addOnSubtitleChangeListener", &HybridOmniEventMapSpec::addOnSubtitleChangeListener);
|
||||
prototype.registerHybridMethod("removeOnSubtitleChangeListener", &HybridOmniEventMapSpec::removeOnSubtitleChangeListener);
|
||||
prototype.registerHybridMethod("addOnRenditionChangeListener", &HybridOmniEventMapSpec::addOnRenditionChangeListener);
|
||||
prototype.registerHybridMethod("removeOnRenditionChangeListener", &HybridOmniEventMapSpec::removeOnRenditionChangeListener);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
@@ -0,0 +1,86 @@
|
||||
///
|
||||
/// HybridOmniEventMapSpec.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 `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 <functional>
|
||||
#include <string>
|
||||
#include "Track.hpp"
|
||||
#include <optional>
|
||||
#include "Rendition.hpp"
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
using namespace margelo::nitro;
|
||||
|
||||
/**
|
||||
* An abstract base class for `OmniEventMap`
|
||||
* Inherit this class to create instances of `HybridOmniEventMapSpec` in C++.
|
||||
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
||||
* @example
|
||||
* ```cpp
|
||||
* class HybridOmniEventMap: public HybridOmniEventMapSpec {
|
||||
* public:
|
||||
* HybridOmniEventMap(...): HybridObject(TAG) { ... }
|
||||
* // ...
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
class HybridOmniEventMapSpec: public virtual HybridObject {
|
||||
public:
|
||||
// Constructor
|
||||
explicit HybridOmniEventMapSpec(): HybridObject(TAG) { }
|
||||
|
||||
// Destructor
|
||||
~HybridOmniEventMapSpec() override = default;
|
||||
|
||||
public:
|
||||
// Properties
|
||||
|
||||
|
||||
public:
|
||||
// Methods
|
||||
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;
|
||||
virtual void removeOnPrevListener(const std::function<void()>& cb) = 0;
|
||||
virtual void addOnNextListener(const std::function<void()>& cb) = 0;
|
||||
virtual void removeOnNextListener(const std::function<void()>& cb) = 0;
|
||||
virtual void addOnErrorListener(const std::function<void(const std::string& /* type */, const std::string& /* message */)>& cb) = 0;
|
||||
virtual void removeOnErrorListener(const std::function<void(const std::string& /* type */, const std::string& /* message */)>& cb) = 0;
|
||||
virtual void addOnAudioFocusChangeListener(const std::function<void(const std::string& /* status */)>& cb) = 0;
|
||||
virtual void removeOnAudioFocusChangeListener(const std::function<void(const std::string& /* status */)>& cb) = 0;
|
||||
virtual void addOnVideoTrackChangeListener(const std::function<void(const Track& /* track */)>& cb) = 0;
|
||||
virtual void removeOnVideoTrackChangeListener(const std::function<void(const Track& /* track */)>& cb) = 0;
|
||||
virtual void addOnAudioTrackChangeListener(const std::function<void(const Track& /* track */)>& cb) = 0;
|
||||
virtual void removeOnAudioTrackChangeListener(const std::function<void(const Track& /* track */)>& cb) = 0;
|
||||
virtual void addOnSubtitleChangeListener(const std::function<void(const std::optional<Track>& /* track */)>& cb) = 0;
|
||||
virtual void removeOnSubtitleChangeListener(const std::function<void(const std::optional<Track>& /* track */)>& cb) = 0;
|
||||
virtual void addOnRenditionChangeListener(const std::function<void(const Rendition& /* rendition */)>& cb) = 0;
|
||||
virtual void removeOnRenditionChangeListener(const std::function<void(const Rendition& /* rendition */)>& cb) = 0;
|
||||
|
||||
protected:
|
||||
// Hybrid Setup
|
||||
void loadHybridMethods() override;
|
||||
|
||||
protected:
|
||||
// Tag for logging
|
||||
static constexpr auto TAG = "OmniEventMap";
|
||||
};
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
+5
-4
@@ -14,10 +14,15 @@ namespace margelo::nitro::omni {
|
||||
HybridObject::loadHybridMethods();
|
||||
// load custom methods/properties
|
||||
registerHybrids(this, [](Prototype& prototype) {
|
||||
prototype.registerHybridGetter("eventMap", &HybridOmniPlayerSpec::getEventMap);
|
||||
prototype.registerHybridGetter("source", &HybridOmniPlayerSpec::getSource);
|
||||
prototype.registerHybridSetter("source", &HybridOmniPlayerSpec::setSource);
|
||||
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("status", &HybridOmniPlayerSpec::getStatus);
|
||||
prototype.registerHybridGetter("isPlaying", &HybridOmniPlayerSpec::getIsPlaying);
|
||||
prototype.registerHybridGetter("currentTime", &HybridOmniPlayerSpec::getCurrentTime);
|
||||
@@ -28,10 +33,6 @@ namespace margelo::nitro::omni {
|
||||
prototype.registerHybridSetter("playbackRate", &HybridOmniPlayerSpec::setPlaybackRate);
|
||||
prototype.registerHybridGetter("volume", &HybridOmniPlayerSpec::getVolume);
|
||||
prototype.registerHybridSetter("volume", &HybridOmniPlayerSpec::setVolume);
|
||||
prototype.registerHybridGetter("videos", &HybridOmniPlayerSpec::getVideos);
|
||||
prototype.registerHybridGetter("audios", &HybridOmniPlayerSpec::getAudios);
|
||||
prototype.registerHybridGetter("subtitles", &HybridOmniPlayerSpec::getSubtitles);
|
||||
prototype.registerHybridGetter("rendition", &HybridOmniPlayerSpec::getRendition);
|
||||
prototype.registerHybridMethod("play", &HybridOmniPlayerSpec::play);
|
||||
prototype.registerHybridMethod("pause", &HybridOmniPlayerSpec::pause);
|
||||
prototype.registerHybridMethod("seekBy", &HybridOmniPlayerSpec::seekBy);
|
||||
|
||||
+12
-7
@@ -13,20 +13,24 @@
|
||||
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
||||
#endif
|
||||
|
||||
// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { class HybridOmniEventMapSpec; }
|
||||
// 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.
|
||||
namespace margelo::nitro::omni { struct Track; }
|
||||
// Forward declaration of `Rendition` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Rendition; }
|
||||
// Forward declaration of `PlayerStatus` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { enum class PlayerStatus; }
|
||||
|
||||
#include <memory>
|
||||
#include "HybridOmniEventMapSpec.hpp"
|
||||
#include "Source.hpp"
|
||||
#include "PlayerStatus.hpp"
|
||||
#include "Track.hpp"
|
||||
#include <vector>
|
||||
#include "Rendition.hpp"
|
||||
#include "PlayerStatus.hpp"
|
||||
#include <optional>
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
@@ -56,10 +60,15 @@ namespace margelo::nitro::omni {
|
||||
|
||||
public:
|
||||
// Properties
|
||||
virtual std::shared_ptr<HybridOmniEventMapSpec> getEventMap() = 0;
|
||||
virtual Source getSource() = 0;
|
||||
virtual void setSource(const Source& source) = 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 PlayerStatus getStatus() = 0;
|
||||
virtual bool getIsPlaying() = 0;
|
||||
virtual double getCurrentTime() = 0;
|
||||
@@ -70,10 +79,6 @@ namespace margelo::nitro::omni {
|
||||
virtual void setPlaybackRate(double playbackRate) = 0;
|
||||
virtual double getVolume() = 0;
|
||||
virtual void setVolume(double volume) = 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;
|
||||
|
||||
public:
|
||||
// Methods
|
||||
|
||||
+7
-7
@@ -29,10 +29,10 @@ namespace margelo::nitro::omni {
|
||||
* An enum which can be represented as a JavaScript union (PlayerStatus).
|
||||
*/
|
||||
enum class PlayerStatus {
|
||||
IDLE SWIFT_NAME(idle) = 0,
|
||||
LOADING SWIFT_NAME(loading) = 1,
|
||||
READYTOPLAY SWIFT_NAME(readytoplay) = 2,
|
||||
ERROR SWIFT_NAME(error) = 3,
|
||||
ERROR SWIFT_NAME(error) = 0,
|
||||
IDLE SWIFT_NAME(idle) = 1,
|
||||
LOADING SWIFT_NAME(loading) = 2,
|
||||
READYTOPLAY SWIFT_NAME(readytoplay) = 3,
|
||||
} CLOSED_ENUM;
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
@@ -45,20 +45,20 @@ namespace margelo::nitro {
|
||||
static inline margelo::nitro::omni::PlayerStatus 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("error"): return margelo::nitro::omni::PlayerStatus::ERROR;
|
||||
case hashString("idle"): return margelo::nitro::omni::PlayerStatus::IDLE;
|
||||
case hashString("loading"): return margelo::nitro::omni::PlayerStatus::LOADING;
|
||||
case hashString("readyToPlay"): return margelo::nitro::omni::PlayerStatus::READYTOPLAY;
|
||||
case hashString("error"): return margelo::nitro::omni::PlayerStatus::ERROR;
|
||||
default: [[unlikely]]
|
||||
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PlayerStatus - invalid value!");
|
||||
}
|
||||
}
|
||||
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::omni::PlayerStatus arg) {
|
||||
switch (arg) {
|
||||
case margelo::nitro::omni::PlayerStatus::ERROR: return JSIConverter<std::string>::toJSI(runtime, "error");
|
||||
case margelo::nitro::omni::PlayerStatus::IDLE: return JSIConverter<std::string>::toJSI(runtime, "idle");
|
||||
case margelo::nitro::omni::PlayerStatus::LOADING: return JSIConverter<std::string>::toJSI(runtime, "loading");
|
||||
case margelo::nitro::omni::PlayerStatus::READYTOPLAY: return JSIConverter<std::string>::toJSI(runtime, "readyToPlay");
|
||||
case margelo::nitro::omni::PlayerStatus::ERROR: return JSIConverter<std::string>::toJSI(runtime, "error");
|
||||
default: [[unlikely]]
|
||||
throw std::invalid_argument("Cannot convert PlayerStatus to JS - invalid value: "
|
||||
+ std::to_string(static_cast<int>(arg)) + "!");
|
||||
@@ -70,10 +70,10 @@ namespace margelo::nitro {
|
||||
}
|
||||
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
||||
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
||||
case hashString("error"):
|
||||
case hashString("idle"):
|
||||
case hashString("loading"):
|
||||
case hashString("readyToPlay"):
|
||||
case hashString("error"):
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user