Skip to content

Commit

Permalink
fix: moved creating audio context host object method to host object
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Makowski committed Jul 19, 2024
1 parent ea2de9e commit fc190c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion android/src/main/cpp/AudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace audiocontext
{
auto audioContextWrapper = std::make_shared<AudioContextWrapper>(std::shared_ptr<AudioContext>(this));
auto runtime = reinterpret_cast<jsi::Runtime *>(jsContext);
auto hostObject = std::make_shared<AudioContextHostObject>(audioContextWrapper);
auto hostObject = AudioContextHostObject::createFromWrapper(audioContextWrapper);

auto object = jsi::Object::createFromHostObject(*runtime, hostObject);
runtime->global().setProperty(*runtime, "__AudioContextProxy", std::move(object));
Expand Down
32 changes: 19 additions & 13 deletions cpp/AudioContext/AudioContextHostObject.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
#pragma once

#include <jsi/jsi.h>
#include "AudioContextWrapper.h"

namespace audiocontext
{
using namespace facebook;
using namespace facebook;

class AudioContextWrapper;
class AudioContextWrapper;

class AudioContextHostObject : public jsi::HostObject
{
private:
std::shared_ptr<AudioContextWrapper> wrapper_;
class AudioContextHostObject : public jsi::HostObject
{
private:
std::shared_ptr<AudioContextWrapper> wrapper_;

public:
explicit AudioContextHostObject(std::shared_ptr<AudioContextWrapper> wrapper) : wrapper_(wrapper) {}
public:
explicit AudioContextHostObject(std::shared_ptr<AudioContextWrapper> wrapper) : wrapper_(wrapper) {}

jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override;
void set(jsi::Runtime &runtime, const jsi::PropNameID &name, const jsi::Value &value) override;
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
static std::shared_ptr<AudioContextHostObject> createFromWrapper(std::shared_ptr<AudioContextWrapper> wrapper) {
return std::make_shared<AudioContextHostObject>(wrapper);
}

jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override;
void set(jsi::Runtime &runtime, const jsi::PropNameID &name, const jsi::Value &value) override;
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;

jsi::Value createOscillator(jsi::Runtime& runtime, const jsi::PropNameID& propNameId);
jsi::Value getDestination(jsi::Runtime& runtime, const jsi::PropNameID& propNameId);

jsi::Value createOscillator(jsi::Runtime& runtime, const jsi::PropNameID& propNameId);
jsi::Value getDestination(jsi::Runtime& runtime, const jsi::PropNameID& propNameId);
};
} // namespace audiocontext

0 comments on commit fc190c8

Please sign in to comment.