Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Local Linphone SDK work in react native environment ? #970

Open
tsuccar opened this issue Dec 9, 2024 · 0 comments
Open

Can Local Linphone SDK work in react native environment ? #970

tsuccar opened this issue Dec 9, 2024 · 0 comments

Comments

@tsuccar
Copy link

tsuccar commented Dec 9, 2024

I need to use the locally installed SDK in react native project. Not sure if it is supported but I gave it a try with the outcome
below. Anyone's help with correcting my installation setup is much appreciated.

Error

❌  error: Filename "LinphoneWrapper.swift" used twice: '/Users/mymac/thisproject/modules/linphonern/ios/linphone-sdk/IOS_64_RELEASE/ios-arm64-simulator/liblinphone/wrappers/swift/LinphoneWrapper.swift'
 and 
'/Users/mymac/thisproject/modules/linphonern/ios/linphone-sdk/IOS_64_RELEASE/ios-arm64/liblinphone/wrappers/swift/LinphoneWrapper.swift' (in target 'Linphonern' from project 'Pods')

› 1 error(s), and 4 warning(s)

CommandError: Failed to build iOS project. "xcodebuild" exited with error code 65.

If I remove the duplicate file ,LinphoneWrapper.swift from one folder, it keeps finding the same
in another.

Set Up

React Native Environment

  • Using Expo workflow with development build not Expo Go App.
  • Using Expo 3rd party library wrapper (Expo module API) https://docs.expo.dev/modules/third-party-library/
  • Installed with npx create-expo-module --local linphonern inside test react native project.

inside wrapper module folder - rootfolder/modules/linphonern/ios

Project folder
│ ── App/
│ ── modules/linphonern/ios
│ ├── linphone-sdk/
│ ├── linphonern.podspec
│ ├── linphonernModule.swift
│ ├── src/
│ └── linphonernModule.ts
|── package.json
└── tsconfig.json

  1. Linphonern.podspec
Pod::Spec.new do |s|
  s.name           = 'Linphonern'
  s.version        = '1.0.0'
  s.summary        = 'A sample project summary'
  s.description    = 'A sample project description'
  s.author         = ''
  s.homepage       = 'https://docs.expo.dev/modules/'
  s.platforms      = {
    :ios => '15.1',
    :tvos => '15.1'
  }
  s.source         = { git: '' }
  s.static_framework = true

  s.dependency 'ExpoModulesCore'

  # Swift/Objective-C compatibility
  s.pod_target_xcconfig = {
    'DEFINES_MODULE' => 'YES',
  }
  s.vendored_frameworks = "linphone-sdk/apple-darwin/XCFrameworks/**"
  s.pod_target_xcconfig = { 'VALID_ARCHS' => "arm64" }
  s.user_target_xcconfig = { 'VALID_ARCHS' => "arm64" }
  s.module_name   = 'linphonesw' # name of the swift package
  s.swift_version = '4.0'
  s.source_files = "linphone-sdk/apple-darwin/share/linphonesw/*.swift"
  s.framework = 'linphone', 'belle-sip', 'bctoolbox'
  s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
end
  1. LinphonernModule.swift
import ExpoModulesCore
import linphonesw //trying to import locally installed linphone-sdk but fails

public class LinephonernModule: Module {
  public func definition() -> ModuleDefinition {
    Name("Linphonern")

    // Define a method that initializes Core and returns its version
    Function("getCoreVersion") { () -> String in
      let linphoneContext = LinePhoneSWHelper()
      return linphoneContext.coreVersion
    }
  }
}

// Helper class to manage Linphone Core initialization
public class LinePhoneSWHelper {
  private var mCore: Core!
  public var coreVersion: String = ""

  init() {
    // Initialize Linphone Core and retrieve the version
    do {
      try mCore = Factory.Instance.createCore(configPath: "", factoryConfigPath: "", systemContext: nil)
      try mCore.start()
      coreVersion = Core.getVersion
    } catch {
      NSLog("Failed to initialize Linphone Core: \(error)")
      coreVersion = "Initialization Error"
    }
  }
} 

App

  1. Index.tsx
import React, { useEffect, useState } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Linphonern from '../modules/linphonern'; // Import the native module

export default function Index() {
  const [coreVersion, setCoreVersion] = useState<string | null>(null);

  useEffect(() => {
    // Fetch the Linphone Core version on component mount
    async function fetchCoreVersion() {
      try {
        const version = await Linphonern.getCoreVersion();
        setCoreVersion(version);
      } catch (error) {
        console.error('Failed to fetch Linphone Core version:', error);
        setCoreVersion('Error fetching version');
      }
    }

    fetchCoreVersion();
  }, []);

  return (
    <View style={styles.container}>
      <Text style={styles.text}>
        {coreVersion
          ? `Linphone Core Version: ${coreVersion}`
          : 'Loading Linphone Core Version...'}
      </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    fontSize: 16,
    textAlign: 'center',
  },
});

compiling & building

  • npx expo prebuild --clean
  • npx expo run:ios
@tsuccar tsuccar changed the title How to use Local SDK with react native environment with a wrapper Can Local Linphone SDK work in react native environment ? Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant