twilio / twilio-voice-react-native

Other
75 stars 29 forks source link

voice.register(token) response null #359

Open iamsiddharthkamble opened 7 months ago

iamsiddharthkamble commented 7 months ago

when I call the register method with the access token , if token is invalid, getting response with error code status , but when token is valid getting response null

my MainActivity.kt is like

package com.pickmeup

import android.Manifest
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.ReactRootView
import com.twiliovoicereactnative.VoiceActivityProxy

class MainActivity : ReactActivity() {
    class MainActivityDelegate(activity: ReactActivity?, mainComponentName: String?) :
        ReactActivityDelegate(activity, mainComponentName) {
        override fun createRootView(): ReactRootView {
            val reactRootView = ReactRootView(context)
            // If you opted-in for the New Architecture, we enable the Fabric Renderer.
            reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED)
            return reactRootView
        }

        protected val isConcurrentRootEnabled: Boolean
            protected get() =// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
                // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
                BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
    }

    private val activityProxy = VoiceActivityProxy(
        this
    ) { permission: String ->
        if (Manifest.permission.RECORD_AUDIO == permission) {
            Toast.makeText(
                this@MainActivity,
                "Microphone permissions needed. Please allow in your application settings.",
                Toast.LENGTH_LONG
            ).show()
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && Manifest.permission.BLUETOOTH_CONNECT == permission) {
            Toast.makeText(
                this@MainActivity,
                "Bluetooth permissions needed. Please allow in your application settings.",
                Toast.LENGTH_LONG
            ).show()
        } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S_V2 && Manifest.permission.POST_NOTIFICATIONS == permission) {
            Toast.makeText(
                this@MainActivity,
                "Notification permissions needed. Please allow in your application settings.",
                Toast.LENGTH_LONG
            ).show()
        }
    }

    /**
     * Returns the name of the main component registered from JavaScript. This is used to schedule
     * rendering of the component.
     */
    override fun getMainComponentName(): String? {
        return "pickmeup"
    }

    /**
     * Returns the instance of the [ReactActivityDelegate]. There the RootView is created and
     * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
     * (Paper).
     */
    override fun createReactActivityDelegate(): ReactActivityDelegate {
        return MainActivityDelegate(this, mainComponentName)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        activityProxy.onCreate(savedInstanceState)
    }

    public override fun onDestroy() {
        activityProxy.onDestroy()
        super.onDestroy()
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        activityProxy.onNewIntent(intent)
    }
}

and MainApplication.kt is like

package com.pickmeup

import android.app.Application
import android.content.Context
import com.facebook.react.ReactApplication
import com.facebook.react.ReactInstanceManager
import com.facebook.react.config.ReactFeatureFlags
import com.facebook.soloader.SoLoader

import com.twiliovoicereactnative.VoiceApplicationProxy
import com.twiliovoicereactnative.VoiceApplicationProxy.VoiceReactNativeHost
import com.pickmeup.newarchitecture.MainApplicationReactNativeHost
import java.lang.reflect.InvocationTargetException

class MainApplication : Application(), ReactApplication {
    private val mNewArchitectureNativeHost: MainApplicationReactNativeHost =
        MainApplicationReactNativeHost(this)
    private val mReactNativeHost: MainReactNativeHost
    private val voiceApplicationProxy: VoiceApplicationProxy

    init {
        mReactNativeHost = MainReactNativeHost(this)
        voiceApplicationProxy = VoiceApplicationProxy(reactNativeHost)
    }

    override val reactNativeHost: VoiceReactNativeHost
        get() = if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
            mNewArchitectureNativeHost
        } else {
            mReactNativeHost
        }

    override fun onCreate() {
        super.onCreate()
        voiceApplicationProxy.onCreate()
        // for app center if available

        // If you opted-in for the New Architecture, we enable the TurboModule system
        ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
        SoLoader.init(this,  /* native exopackage */false)
        initializeFlipper(this, reactNativeHost.reactInstanceManager)
    }

    override fun onTerminate() {
        // Note: this method is not called when running on device, devices just kill the process.
        voiceApplicationProxy.onTerminate()
        super.onTerminate()
    }

    companion object {
        /**
         * Loads Flipper in React Native templates. Call this in the onCreate method with something like
         * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
         *
         * @param context
         * @param reactInstanceManager
         */
        private fun initializeFlipper(
            context: Context, reactInstanceManager: ReactInstanceManager
        ) {
            if (BuildConfig.DEBUG) {
                try {
                    /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
                    val aClass =
                        Class.forName("com.twiliovoicereactnativereferenceapp.ReactNativeFlipper")
                    aClass
                        .getMethod(
                            "initializeFlipper",
                            Context::class.java,
                            ReactInstanceManager::class.java
                        )
                        .invoke(null, context, reactInstanceManager)
                } catch (e: ClassNotFoundException) {
                    e.printStackTrace()
                } catch (e: NoSuchMethodException) {
                    e.printStackTrace()
                } catch (e: IllegalAccessException) {
                    e.printStackTrace()
                } catch (e: InvocationTargetException) {
                    e.printStackTrace()
                }
            }
        }
    }
}
iamsiddharthkamble commented 7 months ago

In Android Studio log sendEvent scopeVoice params {"type":"voiceEventRegistered"} but at the node console the response of voice.register(token) is null. My react native version 0.73.2

mhuynh5757 commented 7 months ago

Hi @iamsiddharthkamble please fill out the original issue template. It helps us tremendously with debugging customer issues. For example, the other versions of the tools in your dev environment.

iamsiddharthkamble commented 7 months ago

Hi I use
"@react-native-firebase/app": "^19.2.1", "@react-native-firebase/messaging": "^19.2.1", "@twilio/voice-react-native-sdk": "^1.0.0-beta.4", "react": "18.2.0", "react-native": "0.73.2",

MainReactNativeHost.kt MainApplication.kt MainActivity.kt

  useEffect(()=>{
    registerCall()
  },[])

const registerCall=async()=>{
  try{
    const registerCallResult = await voice.register(token);
    console.log(registerCallResult,"registerCallResult")
  }catch(e){
    console.log(e,'error at registerCallResult')
  }
}

the output on the console is like

LOG null registerCallResult

but in Android Studio logcat I found that

sendEvent scopeVoice params {"type":"voiceEventRegistered"}

mhuynh5757 commented 3 months ago

Hi @iamsiddharthkamble are you still encountering this issue? Please let me know your Android version and the rest of you development environment if so. See the Issue Template here: https://github.com/twilio/twilio-voice-react-native/blob/main/.github/ISSUE_TEMPLATE.md