Skip to content

Commit

Permalink
Upgrade dependencies and example app (#32)
Browse files Browse the repository at this point in the history
* Upgrade both sdk

* Upgrade RN

* Upgrade RN in example app

* Update pods

* Build and run on iOS and Android

* Update README and GitHub workflow
  • Loading branch information
MrHertal authored May 15, 2021
1 parent 6230a10 commit 566c907
Show file tree
Hide file tree
Showing 26 changed files with 3,260 additions and 3,978 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.pbxproj -text
# specific for windows script files
# Windows files should use crlf line endings
# https://help.github.com/articles/dealing-with-line-endings/
*.bat text eol=crlf
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
node-version: '14.x'
- run: yarn
- run: yarn lint
- run: yarn typescript
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ The following modifications must be made on `AppDelegate.m` in order to handle T

### Twilio server-side web application

Follow the Twilio Voice [iOS SDK Quickstart](https://www.twilio.com/docs/api/voice-sdk/ios/getting-started) and [Android SDK Quickstart](https://www.twilio.com/docs/api/voice-sdk/android/getting-started).
Follow the Twilio Voice [iOS SDK Quickstart](https://www.twilio.com/docs/api/voice-sdk/ios/getting-started) and [Android SDK Quickstart](https://www.twilio.com/docs/api/voice-sdk/android/getting-started), in order to prepare your Twilio environment.

Steps 1 and 6 must be skipped.
There are two options for configuring a server application. The new option is to deploy to Twilio Serverless the server application included in the two quickstart projects. The old option is to run one of the starter project such as [voice-quickstart-server-node](https://github.com/twilio/voice-quickstart-server-node).

## Installation

Expand All @@ -105,7 +105,7 @@ Run this command to complete installation on iOS:
cd ios/ && pod install
```

You must also create a Swift file like [this one](https://github.com/MrHertal/react-native-twilio-phone/blob/master/example/ios/File.swift) in the `/ios` folder. If you don't have such a file, your app won't build.
You must also create a Swift file like [this one](https://github.com/MrHertal/react-native-twilio-phone/blob/master/example/ios/File.swift) in the `/ios` folder. If you don't have such a file, your app may not build.

## Usage

Expand Down
3 changes: 3 additions & 0 deletions _editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Windows files
[*.bat]
end_of_line = crlf
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:3.5.3"
classpath("com.android.tools.build:gradle:4.1.0")
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down Expand Up @@ -128,5 +128,5 @@ dependencies {
api 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation 'com.twilio:voice-android:5.6.2'
implementation 'com.twilio:voice-android:5.7.2'
}
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TwilioPhone_kotlinVersion=1.3.50
TwilioPhone_compileSdkVersion=29
TwilioPhone_buildToolsVersion=29.0.2
TwilioPhone_buildToolsVersion=29.0.3
TwilioPhone_targetSdkVersion=29
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.facebook.react.bridge.*
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
import com.twilio.voice.*


class TwilioPhoneModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
class TwilioPhoneModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {

private val tag = "TwilioPhone"

Expand All @@ -21,7 +21,8 @@ class TwilioPhoneModule(reactContext: ReactApplicationContext) : ReactContextBas

private var callListener = callListener()

private var audioManager: AudioManager = reactContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
private var audioManager: AudioManager =
reactContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager

override fun getName(): String {
return "TwilioPhone"
Expand All @@ -31,23 +32,27 @@ class TwilioPhoneModule(reactContext: ReactApplicationContext) : ReactContextBas
fun register(accessToken: String, deviceToken: String) {
Log.i(tag, "Registering")

Voice.register(accessToken, Voice.RegistrationChannel.FCM, deviceToken, object : RegistrationListener {
override fun onRegistered(accessToken: String, fcmToken: String) {
Log.d(tag, "Successfully registered FCM token")
Voice.register(
accessToken,
Voice.RegistrationChannel.FCM,
deviceToken,
object : RegistrationListener {
override fun onRegistered(accessToken: String, fcmToken: String) {
Log.d(tag, "Successfully registered FCM token")

sendEvent(reactApplicationContext, "RegistrationSuccess", null)
}
sendEvent(reactApplicationContext, "RegistrationSuccess", null)
}

override fun onError(error: RegistrationException, accessToken: String, fcmToken: String) {
Log.e(tag, "Registration error: ${error.errorCode}, ${error.message}")
override fun onError(error: RegistrationException, accessToken: String, fcmToken: String) {
Log.e(tag, "Registration error: ${error.errorCode}, ${error.message}")

val params = Arguments.createMap()
params.putInt("errorCode", error.errorCode)
params.putString("errorMessage", error.message)
val params = Arguments.createMap()
params.putInt("errorCode", error.errorCode)
params.putString("errorMessage", error.message)

sendEvent(reactApplicationContext, "RegistrationFailure", params)
}
})
sendEvent(reactApplicationContext, "RegistrationFailure", params)
}
})
}

@ReactMethod
Expand Down Expand Up @@ -75,7 +80,10 @@ class TwilioPhoneModule(reactContext: ReactApplicationContext) : ReactContextBas
sendEvent(reactApplicationContext, "CallInvite", params)
}

override fun onCancelledCallInvite(cancelledCallInvite: CancelledCallInvite, callException: CallException?) {
override fun onCancelledCallInvite(
cancelledCallInvite: CancelledCallInvite,
callException: CallException?
) {
Log.d(tag, "Cancelled call invite received")

activeCallInvites.remove(cancelledCallInvite.callSid)
Expand Down Expand Up @@ -205,23 +213,27 @@ class TwilioPhoneModule(reactContext: ReactApplicationContext) : ReactContextBas
fun unregister(accessToken: String, deviceToken: String) {
Log.i(tag, "Unregistering")

Voice.unregister(accessToken, Voice.RegistrationChannel.FCM, deviceToken, object : UnregistrationListener {
override fun onUnregistered(accessToken: String, fcmToken: String) {
Log.d(tag, "Successfully unregistered FCM token")
Voice.unregister(
accessToken,
Voice.RegistrationChannel.FCM,
deviceToken,
object : UnregistrationListener {
override fun onUnregistered(accessToken: String, fcmToken: String) {
Log.d(tag, "Successfully unregistered FCM token")

sendEvent(reactApplicationContext, "UnregistrationSuccess", null)
}
sendEvent(reactApplicationContext, "UnregistrationSuccess", null)
}

override fun onError(error: RegistrationException, accessToken: String, fcmToken: String) {
Log.e(tag, "Unregistration error: ${error.errorCode}, ${error.message}")
override fun onError(error: RegistrationException, accessToken: String, fcmToken: String) {
Log.e(tag, "Unregistration error: ${error.errorCode}, ${error.message}")

val params = Arguments.createMap()
params.putInt("errorCode", error.errorCode)
params.putString("errorMessage", error.message)
val params = Arguments.createMap()
params.putInt("errorCode", error.errorCode)
params.putString("errorMessage", error.message)

sendEvent(reactApplicationContext, "UnregistrationFailure", params)
}
})
sendEvent(reactApplicationContext, "UnregistrationFailure", params)
}
})
}

@ReactMethod
Expand All @@ -241,7 +253,13 @@ class TwilioPhoneModule(reactContext: ReactApplicationContext) : ReactContextBas
}

if (permissionsToRequest.isNotEmpty()) {
currentActivity?.let { ActivityCompat.requestPermissions(it, permissionsToRequest.toTypedArray(), 1) }
currentActivity?.let {
ActivityCompat.requestPermissions(
it,
permissionsToRequest.toTypedArray(),
1
)
}
}

val permissions = Arguments.createMap()
Expand All @@ -251,9 +269,11 @@ class TwilioPhoneModule(reactContext: ReactApplicationContext) : ReactContextBas
callback(permissions)
}

private fun sendEvent(reactContext: ReactContext,
eventName: String,
params: WritableMap?) {
private fun sendEvent(
reactContext: ReactContext,
eventName: String,
params: WritableMap?
) {
reactContext
.getJSModule(RCTDeviceEventEmitter::class.java)
.emit(eventName, params)
Expand Down
1 change: 0 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

<service
android:name="io.wazo.callkeep.VoiceConnectionService"
Expand Down
5 changes: 3 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

buildscript {
ext {
buildToolsVersion = "29.0.2"
buildToolsVersion = "29.0.3"
minSdkVersion = 23
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "20.1.5948944"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.3")
classpath("com.android.tools.build:gradle:4.1.0")

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

android.useAndroidX=true
android.enableJetifier=true
FLIPPER_VERSION=0.74.0
FLIPPER_VERSION=0.75.1
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions example/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
[
'module-resolver',
{
extensions: ['.js', '.ts', '.json', '.jsx', '.tsx'],
alias: {
[pak.name]: path.join(__dirname, '..', pak.source),
},
Expand Down
File renamed without changes.
12 changes: 8 additions & 4 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ platform :ios, '11.0'
target 'TwilioPhoneExample' do
config = use_native_modules!

use_react_native!(:path => config["reactNativePath"])
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
)

pod 'react-native-twilio-phone', :path => '../..'

# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
use_flipper!({ 'Flipper' => '0.74.0' })
# you should disable the next line.
use_flipper!()
post_install do |installer|
flipper_post_install(installer)
react_native_post_install(installer)
end
end
Loading

0 comments on commit 566c907

Please sign in to comment.