Skip to content

Commit

Permalink
refactor: refactored module installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Makowski committed Oct 24, 2024
1 parent edd3cd8 commit 47f88ac
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions packages/react-native-audio-api/src/utils/install.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { NativeModules, Platform } from 'react-native';
import { TurboModuleRegistry, TurboModule, Platform } from 'react-native';

interface AudioAPIModuleSpec extends TurboModule {
install(): boolean;
}

export function installModule() {
const AudioAPIModule = NativeModules.AudioAPIModule;
const AudioAPIModule =
TurboModuleRegistry.getEnforcing<AudioAPIModuleSpec>('AudioAPIModule');

if (AudioAPIModule == null) {
throw new Error(buildErrorMessage());
Expand All @@ -22,7 +27,6 @@ function buildErrorMessage(): string {
`;

message += verifyAppleOS();
message += verifyExpo();

message += '\n* Make sure you rebuilt the app.';

Expand All @@ -37,21 +41,6 @@ function verifyAppleOS(): string {
return '';
}

function verifyExpo(): string {
const ExpoConstants =
NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;

if (!ExpoConstants) {
return '';
}

if (ExpoConstants.appOwnership === 'expo') {
return "\n* 'react-native-audio-api' is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.";
}

return "\n* Make sure you ran 'expo prebuild'.";
}

function verifyOnDevice(Module: any) {
if (global.nativeCallSyncHook == null || Module.install == null) {
throw new Error(
Expand Down

0 comments on commit 47f88ac

Please sign in to comment.