|
@@ -3,7 +3,6 @@ package com.wdkl.ncs.android.component.home.activity
|
|
|
import android.app.Activity
|
|
|
import android.bluetooth.BluetoothAdapter
|
|
|
import android.bluetooth.BluetoothHeadset
|
|
|
-import android.graphics.Color
|
|
|
import android.os.Bundle
|
|
|
import android.os.CountDownTimer
|
|
|
import android.os.Handler
|
|
@@ -37,7 +36,6 @@ import kotlinx.android.synthetic.main.activity_sip_voip_audio.call_duration_tv
|
|
|
import kotlinx.android.synthetic.main.activity_sip_voip_audio.hang_up_imagev
|
|
|
import kotlinx.android.synthetic.main.activity_sip_voip_audio.room_number_tv
|
|
|
import kotlinx.android.synthetic.main.activity_web_rtc_voip_audio.*
|
|
|
-import kotlinx.android.synthetic.main.watch_activity_home2.*
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
@@ -61,7 +59,7 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
//呼叫倒计时
|
|
|
lateinit var countDownTimer: CountDownTimer
|
|
|
private var isClick = true //是否可点击
|
|
|
-
|
|
|
+ private var createEnabled = true
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
@@ -99,7 +97,9 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
}
|
|
|
|
|
|
if (action == CALLING) {
|
|
|
- createCallout()
|
|
|
+ AppTool.Time.delay(500) {
|
|
|
+ createCallout()
|
|
|
+ }
|
|
|
|
|
|
call_duration_tv.visibility = View.VISIBLE
|
|
|
call_duration_tv.text = "连接中...."
|
|
@@ -112,10 +112,6 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun onStart() {
|
|
|
- super.onStart()
|
|
|
- }
|
|
|
-
|
|
|
fun init() {
|
|
|
hang_up_imagev.setOnClickListener(this)
|
|
|
hands_free_image.setOnClickListener(this)
|
|
@@ -134,9 +130,14 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
|
|
|
fun createCallout(){
|
|
|
Handler().postDelayed({
|
|
|
+ if (gEngineKit?.currentSession?.state != EnumType.CallState.Connected){
|
|
|
+ //showMessage("连接失败")
|
|
|
+ gEngineKit?.endCall()
|
|
|
+ finish()
|
|
|
+ }
|
|
|
call_duration_tv.base = SystemClock.elapsedRealtime()
|
|
|
call_duration_tv.start()
|
|
|
- }, 3500)
|
|
|
+ }, 2900)
|
|
|
|
|
|
val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
if ((interactionVO.fromClerkId!=null && interactionVO.fromClerkId>=0) && interactionVO.fromDeviceId!=Constants.deviceId){
|
|
@@ -162,32 +163,38 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
}
|
|
|
},1000)
|
|
|
} else {
|
|
|
- var room = UUID.randomUUID().toString() + System.currentTimeMillis()
|
|
|
- Log.d(TAG, "生成的房间号room " + room + "sipid targetId" + targetId)
|
|
|
- gEngineKit?.currentSession?.setCallState(EnumType.CallState.Idle)
|
|
|
- val outCallResult = gEngineKit?.startOutCall(applicationContext, room, targetId, true)
|
|
|
- val session = gEngineKit?.currentSession
|
|
|
- if (session == null){
|
|
|
- showMessage("通话失败,请重试1")
|
|
|
- AppTool.Time.delay(800) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- } else {
|
|
|
- session.setSessionCallback(this)
|
|
|
- Log.d(TAG+"_peer"," 呼出状态: myId = ${session?.mMyId} , targetId = ${session?.mTargetId}, roomId = ${session?.roomId}, state = ${session?.state}, outCallResult = $outCallResult")
|
|
|
- if (outCallResult!!) {
|
|
|
- setAudioDeviceOut(session)
|
|
|
- } else if (session.state == EnumType.CallState.Connected || session.state == EnumType.CallState.Connecting){
|
|
|
- setAudioDeviceOut(session)
|
|
|
- } else {
|
|
|
- if (session.state != EnumType.CallState.Idle) {
|
|
|
- showMessage("对方忙线中2")
|
|
|
- } else {
|
|
|
- showMessage("通话失败,请重试")
|
|
|
- }
|
|
|
+ if (createEnabled) {
|
|
|
+ var room = UUID.randomUUID().toString() + System.currentTimeMillis()
|
|
|
+ Log.d(TAG, "生成的房间号room " + room + "sipid targetId" + targetId)
|
|
|
+ //gEngineKit?.currentSession?.setCallState(EnumType.CallState.Idle)
|
|
|
+ val outCallResult = gEngineKit?.startOutCall(applicationContext, room, targetId, true)
|
|
|
+ val session = gEngineKit?.currentSession
|
|
|
+ if (session == null) {
|
|
|
+ showMessage("通话失败,请重试1")
|
|
|
AppTool.Time.delay(800) {
|
|
|
finish()
|
|
|
}
|
|
|
+ } else {
|
|
|
+ session.setSessionCallback(this)
|
|
|
+ Log.d(TAG + "_peer", " 呼出状态: myId = ${session?.mMyId} , targetId = ${session?.mTargetId}, roomId = ${session?.roomId}, state = ${session?.state}, outCallResult = $outCallResult")
|
|
|
+ if (outCallResult!!) {
|
|
|
+ setAudioDeviceOut(session)
|
|
|
+ } else if (session.state == EnumType.CallState.Connected || session.state == EnumType.CallState.Connecting) {
|
|
|
+ setAudioDeviceOut(session)
|
|
|
+ } else {
|
|
|
+ if (session.state != EnumType.CallState.Idle) {
|
|
|
+ showMessage("对方忙线中2")
|
|
|
+ } else {
|
|
|
+ showMessage("通话失败,请重试")
|
|
|
+ }
|
|
|
+ AppTool.Time.delay(300) {
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
+ finish()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -285,7 +292,9 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
Log.i(TAG, "对方接听电话啦")
|
|
|
call_duration_tv.visibility = View.VISIBLE
|
|
|
call_duration_tv.text = "连接中...."
|
|
|
- createCallout()
|
|
|
+ AppTool.Time.delay(600) {
|
|
|
+ createCallout()
|
|
|
+ }
|
|
|
} else if (tcpModel.action == TcpAction.VoiceAction.HANDOFF) { //对方挂断
|
|
|
|
|
|
var interactionVO: InteractionVO? = null
|
|
@@ -298,7 +307,8 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
if (interactionVO!!.id == currentTnVO.id){
|
|
|
call_duration_tv.stop()
|
|
|
showMessage("对方挂断")
|
|
|
- gEngineKit?.currentSession?.leave()
|
|
|
+ createEnabled = false
|
|
|
+ gEngineKit?.endCall()
|
|
|
finish()
|
|
|
}
|
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.REJECT) {
|
|
@@ -311,20 +321,33 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
val currentTnVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
if (interactionVO!!.id == currentTnVO.id){
|
|
|
showMessage("对方拒绝接听")
|
|
|
+ createEnabled = false
|
|
|
+ gEngineKit?.endCall()
|
|
|
finish()
|
|
|
}
|
|
|
|
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.CALLING) {
|
|
|
+ createEnabled = false
|
|
|
+ gEngineKit?.endCall()
|
|
|
//showMessage("对方正在通话")
|
|
|
AppTool.Time.delay(800) {
|
|
|
finish()
|
|
|
}
|
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.FAILED) {
|
|
|
+ gEngineKit?.endCall()
|
|
|
//voiceStatus.setText("对方拒绝");
|
|
|
showMessage("呼叫失败,对方可能不在线")
|
|
|
+ createEnabled = false
|
|
|
AppTool.Time.delay(800) {
|
|
|
finish()
|
|
|
}
|
|
|
+ } else if (tcpModel.action === TcpAction.VoiceAction.CANCEL) {
|
|
|
+ showMessage("对方取消")
|
|
|
+ createEnabled = false
|
|
|
+ gEngineKit?.endCall()
|
|
|
+ AppTool.Time.delay(400) {
|
|
|
+ finish()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -348,7 +371,14 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
}
|
|
|
MediaPlayHelper.getInstance().stopMusic()
|
|
|
EventBus.getDefault().unregister(this)
|
|
|
- gEngineKit?.currentSession?.setCallState(EnumType.CallState.Idle)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun finish() {
|
|
|
+ if (gEngineKit?.currentSession?.state != EnumType.CallState.Idle){
|
|
|
+ gEngineKit?.endCall()
|
|
|
+ }
|
|
|
+ super.finish()
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
@@ -366,7 +396,7 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
gEngineKit?.endCall()
|
|
|
runOnUiThread(Runnable {
|
|
|
//showMessage("对方挂断")
|
|
|
- AppTool.Time.delay(800) {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
finish()
|
|
|
}
|
|
|
})
|
|
@@ -399,16 +429,12 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
runOnUiThread(Runnable {
|
|
|
when (var1) {
|
|
|
CallEndReason.Busy -> {
|
|
|
- showMessage("对方忙线中3")
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(800) {
|
|
|
- finish()
|
|
|
- }
|
|
|
+ handOffCall()
|
|
|
}
|
|
|
CallEndReason.AcceptByOtherClient -> {
|
|
|
showMessage("通话中")
|
|
|
gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(800) {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
finish()
|
|
|
}
|
|
|
}
|
|
@@ -418,38 +444,42 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
|
|
|
CallEndReason.MediaError -> {
|
|
|
showMessage("媒体错误")
|
|
|
gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(800) {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
finish()
|
|
|
}
|
|
|
}
|
|
|
CallEndReason.OpenCameraFailure -> {
|
|
|
showMessage("打开摄像头错误")
|
|
|
gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(800) {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
finish()
|
|
|
}
|
|
|
}
|
|
|
CallEndReason.RemoteHangup -> {
|
|
|
- //showMessage("对方挂断")
|
|
|
+ showMessage("对方挂断")
|
|
|
+ gEngineKit?.endCall()
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
+ finish()
|
|
|
+ }
|
|
|
}
|
|
|
CallEndReason.RemoteSignalError -> {
|
|
|
showMessage("对方网络断开")
|
|
|
gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(800) {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
finish()
|
|
|
}
|
|
|
}
|
|
|
CallEndReason.SignalError -> {
|
|
|
showMessage("连接断开")
|
|
|
gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(800) {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
finish()
|
|
|
}
|
|
|
}
|
|
|
CallEndReason.Timeout -> {
|
|
|
showMessage("对方未接听")
|
|
|
gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(800) {
|
|
|
+ AppTool.Time.delay(200) {
|
|
|
finish()
|
|
|
}
|
|
|
}
|