Skip to content

Commit

Permalink
refactor: change __OscillatorProxy to createOscillator
Browse files Browse the repository at this point in the history
  • Loading branch information
hubgan committed Jul 16, 2024
1 parent b325d2a commit 9db5511
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ios/AudioContextModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ @implementation AudioContextModule

runtime.global().setProperty(
runtime,
jsi::String::createFromUtf8(runtime, "__OscillatorProxy"),
jsi::String::createFromUtf8(runtime, "createOscillator"),
jsi::Function::createFromHostFunction(
runtime,
jsi::PropNameID::forUtf8(runtime, "__OscillatorProxy"),
jsi::PropNameID::forUtf8(runtime, "createOscillator"),
0,
[](jsi::Runtime& runtime, const jsi::Value& thisVal, const jsi::Value* args, size_t count) -> jsi::Value {
const float frequency = static_cast<float>(args[0].asNumber());
Expand Down
16 changes: 8 additions & 8 deletions src/Oscillator/Oscillator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {
} from '../utils/install';

function verifyInstallation() {
if (global.__OscillatorProxy == null)
if (global.createOscillator == null)
throw new Error(
'Failed to install react-native-audio-context, the native initializer function does not exist. Are you trying to use Oscillator from different JS Runtimes?'
);
}

function createOscillatorProxy(): (frequency: number) => OscillatorNode {
if (global.__OscillatorProxy) {
return global.__OscillatorProxy;
function createOscillator(): (frequency: number) => OscillatorNode {
if (global.createOscillator) {
return global.createOscillator;
}

verifyExpoGo();
Expand All @@ -26,12 +26,12 @@ function createOscillatorProxy(): (frequency: number) => OscillatorNode {
installModule(AudioContextModule);
verifyInstallation();

if (global.__OscillatorProxy == null) {
throw new Error('Failed to initialize __OscillatorProxy.');
if (global.createOscillator == null) {
throw new Error('Failed to initialize createOscillator.');
}

return global.__OscillatorProxy;
return global.createOscillator;
}

// Call the creator and export what it returns
export default createOscillatorProxy();
export default createOscillator();
2 changes: 1 addition & 1 deletion src/Oscillator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export interface OscillatorNode {
// global func declaration for JSI functions
declare global {
function nativeCallSyncHook(): unknown;
var __OscillatorProxy: (frequency: number) => OscillatorNode;
var createOscillator: (frequency: number) => OscillatorNode;
}

0 comments on commit 9db5511

Please sign in to comment.