Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions app-to-app-kotlin/app-to-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 33
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.vonage.tutorial.apptoapp"
minSdkVersion 23
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand All @@ -35,12 +35,13 @@ android {
dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.nexmo.android:client-sdk:4.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

implementation 'com.vonage:client-sdk-voice:0.1.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Apptoapp">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.view.forEach
import com.nexmo.client.NexmoCall
import com.nexmo.client.NexmoCallEventListener
import com.nexmo.client.NexmoCallHandler
import com.nexmo.client.NexmoMember
import com.nexmo.client.NexmoCallMemberStatus
import com.nexmo.client.NexmoClient
import com.nexmo.client.NexmoMediaActionState
import com.nexmo.client.request_listener.NexmoApiError
import com.nexmo.client.request_listener.NexmoConnectionListener
import com.nexmo.client.request_listener.NexmoRequestListener
import com.vonage.voice.api.*

class MainActivity : AppCompatActivity() {

private lateinit var client: NexmoClient
private val aliceJWT = ""
private val bobJWT = ""
private lateinit var client: VoiceClient
private var otherUser: String = ""
private var onGoingCall: NexmoCall? = null
private var onGoingCall: VoiceCall? = null
private var callInvite: VoiceInvite? = null

private lateinit var connectionStatusTextView: TextView
private lateinit var waitingForIncomingCallTextView: TextView
Expand All @@ -35,7 +29,6 @@ class MainActivity : AppCompatActivity() {
private lateinit var answerCallButton: Button
private lateinit var rejectCallButton: Button
private lateinit var endCallButton: Button
private lateinit var callListener: NexmoCallEventListener

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -62,49 +55,17 @@ class MainActivity : AppCompatActivity() {
endCallButton.setOnClickListener { endCall() }
startCallButton.setOnClickListener { startCall() }

client = NexmoClient.Builder().build(this)
client = VoiceClient(this.application.applicationContext)
client.setConfig(ClientConfig(ConfigRegion.US))

client.setConnectionListener { connectionStatus, _ ->
runOnUiThread { connectionStatusTextView.text = connectionStatus.toString() }

if (connectionStatus == NexmoConnectionListener.ConnectionStatus.CONNECTED) {
runOnUiThread {
hideUI()
connectionStatusTextView.visibility = View.VISIBLE
startCallButton.visibility = View.VISIBLE
waitingForIncomingCallTextView.visibility = View.VISIBLE
}

return@setConnectionListener
}
}

client.addIncomingCallListener { it ->
onGoingCall = it
client.setCallInviteListener { invite ->
callInvite = invite
runOnUiThread {
hideUI()
answerCallButton.visibility = View.VISIBLE
rejectCallButton.visibility = View.VISIBLE
}
}

callListener = object: NexmoCallEventListener {
override fun onMemberStatusUpdated(callStatus: NexmoCallMemberStatus, callMember: NexmoMember) {
if (callStatus == NexmoCallMemberStatus.COMPLETED || callStatus == NexmoCallMemberStatus.CANCELLED) {
onGoingCall = null

runOnUiThread {
hideUI()
startCallButton.visibility = View.VISIBLE
waitingForIncomingCallTextView.visibility = View.VISIBLE
}
}
}

override fun onMuteChanged(nexmoMediaActionState: NexmoMediaActionState, callMember: NexmoMember) {}
override fun onEarmuffChanged(nexmoMediaActionState: NexmoMediaActionState, callMember: NexmoMember) {}
override fun onDTMF(dtmf: String, callMember: NexmoMember) {}
}
}

private fun hideUI() {
Expand All @@ -114,81 +75,112 @@ class MainActivity : AppCompatActivity() {

private fun loginAsAlice() {
otherUser = "Bob"
client.login("ALICE_JWT")
client.createSession(aliceJWT, null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this param optional?

err, sessionId ->
when {
err != null -> {
hideUI()
connectionStatusTextView.visibility = View.VISIBLE
connectionStatusTextView.text = err.localizedMessage
}
else -> {
hideUI()
connectionStatusTextView.visibility = View.VISIBLE
connectionStatusTextView.text = "Connected"
startCallButton.visibility = View.VISIBLE
waitingForIncomingCallTextView.visibility = View.VISIBLE
}
}
}
}

private fun loginAsBob() {
otherUser = "Alice"
client.login("BOB_JWT")
client.createSession(bobJWT, null) {
err, sessionId ->
when {
err != null -> {
hideUI()
connectionStatusTextView.visibility = View.VISIBLE
connectionStatusTextView.text = err.localizedMessage
}
else -> {
hideUI()
connectionStatusTextView.visibility = View.VISIBLE
connectionStatusTextView.text = "Connected"
startCallButton.visibility = View.VISIBLE
waitingForIncomingCallTextView.visibility = View.VISIBLE
}
}
}
}

@SuppressLint("MissingPermission")
fun startCall() {
client.serverCall(otherUser, null, object : NexmoRequestListener<NexmoCall> {
override fun onSuccess(call: NexmoCall?) {
runOnUiThread {
client.serverCall(mapOf("callee" to otherUser)) {
err, outboundCall ->
when {
err != null -> {
connectionStatusTextView.text = err.localizedMessage
}
else -> {
onGoingCall = outboundCall
hideUI()
endCallButton.visibility = View.VISIBLE
}

onGoingCall = call

onGoingCall?.addCallEventListener(callListener)
}

override fun onError(apiError: NexmoApiError) {
}
})
}
}


@SuppressLint("MissingPermission")
private fun answerCall() {
onGoingCall?.answer(object : NexmoRequestListener<NexmoCall> {
override fun onError(p0: NexmoApiError) {
}

override fun onSuccess(p0: NexmoCall?) {
onGoingCall?.addCallEventListener(callListener)
runOnUiThread {
callInvite?.answer {
err, incomingCall ->
when {
err != null -> {
connectionStatusTextView.text = err.localizedMessage
}
else -> {
onGoingCall = incomingCall
hideUI()
endCallButton.visibility = View.VISIBLE
}
}
})
}
}

private fun rejectCall() {
onGoingCall?.hangup(object : NexmoRequestListener<NexmoCall> {
override fun onError(p0: NexmoApiError) {
}

override fun onSuccess(p0: NexmoCall?) {
runOnUiThread {
callInvite?.reject {
err ->
when {
err != null -> {
connectionStatusTextView.text = err.localizedMessage
}
else -> {
hideUI()
startCallButton.visibility = View.VISIBLE
waitingForIncomingCallTextView.visibility = View.VISIBLE
}
}
})

}
onGoingCall = null
}

private fun endCall() {
onGoingCall?.hangup(object : NexmoRequestListener<NexmoCall> {
override fun onError(p0: NexmoApiError) {
}

override fun onSuccess(p0: NexmoCall?) {
runOnUiThread {
onGoingCall?.hangup {
err ->
when {
err != null -> {
connectionStatusTextView.text = err.localizedMessage
}
else -> {
hideUI()
startCallButton.visibility = View.VISIBLE
waitingForIncomingCallTextView.visibility = View.VISIBLE
}
}
})

}
onGoingCall = null
}
}
4 changes: 2 additions & 2 deletions app-to-app-kotlin/app-to-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.0"
ext.kotlin_version = "1.7.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath "com.android.tools.build:gradle:7.3.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Mar 26 10:20:49 CET 2021
#Mon Dec 12 11:50:57 GMT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
20 changes: 11 additions & 9 deletions app-to-phone-kotlin/app-to-phone/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 33
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.vonage.tutorial.voice.apptophone"
minSdkVersion 23
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand All @@ -30,17 +30,19 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.vonage.tutorial.voice.apptophone'
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.nexmo.android:client-sdk:4.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

implementation 'com.vonage:client-sdk-voice:0.1.3'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vonage.tutorial.voice.apptophone">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand All @@ -16,7 +15,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.apptophone">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Loading