Skip to content

Commit d7bf11a

Browse files
authored
refactor(samples): Bump to 1.3.0 [APICSA-1647] (#35)
* Bump to 1.3.0-alpha.3 * Use Record<string, any> in react package * Revert "Use Record<string, any> in react package" This reverts commit ba04cab. * Update ios-chat to use swift wrappers * Bump android apps to 1.3.0 * Bump iOS and react to 1.3.0
1 parent beab0b0 commit d7bf11a

File tree

37 files changed

+323
-100
lines changed

37 files changed

+323
-100
lines changed

contact-center/android-chat/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ dependencies {
8282
implementation 'com.google.firebase:firebase-messaging-ktx'
8383

8484
// Vonage Client SDK
85-
implementation("com.vonage:client-sdk-chat:1.2.1")
85+
implementation("com.vonage:client-sdk-chat:1.3.0")
8686

8787
// Dagger - HILT (Dependency Injector)
8888
implementation 'com.google.dagger:hilt-android:2.45'

contact-center/android-chat/app/src/main/java/com/example/vonage/chatsampleapp/chat/ChatClientManager.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,34 @@ class ChatClientManager(
9999
suspend fun getConversations(pageSize: Int = Constants.PAGE_SIZE,
100100
cursor: String? = null,
101101
order: PresentingOrder = Constants.DEFAULT_ORDER) : ConversationsPage =
102-
client.getConversations(order, pageSize, cursor)
102+
client.getConversations(GetConversationsParameters(order, pageSize, cursor))
103103

104104
suspend fun getMembers(pageSize: Int = Constants.PAGE_SIZE,
105105
cursor: String? = null,
106106
order: PresentingOrder = Constants.DEFAULT_ORDER,
107107
conversationId: ConversationId = currentConversation.id) : MembersPage =
108-
client.getConversationMembers(conversationId, order, pageSize, cursor)
108+
client.getConversationMembers(conversationId, GetConversationMembersParameters(order, pageSize, cursor))
109109

110110
suspend fun getEvents(pageSize: Int = Constants.PAGE_SIZE,
111111
cursor: String? = null,
112112
order: PresentingOrder = Constants.DEFAULT_ORDER,
113113
conversationId: ConversationId = currentConversation.id) : EventsPage =
114-
client.getConversationEvents(conversationId, order, pageSize, cursor)
114+
client.getConversationEvents(conversationId, GetConversationEventsParameters(order, pageSize, cursor))
115115

116116
suspend fun createConversation(name: String, displayName: String?) : ConversationId =
117-
client.createConversation(name, displayName)
117+
client.createConversation(CreateConversationParameters(name, displayName))
118118

119119
suspend fun joinConversation(conversationId: ConversationId) : MemberId =
120120
client.joinConversation(conversationId)
121121

122122
private suspend fun hasNoOtherMembers(conversationId: ConversationId) : Boolean {
123-
val page = client.getConversationMembers(pageSize = 2, cid = conversationId)
123+
val page = client.getConversationMembers(conversationId, GetConversationMembersParameters(pageSize = 2))
124124
return page.members.none { it.user?.name != currentUser.name }
125125
}
126126

127127
suspend fun leaveConversation(conversationId: ConversationId){
128128
client.leaveConversation(conversationId)
129-
//TODO: Check ASYNCHRONOUSLY if Conversation Needs to be cleaned up
129+
// Check ASYNCHRONOUSLY if Conversation Needs to be cleaned up
130130
CoroutineScope(Dispatchers.IO).launch {
131131
if(hasNoOtherMembers(conversationId)){
132132
deleteConversation(conversationId)
@@ -191,6 +191,7 @@ class ChatClientManager(
191191
is MessageVideoEvent -> "$sender has sent a video in the conversation ${event.conversationId}"
192192
is CustomConversationEvent -> "$sender has sent a custom event in the conversation ${event.conversationId}"
193193
is EphemeralConversationEvent -> "$sender has sent an ephemeral event in the conversation ${event.conversationId}"
194+
is EventDeleteConversationEvent -> "$sender has deleted event body ${event.body} in conversation ${event.conversationId}"
194195
}
195196

196197
// TODO: Provide utility to parse Conversation?

contact-center/android-chat/app/src/main/java/com/example/vonage/chatsampleapp/data/PagingDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class PagingDataSource<T : Any, PageT: Page>(
4040
val data : List<T> = when(response){
4141
is ConversationsPage -> (response.conversations as List<T>)
4242
is MembersPage -> (response.members.filterNot {
43-
// TODO: Filter Out Members who left
43+
// Filter Out Members who left
4444
it.state == MemberState.LEFT
4545
} as List<T>)
4646
is EventsPage -> (response.events as List<T>)

contact-center/android-chat/app/src/main/java/com/example/vonage/chatsampleapp/view/ConversationDetailsActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ConversationDetailsActivity : ComponentActivity() {
7474
LaunchedEffect(true){
7575
val conversationDetails = viewModel.getConversationDetails()
7676
// Possible use: handle Custom Data
77-
conversationDetails?.customData
77+
conversationDetails?.properties?.customData
7878
}
7979
ConversationDetailsScreen(
8080
conversationName,

contact-center/android-chat/app/src/main/java/com/example/vonage/chatsampleapp/view/ui/composables/ConversationEventItem.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ fun ConversationEventItem(
128128
senderImageUrl = senderImageUrl,
129129
time = time
130130
)
131-
is CustomConversationEvent, is EphemeralConversationEvent -> {
131+
is CustomConversationEvent,
132+
is EphemeralConversationEvent,
133+
is EventDeleteConversationEvent -> {
132134
//NOOP
133135
}
134136
}

contact-center/android-voice/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
implementation 'com.google.firebase:firebase-messaging-ktx'
5656

5757
// Vonage Client SDK
58-
implementation("com.vonage:client-sdk:1.2.1")
58+
implementation("com.vonage:client-sdk:1.3.0")
5959

6060
// Retrofit + Moshi (HTTP Client)
6161
def retrofit_version = "2.9.0"

contact-center/android-voice/app/src/main/java/com/example/vonage/voicesampleapp/activities/CallActivity.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
99
import android.os.Bundle
1010
import android.telecom.Connection
1111
import android.view.View
12+
import androidx.core.content.ContextCompat
1213
import com.example.vonage.voicesampleapp.App
1314
import com.example.vonage.voicesampleapp.R
1415
import com.example.vonage.voicesampleapp.databinding.ActivityCallBinding
@@ -51,11 +52,8 @@ class CallActivity : AppCompatActivity() {
5152
fallbackState = if(it) Connection.STATE_DISCONNECTED else null
5253
}
5354
// Call State Updated
54-
intent?.getStringExtra(CALL_STATE)?.let {
55-
setStateUI()
56-
if(it == CALL_DISCONNECTED){
57-
finish()
58-
}
55+
intent?.getStringExtra(CALL_STATE)?.let { callStateExtra ->
56+
setStateUI(callStateExtra)
5957
}
6058
}
6159
}
@@ -65,7 +63,12 @@ class CallActivity : AppCompatActivity() {
6563
setContentView(binding.root)
6664
handleIntent(intent)
6765
setBindings()
68-
registerReceiver(messageReceiver, IntentFilter(MESSAGE_ACTION))
66+
ContextCompat.registerReceiver(
67+
this,
68+
messageReceiver,
69+
IntentFilter(MESSAGE_ACTION),
70+
ContextCompat.RECEIVER_NOT_EXPORTED
71+
)
6972
}
7073

7174
override fun onDestroy() {
@@ -104,10 +107,10 @@ class CallActivity : AppCompatActivity() {
104107
userName.text = coreContext.activeCall?.callerDisplayName ?: fallbackUsername
105108
}
106109

107-
private fun setStateUI() = binding.run {
108-
val state = coreContext.activeCall?.state ?: fallbackState
110+
private fun setStateUI(callStateExtra: String? = null) = binding.run {
111+
val callState = coreContext.activeCall?.state ?: fallbackState
109112
//Buttons Visibility
110-
if(state == Connection.STATE_RINGING){
113+
if(callState == Connection.STATE_RINGING){
111114
btnAnswer.visibility = View.VISIBLE
112115
btnReject.visibility = View.VISIBLE
113116
btnHangup.visibility = View.GONE
@@ -122,15 +125,21 @@ class CallActivity : AppCompatActivity() {
122125
btnKeypad.visibility = View.VISIBLE
123126
}
124127
//Background Color and State label
125-
val (backgroundColor, stateLabel) = when(state) {
128+
val (backgroundColor, stateLabel) = when(callStateExtra){
129+
CALL_RECONNECTING -> R.color.gray to R.string.call_state_reconnecting_label
130+
else -> null
131+
} ?: when(callState) {
126132
Connection.STATE_RINGING -> R.color.gray to R.string.call_state_ringing_label
127133
Connection.STATE_DIALING -> R.color.gray to R.string.call_state_dialing_label
128134
Connection.STATE_ACTIVE -> R.color.green to R.string.call_state_active_label
129135
Connection.STATE_DISCONNECTED -> R.color.red to R.string.call_state_remotely_disconnected_label
130136
else -> R.color.red to R.string.call_state_locally_disconnected_label
131137
}
132138
cardView.setCardBackgroundColor(getColor(backgroundColor))
133-
callState.text = getString(stateLabel)
139+
callStateLabel.text = getString(stateLabel)
140+
if(callStateExtra == CALL_DISCONNECTED){
141+
finish()
142+
}
134143
}
135144

136145
private fun onAnswer(){
@@ -181,6 +190,8 @@ class CallActivity : AppCompatActivity() {
181190
const val IS_MUTED = "isMuted"
182191
const val CALL_STATE = "callState"
183192
const val CALL_ANSWERED = "answered"
193+
const val CALL_RECONNECTING = "reconnecting"
194+
const val CALL_RECONNECTED = "reconnected"
184195
const val CALL_DISCONNECTED = "disconnected"
185196
const val IS_REMOTE_DISCONNECT = "isRemoteDisconnect"
186197
}

contact-center/android-voice/app/src/main/java/com/example/vonage/voicesampleapp/core/VoiceClientManager.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class VoiceClientManager(private val context: Context) {
3939

4040
private fun initClient(){
4141
val config = VGClientInitConfig(LoggingLevel.Info)
42-
4342
client = VoiceClient(context, config)
4443
}
4544

@@ -99,6 +98,27 @@ class VoiceClientManager(private val context: Context) {
9998
}
10099
}
101100

101+
client.setOnCallMediaDisconnectListener { callId, reason ->
102+
println("Call $callId has been disconnected with reason: ${reason.name}")
103+
takeIfActive(callId)?.apply {
104+
cleanUp(DisconnectCause(DisconnectCause.ERROR), isRemote = false)
105+
}
106+
}
107+
108+
client.setOnCallMediaReconnectingListener { callId ->
109+
println("Call $callId is reconnecting")
110+
takeIfActive(callId)?.apply {
111+
notifyCallReconnectingToCallActivity(context)
112+
}
113+
}
114+
115+
client.setOnCallMediaReconnectionListener { callId ->
116+
println("Call $callId has successfully reconnected")
117+
takeIfActive(callId)?.apply {
118+
notifyCallReconnectedToCallActivity(context)
119+
}
120+
}
121+
102122
client.setCallInviteCancelListener { callId, reason ->
103123
println("Invite to Call $callId has been canceled with reason: ${reason.name}")
104124
takeIfActive(callId)?.apply {

contact-center/android-voice/app/src/main/java/com/example/vonage/voicesampleapp/telecom/TelecomHelper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class TelecomHelper(private val context: Context) {
5656
PhoneAccount
5757
.builder(phoneAccountHandle, CUSTOM_PHONE_ACCOUNT_NAME)
5858
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
59+
// To handle calls with your custom UI change it to:
60+
// .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
5961
.setIcon(Icon.createWithResource(context, R.drawable.vonage_logo_svg))
6062
.build()
6163
.also {

contact-center/android-voice/app/src/main/java/com/example/vonage/voicesampleapp/utils/NavigationUtils.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ internal fun notifyCallAnsweredToCallActivity(context: Context) {
8181
sendMessageToCallActivity(context, extras)
8282
}
8383

84+
internal fun notifyCallReconnectingToCallActivity(context: Context) {
85+
val extras = Bundle()
86+
extras.putString(CallActivity.CALL_STATE, CallActivity.CALL_RECONNECTING)
87+
sendMessageToCallActivity(context, extras)
88+
}
89+
90+
internal fun notifyCallReconnectedToCallActivity(context: Context) {
91+
val extras = Bundle()
92+
extras.putString(CallActivity.CALL_STATE, CallActivity.CALL_RECONNECTED)
93+
sendMessageToCallActivity(context, extras)
94+
}
95+
8496
internal fun notifyCallDisconnectedToCallActivity(context: Context, isRemote:Boolean) {
8597
val extras = Bundle()
8698
extras.putString(CallActivity.CALL_STATE, CallActivity.CALL_DISCONNECTED)

0 commit comments

Comments
 (0)