-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from software-mansion-labs/feat/android/connec…
…t-method Feat/android/connect method
- Loading branch information
Showing
23 changed files
with
373 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,35 @@ | ||
#include "AudioContext.h" | ||
#include "AudioContextHostObject.h" | ||
#include "OscillatorNode.h" | ||
#include <fbjni/fbjni.h> | ||
#include <jsi/jsi.h> | ||
#include <android/log.h> | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook::jni; | ||
|
||
AudioContext::AudioContext(jni::alias_ref<AudioContext::jhybridobject> &jThis, | ||
jlong jsContext): javaObject_(make_global(jThis)) { | ||
auto runtime = reinterpret_cast<jsi::Runtime *>(jsContext); | ||
auto hostObject = std::make_shared<AudioContextHostObject>(this); | ||
auto object = jsi::Object::createFromHostObject(*runtime, hostObject); | ||
runtime->global().setProperty(*runtime, "__AudioContextProxy", std::move(object)); | ||
} | ||
|
||
jsi::Object AudioContext::createOscillator() { | ||
static const auto method = javaClassLocal()->getMethod<OscillatorNode()>("createOscillator"); | ||
auto oscillator = method(javaObject_.get()); | ||
auto oscillatorCppInstance = oscillator->cthis(); | ||
|
||
return oscillatorCppInstance->createOscillatorNodeHostObject(); | ||
} | ||
|
||
namespace audiocontext | ||
{ | ||
|
||
using namespace facebook::jni; | ||
|
||
AudioContext::AudioContext(jni::alias_ref<AudioContext::jhybridobject> &jThis, | ||
jlong jsContext) : javaObject_(make_global(jThis)), jsContext_(jsContext) | ||
{ | ||
auto runtime = reinterpret_cast<jsi::Runtime *>(jsContext); | ||
auto hostObject = std::make_shared<AudioContextHostObject>(this); | ||
auto object = jsi::Object::createFromHostObject(*runtime, hostObject); | ||
runtime->global().setProperty(*runtime, "__AudioContextProxy", std::move(object)); | ||
} | ||
|
||
jsi::Object AudioContext::createOscillator() | ||
{ | ||
static const auto method = javaClassLocal()->getMethod<OscillatorNode()>("createOscillator"); | ||
auto oscillator = method(javaObject_.get()); | ||
auto oscillatorCppInstance = oscillator->cthis(); | ||
|
||
return oscillatorCppInstance->createOscillatorNodeHostObject(); | ||
} | ||
|
||
jsi::Object AudioContext::getDestination() | ||
{ | ||
static const auto method = javaClassLocal()->getMethod<AudioDestinationNode()>("getDestination"); | ||
auto destination = method(javaObject_.get()); | ||
auto destinationCppInstance = destination->cthis(); | ||
|
||
return destinationCppInstance->createAudioDestinationHostObject(); | ||
} | ||
|
||
} // namespace audiocontext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "AudioDestinationNode.h" | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook::jni; | ||
|
||
AudioDestinationNode::AudioDestinationNode(jni::alias_ref<AudioDestinationNode::jhybridobject> &jThis, | ||
jlong jsContext): javaObject_(make_global(jThis)), jsContext_(jsContext) {} | ||
|
||
jsi::Object AudioDestinationNode::createAudioDestinationHostObject() { | ||
auto runtime = reinterpret_cast<jsi::Runtime *>(jsContext_); | ||
auto hostObject = std::make_shared<AudioDestinationNodeHostObject>(this); | ||
return jsi::Object::createFromHostObject(*runtime, hostObject); | ||
} | ||
} // namespace audiocontext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <jsi/jsi.h> | ||
#include <react/jni/CxxModuleWrapper.h> | ||
#include <react/jni/JMessageQueueThread.h> | ||
#include "AudioDestinationNodeHostObject.h" | ||
#include "OscillatorNode.h" | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook; | ||
using namespace facebook::jni; | ||
|
||
class OscillatorNode; | ||
|
||
class AudioDestinationNode : public jni::HybridClass<AudioDestinationNode> { | ||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/audiocontext/nodes/AudioDestinationNode;"; | ||
|
||
static jni::local_ref<AudioDestinationNode::jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis, jlong jsContext) | ||
{ | ||
return makeCxxInstance(jThis, jsContext); | ||
} | ||
|
||
static void registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod("initHybrid", AudioDestinationNode::initHybrid), | ||
}); | ||
} | ||
|
||
jsi::Object createAudioDestinationHostObject(); | ||
|
||
private: | ||
friend HybridBase; | ||
friend class OscillatorNode; | ||
|
||
global_ref<AudioDestinationNode::javaobject> javaObject_; | ||
jlong jsContext_{}; | ||
|
||
explicit AudioDestinationNode(jni::alias_ref<AudioDestinationNode::jhybridobject>& jThis, jlong jsContext); | ||
}; | ||
|
||
} // namespace audiocontext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.