diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index 797acea5..00000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 4f1c03cc..904bbab7 100644
--- a/README.md
+++ b/README.md
@@ -209,6 +209,19 @@ In order to do this you need to:
4. Setup a Push Credential within the Telnyx Portal
5. Generate a Firebase Cloud Messaging instance token
6. Send the token with your login message
+
+Finally, you will need to provide the `connect(..)` method with a `txPushIPConfig` object if the call is from a push notification.
+The `txPushIPConfig` is a data class that represents the push notification settings for the client to use. It looks like this:
+
+```kotlin
+val txPushIPConfig = TxPushIPConfig(
+ rtcIP = "",
+ rtcPort = ""
+)
+
+```
+
+The `rtc_port` and `rtc_ip` are the provided in the push notification payload.
For a detailed tutorial, please visit our official [Push Notification Docs](https://developers.telnyx.com/docs/v2/webrtc/push-notifications?type=Android)
diff --git a/app/.gitignore b/app/.gitignore
index 3af20ca4..26053f90 100644
--- a/app/.gitignore
+++ b/app/.gitignore
@@ -1,2 +1,14 @@
/build
.idea/
+
+# IntelliJ
+misc.xml
+deploymentTargetDropDown.xml
+render.experimental.xml
+
+# Keystore files
+*.jks
+*.keystore
+
+# Google Services (e.g. APIs or Firebase)
+google-services.json
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 04c0eac3..6e1b2a95 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,6 +5,7 @@ plugins {
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'com.google.gms.google-services'
+
}
def localProperties = new Properties()
@@ -199,4 +200,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+ implementation platform('com.google.firebase:firebase-bom:32.2.3')
+ implementation 'com.google.firebase:firebase-analytics'
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainActivity.kt b/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainActivity.kt
index a6dbcb82..07e6c802 100644
--- a/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainActivity.kt
+++ b/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainActivity.kt
@@ -32,8 +32,11 @@ import com.telnyx.webrtc.sdk.manager.UserManager
import com.telnyx.webrtc.sdk.model.AudioDevice
import com.telnyx.webrtc.sdk.model.LogLevel
import com.telnyx.webrtc.sdk.model.SocketMethod
+import com.telnyx.webrtc.sdk.model.TxPushIPConfig
import com.telnyx.webrtc.sdk.model.TxServerConfiguration
import com.telnyx.webrtc.sdk.ui.wsmessages.WsMessageFragment
+import com.telnyx.webrtc.sdk.utilities.parseObject
+import com.telnyx.webrtc.sdk.utilities.toJsonString
import com.telnyx.webrtc.sdk.utility.MyFirebaseMessagingService
import com.telnyx.webrtc.sdk.verto.receive.*
import dagger.hilt.android.AndroidEntryPoint
@@ -59,7 +62,7 @@ class MainActivity : AppCompatActivity() {
private var isDev = false
private var isAutomaticLogin = false
private var wsMessageList: ArrayList? = null
-
+ private var txPushIPConfig: TxPushIPConfig? = null
// Notification handling
private var notificationAcceptHandling: Boolean? = null
@@ -67,6 +70,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(findViewById(R.id.toolbar_id))
+ mainViewModel = ViewModelProvider(this@MainActivity)[MainViewModel::class.java]
+
// Add environment text
isDev = userManager.isDev
@@ -74,9 +79,9 @@ class MainActivity : AppCompatActivity() {
FirebaseApp.initializeApp(this)
- mainViewModel = ViewModelProvider(this@MainActivity)[MainViewModel::class.java]
checkPermissions()
+ handleCallNotification()
initViews()
}
@@ -148,13 +153,14 @@ class MainActivity : AppCompatActivity() {
} ?: throw IllegalStateException("Activity cannot be null")
}
- private fun connectToSocketAndObserve() {
+ private fun connectToSocketAndObserve(txPushIPConfig: TxPushIPConfig? = null) {
if (!isDev) {
- mainViewModel.initConnection(applicationContext, null)
+ mainViewModel.initConnection(applicationContext, null,txPushIPConfig)
} else {
mainViewModel.initConnection(
applicationContext,
- TxServerConfiguration(host = "rtcdev.telnyx.com")
+ TxServerConfiguration(host = "rtcdev.telnyx.com"),
+ txPushIPConfig
)
}
observeSocketResponses()
@@ -211,6 +217,7 @@ class MainActivity : AppCompatActivity() {
}
override fun onError(message: String?) {
+ Timber.e("onError: %s", message)
Toast.makeText(
this@MainActivity,
message ?: "Socket Connection Error",
@@ -382,7 +389,14 @@ class MainActivity : AppCompatActivity() {
private fun connectButtonPressed() {
progress_indicator_id.visibility = View.VISIBLE
- connectToSocketAndObserve()
+ if (notificationAcceptHandling == true) {
+ Timber.d("notificationAcceptHandling is true ${txPushIPConfig?.toJsonString()}")
+ if (txPushIPConfig != null) {
+ connectToSocketAndObserve(txPushIPConfig)
+ }
+ }else {
+ connectToSocketAndObserve()
+ }
}
private fun doLogin(isAuto: Boolean) {
@@ -455,6 +469,7 @@ class MainActivity : AppCompatActivity() {
Timber.d("FCM TOKEN RECEIVED: $token")
}
fcmToken = token
+
}
}
@@ -601,6 +616,7 @@ class MainActivity : AppCompatActivity() {
val action = intent.extras?.get(MyFirebaseMessagingService.EXT_KEY_DO_ACTION) as String?
action?.let {
+ txPushIPConfig = intent.extras?.get(MyFirebaseMessagingService.TX_IP_CONFIG)?.toString()?.parseObject()
if (action == MyFirebaseMessagingService.ACT_ANSWER_CALL) {
// Handle Answer
notificationAcceptHandling = true
@@ -611,8 +627,5 @@ class MainActivity : AppCompatActivity() {
}
}
- override fun onResume() {
- super.onResume()
- handleCallNotification()
- }
+
}
diff --git a/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt b/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt
index 299da2db..872fd86b 100644
--- a/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt
+++ b/app/src/main/java/com/telnyx/webrtc/sdk/ui/MainViewModel.kt
@@ -15,6 +15,7 @@ import com.telnyx.webrtc.sdk.TokenConfig
import com.telnyx.webrtc.sdk.manager.UserManager
import com.telnyx.webrtc.sdk.model.AudioDevice
import com.telnyx.webrtc.sdk.model.CallState
+import com.telnyx.webrtc.sdk.model.TxPushIPConfig
import com.telnyx.webrtc.sdk.model.TxServerConfiguration
import com.telnyx.webrtc.sdk.verto.receive.ReceivedMessageBody
import com.telnyx.webrtc.sdk.verto.receive.SocketResponse
@@ -34,12 +35,16 @@ class MainViewModel @Inject constructor(
private var calls: Map = mapOf()
- fun initConnection(context: Context, providedServerConfig: TxServerConfiguration?) {
+ fun initConnection(
+ context: Context,
+ providedServerConfig: TxServerConfiguration?,
+ txPushIPConfig: TxPushIPConfig? = null
+ ) {
telnyxClient = TelnyxClient(context)
providedServerConfig?.let {
- telnyxClient?.connect(it)
+ telnyxClient?.connect(it, txPushIPConfig = txPushIPConfig)
} ?: run {
- telnyxClient?.connect()
+ telnyxClient?.connect(txPushIPConfig = txPushIPConfig)
}
}
@@ -101,10 +106,11 @@ class MainViewModel @Inject constructor(
telnyxClient?.call?.acceptCall(callId, destinationNumber)
}
- fun disablePushNotifications(sipUserName:String,fcmToken: String) {
- telnyxClient?.disablePushNotification(sipUserName,null, fcmToken)
+ fun disablePushNotifications(sipUserName: String, fcmToken: String) {
+ telnyxClient?.disablePushNotification(sipUserName, null, fcmToken)
}
+
fun endCall(callId: UUID? = null) {
callId?.let {
telnyxClient?.call?.endCall(callId)
diff --git a/app/src/main/java/com/telnyx/webrtc/sdk/utility/MyFirebaseMessagingService.kt b/app/src/main/java/com/telnyx/webrtc/sdk/utility/MyFirebaseMessagingService.kt
index 0ac60fab..2d1cf96c 100644
--- a/app/src/main/java/com/telnyx/webrtc/sdk/utility/MyFirebaseMessagingService.kt
+++ b/app/src/main/java/com/telnyx/webrtc/sdk/utility/MyFirebaseMessagingService.kt
@@ -19,7 +19,9 @@ import com.google.firebase.messaging.RemoteMessage
import com.google.gson.Gson
import com.telnyx.webrtc.sdk.R
import com.telnyx.webrtc.sdk.model.PushMetaData
+import com.telnyx.webrtc.sdk.model.TxPushIPConfig
import com.telnyx.webrtc.sdk.ui.MainActivity
+import com.telnyx.webrtc.sdk.utilities.toJsonString
import org.json.JSONObject
import timber.log.Timber
import java.util.*
@@ -46,6 +48,11 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationID = Random().nextInt(3000)
+ // Save the IP and Port for the call
+ val txPushIPConfigData = TxPushIPConfig(
+ telnyxPushMetadata.rtcIP,
+ telnyxPushMetadata.rtcPort
+ ).toJsonString()
/*
Apps targeting SDK 26 or above (Android O) must implement notification channels and add its notifications
to at least one of them.
@@ -71,6 +78,9 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
answerResultIntent.action = Intent.ACTION_VIEW
answerResultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
answerResultIntent.putExtra(EXT_KEY_DO_ACTION, ACT_ANSWER_CALL)
+
+ answerResultIntent.putExtra(TX_IP_CONFIG, txPushIPConfigData)
+
val answerPendingIntent = PendingIntent.getActivity(
this,
ANSWER_REQUEST_CODE,
@@ -83,7 +93,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
.setSmallIcon(R.drawable.ic_stat_contact_phone)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentTitle(remoteMessage.data["title"])
- .setContentText(telnyxPushMetadata.caller_name + " - " + telnyxPushMetadata.caller_number)
+ .setContentText(telnyxPushMetadata.callerName + " - " + telnyxPushMetadata.callerNumber)
.setVibrate(longArrayOf(1000, 1000, 1000, 1000, 1000))
.addAction(R.drawable.ic_call_white, ACT_ANSWER_CALL, answerPendingIntent)
.addAction(R.drawable.ic_call_end_white, ACT_REJECT_CALL, rejectPendingIntent)
@@ -143,6 +153,8 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
private const val ANSWER_REQUEST_CODE = 0
private const val REJECT_REQUEST_CODE = 1
+ const val TX_IP_CONFIG = "tx_push_ip_config"
+
const val EXT_KEY_DO_ACTION = "ext_key_do_action"
const val EXT_CALL_ID = "ext_call_id"
const val EXT_DESTINATION_NUMBER = "ext_destination_number"
diff --git a/telnyx_rtc/build.gradle b/telnyx_rtc/build.gradle
index 6875e334..3a1bfe43 100644
--- a/telnyx_rtc/build.gradle
+++ b/telnyx_rtc/build.gradle
@@ -13,7 +13,7 @@ apply plugin: 'maven-publish'
apply plugin: "com.bugsnag.android.gradle"
def getVersionName = { ->
- return "v1.2.16-alpha"
+ return "v.1.2.4"
}
def getArtifactId = { ->
diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt
index 6135ccc1..478ce26f 100644
--- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt
+++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/TelnyxClient.kt
@@ -78,6 +78,13 @@ class TelnyxClient(
val call: Call? by lazy { buildCall() }
+ private var isCallPendingFromPush: Boolean = false
+ private var txPushIPConfig: TxPushIPConfig? = null
+ private fun processCallFromPush(txPushIPConfig: TxPushIPConfig) {
+ isCallPendingFromPush = true
+ this.txPushIPConfig = txPushIPConfig
+ }
+
/**
* Build a call containing all required parameters.
* Will return null if there has been no session established (No successful connection and login)
@@ -159,8 +166,19 @@ class TelnyxClient(
launch {
// Socket is now the reconnectionSocket
socket = socketReconnection!!
+
+
+ if (providedHostAddress == null) {
+ providedHostAddress =
+ if (txPushIPConfig == null) Config.TELNYX_PROD_HOST_ADDRESS
+ else
+ Config.TELNYX_PROD_HOST_ADDRESS +
+ "?rtc_ip=${txPushIPConfig!!.rtcIP}" +
+ "&rtc_port=${txPushIPConfig!!.rtcPort}"
+ }
+
// Connect to new socket
- socket.connect(this@TelnyxClient, providedHostAddress, providedPort)
+ socket.connect(this@TelnyxClient, providedHostAddress, providedPort, txPushIPConfig)
delay(1000)
// Login with stored configuration
credentialSessionConfig?.let {
@@ -212,15 +230,32 @@ class TelnyxClient(
* Will respond with 'No Network Connection' if there is no network available
* @see [TxSocket]
*/
- fun connect(providedServerConfig: TxServerConfiguration = TxServerConfiguration()) {
+ fun connect(
+ providedServerConfig: TxServerConfiguration = TxServerConfiguration(),
+ txPushIPConfig: TxPushIPConfig? = null
+ ) {
+
+ if (txPushIPConfig != null) {
+ processCallFromPush(txPushIPConfig)
+ }
+
invalidateGatewayResponseTimer()
resetGatewayCounters()
- providedHostAddress = providedServerConfig.host
+
+ providedHostAddress =
+ if (txPushIPConfig == null) providedServerConfig.host
+ else providedServerConfig.host +
+ "?rtc_ip=${txPushIPConfig!!.rtcIP}" +
+ "&rtc_port=${txPushIPConfig!!.rtcPort}"
+
+
+ Timber.d("Provided Host Address: $providedHostAddress")
+
providedPort = providedServerConfig.port
providedTurn = providedServerConfig.turn
providedStun = providedServerConfig.stun
if (ConnectivityHelper.isNetworkEnabled(context)) {
- socket.connect(this, providedHostAddress, providedPort)
+ socket.connect(this, providedHostAddress, providedPort, txPushIPConfig)
} else {
socketResponseLiveData.postValue(SocketResponse.error("No Network Connection"))
}
@@ -335,7 +370,7 @@ class TelnyxClient(
login = user,
passwd = password,
userVariables = notificationJsonObject,
- loginParams = arrayListOf(),
+ loginParams = mapOf("attach_call" to "true"),
sessid = sessid
)
)
@@ -390,6 +425,26 @@ class TelnyxClient(
}
+ private fun attachCall() {
+
+ val params = AttachCallParams(
+ userVariables = AttachUserVariables()
+ )
+
+ val attachPushMessage = SendingMessageBody(
+ id = UUID.randomUUID().toString(),
+ method = SocketMethod.ATTACH_CALL.methodName,
+ params = params
+ )
+ Log.d("sending attach Call", attachPushMessage.toString())
+ socket.send(attachPushMessage)
+ //reset push params
+ txPushIPConfig = null
+ isCallPendingFromPush = false
+
+ }
+
+
/**
* Logs the user in with credentials provided via TokenConfig
*
@@ -424,7 +479,7 @@ class TelnyxClient(
login = null,
passwd = null,
userVariables = notificationJsonObject,
- loginParams = arrayListOf(),
+ loginParams = mapOf("attach_calls" to "true"),
sessid = sessid
)
)
@@ -587,6 +642,12 @@ class TelnyxClient(
socket.isLoggedIn = true
+ Timber.d("isCallPendingFromPush $isCallPendingFromPush")
+ //if there is a call pending from push, attach it
+ if (isCallPendingFromPush) {
+ attachCall()
+ }
+
CoroutineScope(Dispatchers.Main).launch {
socketResponseLiveData.postValue(
SocketResponse.messageReceived(
@@ -632,6 +693,7 @@ class TelnyxClient(
"[%s] :: onClientReady :: Ready to make calls",
this@TelnyxClient.javaClass.simpleName,
)
+
socketResponseLiveData.postValue(
SocketResponse.messageReceived(
ReceivedMessageBody(
@@ -727,6 +789,7 @@ class TelnyxClient(
override fun onErrorReceived(jsonObject: JsonObject) {
val errorMessage = jsonObject.get("error").asJsonObject.get("message").asString
+ Timber.d("[%s] :: onErrorReceived ", errorMessage)
socketResponseLiveData.postValue(SocketResponse.error(errorMessage))
}
diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/PushMetaData.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/PushMetaData.kt
index 55350033..87c1c3c7 100644
--- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/PushMetaData.kt
+++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/PushMetaData.kt
@@ -1,7 +1,16 @@
package com.telnyx.webrtc.sdk.model
+import com.google.gson.annotations.SerializedName
+
data class PushMetaData(
- val caller_name: String,
- val caller_number: String,
- val call_id: String
-)
+ @SerializedName("caller_name")
+ val callerName: String,
+ @SerializedName("caller_number")
+ val callerNumber: String,
+ @SerializedName("call_id")
+ val callId: String,
+ @SerializedName("rtc_ip")
+ val rtcIP: String,
+ @SerializedName("rtc_port")
+ val rtcPort: Int,
+ )
diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/SocketMethod.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/SocketMethod.kt
index aaf26df7..98d2aab1 100644
--- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/SocketMethod.kt
+++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/SocketMethod.kt
@@ -32,5 +32,6 @@ enum class SocketMethod(var methodName: String) {
CLIENT_READY("telnyx_rtc.clientReady"),
GATEWAY_STATE("telnyx_rtc.gatewayState"),
DISABLE_PUSH("telnyx_rtc.disable_push_notification"),
+ ATTACH_CALL("telnyx_rtc.attachCalls"),
LOGIN("login")
}
diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/TxPushIPConfig.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/TxPushIPConfig.kt
new file mode 100644
index 00000000..1b5500d7
--- /dev/null
+++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/model/TxPushIPConfig.kt
@@ -0,0 +1,8 @@
+package com.telnyx.webrtc.sdk.model
+
+import java.io.Serializable
+
+data class TxPushIPConfig(
+ val rtcIP: String,
+ val rtcPort: Int
+)
diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt
index 372985cc..ed1fd040 100644
--- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt
+++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/socket/TxSocket.kt
@@ -11,6 +11,7 @@ import com.telnyx.webrtc.sdk.TelnyxClient
import com.telnyx.webrtc.sdk.model.SocketError.CREDENTIAL_ERROR
import com.telnyx.webrtc.sdk.model.SocketError.TOKEN_ERROR
import com.telnyx.webrtc.sdk.model.SocketMethod.*
+import com.telnyx.webrtc.sdk.model.TxPushIPConfig
import kotlinx.coroutines.*
import okhttp3.*
import okhttp3.logging.HttpLoggingInterceptor
@@ -58,7 +59,8 @@ class TxSocket(
fun connect(
listener: TelnyxClient,
providedHostAddress: String? = Config.TELNYX_PROD_HOST_ADDRESS,
- providedPort: Int? = Config.TELNYX_PORT
+ providedPort: Int? = Config.TELNYX_PORT,
+ txPushIPConfig: TxPushIPConfig? = null
) = launch {
client = OkHttpClient.Builder()
.addNetworkInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
@@ -74,6 +76,7 @@ class TxSocket(
}
).build()
+
providedHostAddress?.let {
host_address = it
}
@@ -81,8 +84,16 @@ class TxSocket(
port = it
}
+ val requestUrl = if (txPushIPConfig != null) {
+ "wss://$host_address"
+ } else {
+ "wss://$host_address:$port/"
+ }
+
val request: Request =
- Request.Builder().url("wss://$host_address:$port/").build()
+ Request.Builder().url(requestUrl).build()
+
+ Timber.d("request: $requestUrl")
socket = client.newWebSocket(
request,
object : WebSocketListener() {
@@ -117,7 +128,9 @@ class TxSocket(
params = result.get("params").asJsonObject
if (params.asJsonObject.has("state")) {
val gatewayState = params.get("state").asString
- listener.onGatewayStateReceived(gatewayState, sessionId)
+ if (gatewayState != STATE_ATTACHED) {
+ listener.onGatewayStateReceived(gatewayState, sessionId)
+ }
}
} else if (jsonObject.get("result").asJsonObject.has("message")) {
val result = jsonObject.get("result").asJsonObject
@@ -287,4 +300,8 @@ class TxSocket(
}
job.cancel("Socket was destroyed, cancelling attached job")
}
+
+ companion object {
+ const val STATE_ATTACHED = "ATTACHED"
+ }
}
diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/utilities/StringExtensions.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/utilities/StringExtensions.kt
index 8cdb75ea..1743970c 100644
--- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/utilities/StringExtensions.kt
+++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/utilities/StringExtensions.kt
@@ -7,6 +7,12 @@ package com.telnyx.webrtc.sdk.utilities
/**
* String extensions functions used by the SDK
*/
+import android.util.MalformedJsonException
+import com.google.gson.Gson
+import com.google.gson.GsonBuilder
+import com.google.gson.JsonIOException
+import com.google.gson.reflect.TypeToken
+import timber.log.Timber
import java.nio.charset.StandardCharsets
fun String.encodeBase64(): String {
@@ -16,6 +22,24 @@ fun String.encodeBase64(): String {
)
}
+fun Any.toJsonString(): String {
+ return try {
+ GsonBuilder().serializeSpecialFloatingPointValues().create().toJson(this)
+ }catch (e: JsonIOException){
+ Timber.e(e)
+ ""
+ }
+}
+
+inline fun String.parseObject(): T? {
+ return try {
+ Gson().fromJson(this, object : TypeToken() {}.type)
+ } catch (ex: JsonIOException) {
+ Timber.e(ex)
+ null
+ }
+}
+
fun String.decodeBase64(): String {
return String(
android.util.Base64.decode(this, android.util.Base64.DEFAULT),
diff --git a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/verto/send/ParamRequest.kt b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/verto/send/ParamRequest.kt
index 6ca68d1c..051fa1d6 100644
--- a/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/verto/send/ParamRequest.kt
+++ b/telnyx_rtc/src/main/java/com/telnyx/webrtc/sdk/verto/send/ParamRequest.kt
@@ -15,10 +15,12 @@ data class LoginParam(
val login: String?,
val passwd: String?,
val userVariables: JsonObject,
- val loginParams: ArrayList?,
- val sessid: String
+ val loginParams: Map?,
+ val sessid: String ,
) : ParamRequest()
+
+
data class CallParams(
val sessid: String,
val sdp: String,
@@ -49,6 +51,19 @@ data class TokenDisablePushParams(
val userVariables: UserVariables
) : ParamRequest()
+data class AttachCallParams(
+ @SerializedName("userVariables")
+ val userVariables: AttachUserVariables
+) : ParamRequest()
+
+
+data class AttachUserVariables(
+ @SerializedName("push_notification_environment")
+ val pushNotificationEnvironment:String = "production",
+ @SerializedName("push_notification_provider")
+ val pushNotificationProvider:String = "android",
+)
+
data class UserVariables(
@SerializedName("push_device_token")
val pushDeviceToken:String,
diff --git a/versions.gradle b/versions.gradle
index f2997a70..84c320d4 100644
--- a/versions.gradle
+++ b/versions.gradle
@@ -2,7 +2,7 @@ ext.deps = [:]
def versions = [:]
versions.android_gradle_plugin = '4.2.0'
-versions.google_play_services = "4.3.5"
+versions.google_play_services = "4.3.15"
versions.kotlin = "1.4.21"
versions.androidx_core = "1.3.2"
versions.androidx_appcompat = "1.2.0"