Skip to content

Commit

Permalink
Disconnect callback issue fixed (#274)
Browse files Browse the repository at this point in the history
* Disconnect callback issue fixed
added notification permission for android 13

* Disconnect callback issue fixed
added notification permission for android 13

* Disconnect callback issue fixed
added notification permission for android 13

* Disconnect callback issue fixed
added notification permission for android 13

* Disconnect callback issue fixed
added notification permission for android 13
  • Loading branch information
RakshakGaind0910 authored Feb 15, 2023
1 parent 9d64fcb commit e73ddae
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
Expand Down
88 changes: 58 additions & 30 deletions app/src/main/java/com/telnyx/webrtc/sdk/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

package com.telnyx.webrtc.sdk.ui

import android.Manifest
import android.Manifest.permission.INTERNET
import android.Manifest.permission.RECORD_AUDIO
import android.app.AlertDialog
import android.app.Dialog
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
Expand Down Expand Up @@ -215,6 +217,12 @@ class MainActivity : AppCompatActivity() {
Toast.LENGTH_SHORT
).show()
progress_indicator_id.visibility = View.INVISIBLE
incoming_call_section_id.visibility = View.GONE
call_control_section_id.visibility = View.GONE
login_section_id.visibility = View.VISIBLE

socket_text_value.text = getString(R.string.disconnected)
call_state_text_value.text = "-"
}
}
)
Expand Down Expand Up @@ -442,13 +450,6 @@ class MainActivity : AppCompatActivity() {
}

private fun disconnectPressed() {
incoming_call_section_id.visibility = View.GONE
call_control_section_id.visibility = View.GONE
login_section_id.visibility = View.VISIBLE

socket_text_value.text = getString(R.string.disconnected)
call_state_text_value.text = "-"

mainViewModel.disconnect()
}

Expand Down Expand Up @@ -533,31 +534,58 @@ class MainActivity : AppCompatActivity() {
}

private fun checkPermissions() {
Dexter.withContext(this)
.withPermissions(
RECORD_AUDIO,
INTERNET,
)
.withListener(object : MultiplePermissionsListener {
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
if (report!!.areAllPermissionsGranted()) {
connect_button_id.isClickable = true
} else if (report.isAnyPermissionPermanentlyDenied) {
Toast.makeText(
this@MainActivity,
"Audio permissions are required to continue",
Toast.LENGTH_LONG
).show()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Dexter.withContext(this)
.withPermissions(
RECORD_AUDIO, Manifest.permission.POST_NOTIFICATIONS
)
.withListener(object : MultiplePermissionsListener {
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
if (report!!.areAllPermissionsGranted()) {
connect_button_id.isClickable = true
} else if (report.isAnyPermissionPermanentlyDenied) {
Toast.makeText(
this@MainActivity,
"permissions are required to continue",
Toast.LENGTH_LONG
).show()
}
}
}

override fun onPermissionRationaleShouldBeShown(
permission: MutableList<PermissionRequest>?,
token: PermissionToken?
) {
token?.continuePermissionRequest()
}
}).check()
override fun onPermissionRationaleShouldBeShown(
permission: MutableList<PermissionRequest>?,
token: PermissionToken?
) {
token?.continuePermissionRequest()
}
}).check()
} else {
Dexter.withContext(this)
.withPermissions(
RECORD_AUDIO,
INTERNET
)
.withListener(object : MultiplePermissionsListener {
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
if (report!!.areAllPermissionsGranted()) {
connect_button_id.isClickable = true
} else if (report.isAnyPermissionPermanentlyDenied) {
Toast.makeText(
this@MainActivity,
"permissions are required to continue",
Toast.LENGTH_LONG
).show()
}
}

override fun onPermissionRationaleShouldBeShown(
permission: MutableList<PermissionRequest>?,
token: PermissionToken?
) {
token?.continuePermissionRequest()
}
}).check()
}
}

private fun handleCallNotification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ class TelnyxClient(
* @see [ConnectivityHelper]
* @see [TxSocket]
*/
fun disconnect() {
fun disconnect(disconnectMessage: String = "Socket disconnected") {
socketResponseLiveData.postValue(SocketResponse.error(disconnectMessage))
invalidateGatewayResponseTimer()
resetGatewayCounters()
unregisterNetworkCallback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,14 @@ class TxSocket(
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
super.onClosing(webSocket, code, reason)
Timber.tag("TxSocket").i("Socket is closing: $code :: $reason")
listener.disconnect("Socket is closed: $code :: $reason")
}

override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
super.onClosed(webSocket, code, reason)
Timber.tag("TxSocket").i("Socket is closed: $code :: $reason")
destroy()
listener.disconnect("Socket is closed: $code :: $reason")
}

override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class TxSocketTest : BaseTest() {
// Sleep to give time to connect
Thread.sleep(6000)
verify(client, times(1)).onConnectionEstablished()
client.pingPong()
Thread.sleep(30000)
verify(client, times(2)).pingPong()
socket.isPing shouldBe true
}

@Test
Expand Down Expand Up @@ -169,10 +173,6 @@ class TxSocketTest : BaseTest() {
// Sleep to give time to connect
Thread.sleep(6000)
verify(client, times(1)).onConnectionEstablished()
client.pingPong()
Thread.sleep(30000)
verify(client, times(2)).pingPong()
socket.isPing shouldBe true
}

@Test
Expand Down

0 comments on commit e73ddae

Please sign in to comment.