|
@@ -3,7 +3,7 @@ package com.wdkl.ncs.android.component.home.activity
|
|
import android.app.Activity
|
|
import android.app.Activity
|
|
import android.bluetooth.BluetoothAdapter
|
|
import android.bluetooth.BluetoothAdapter
|
|
import android.bluetooth.BluetoothHeadset
|
|
import android.bluetooth.BluetoothHeadset
|
|
-import android.media.AudioManager
|
|
|
|
|
|
+import android.graphics.Color
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
import android.os.CountDownTimer
|
|
import android.os.CountDownTimer
|
|
import android.os.Handler
|
|
import android.os.Handler
|
|
@@ -27,7 +27,9 @@ import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
|
|
import com.wdkl.ncs.android.middleware.tcp.enums.TcpType
|
|
import com.wdkl.ncs.android.middleware.tcp.enums.TcpType
|
|
import com.wdkl.ncs.android.middleware.utils.MessageEvent
|
|
import com.wdkl.ncs.android.middleware.utils.MessageEvent
|
|
import com.wdkl.skywebrtc.CallSession
|
|
import com.wdkl.skywebrtc.CallSession
|
|
|
|
+import com.wdkl.skywebrtc.CallSession.CallSessionCallback
|
|
import com.wdkl.skywebrtc.EnumType
|
|
import com.wdkl.skywebrtc.EnumType
|
|
|
|
+import com.wdkl.skywebrtc.EnumType.CallEndReason
|
|
import com.wdkl.skywebrtc.SkyEngineKit
|
|
import com.wdkl.skywebrtc.SkyEngineKit
|
|
import com.wdkl.skywebrtc.except.NotInitializedException
|
|
import com.wdkl.skywebrtc.except.NotInitializedException
|
|
import kotlinx.android.synthetic.main.activity_sip_voip_audio.bao_mother_name_tv
|
|
import kotlinx.android.synthetic.main.activity_sip_voip_audio.bao_mother_name_tv
|
|
@@ -35,12 +37,13 @@ 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.hang_up_imagev
|
|
import kotlinx.android.synthetic.main.activity_sip_voip_audio.room_number_tv
|
|
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.activity_web_rtc_voip_audio.*
|
|
|
|
+import kotlinx.android.synthetic.main.watch_activity_home2.*
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.Subscribe
|
|
import org.greenrobot.eventbus.Subscribe
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
import java.util.*
|
|
import java.util.*
|
|
|
|
|
|
-class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
|
|
|
|
+class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCallback {
|
|
var TAG = WebRTCVoipAudioActivity::class.java.simpleName
|
|
var TAG = WebRTCVoipAudioActivity::class.java.simpleName
|
|
|
|
|
|
var ACTION = "ACTION"
|
|
var ACTION = "ACTION"
|
|
@@ -76,23 +79,12 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
DeviceChannel.calling = true
|
|
DeviceChannel.calling = true
|
|
init()
|
|
init()
|
|
|
|
|
|
- try {
|
|
|
|
- gEngineKit = SkyEngineKit.Instance()
|
|
|
|
- } catch (e: NotInitializedException) {
|
|
|
|
- SkyEngineKit.init(VoipEvent()) //重新初始化
|
|
|
|
- try {
|
|
|
|
- gEngineKit = SkyEngineKit.Instance()
|
|
|
|
- } catch (ex: NotInitializedException) {
|
|
|
|
- finish()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
targetId = intent.getStringExtra("targetId")
|
|
targetId = intent.getStringExtra("targetId")
|
|
Log.i(TAG, "SIP账号$targetId")
|
|
Log.i(TAG, "SIP账号$targetId")
|
|
tcpModel = intent.getSerializableExtra("TcpModel") as TcpModel
|
|
tcpModel = intent.getSerializableExtra("TcpModel") as TcpModel
|
|
action = intent.getStringExtra(ACTION)
|
|
action = intent.getStringExtra(ACTION)
|
|
|
|
|
|
- Log.i(TAG, "tcpModel" + tcpModel.action)
|
|
|
|
|
|
+ Log.i(TAG, "tcpModel.action " + tcpModel.action)
|
|
|
|
|
|
if (tcpModel.type == TcpType.VOICE) {
|
|
if (tcpModel.type == TcpType.VOICE) {
|
|
if (tcpModel.action === TcpAction.VoiceAction.CALL) {
|
|
if (tcpModel.action === TcpAction.VoiceAction.CALL) {
|
|
@@ -107,7 +99,6 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
}
|
|
}
|
|
|
|
|
|
if (action == CALLING) {
|
|
if (action == CALLING) {
|
|
- Log.i(TAG, "自己同意 拨打过去。。。")
|
|
|
|
createCallout()
|
|
createCallout()
|
|
|
|
|
|
call_duration_tv.visibility = View.VISIBLE
|
|
call_duration_tv.visibility = View.VISIBLE
|
|
@@ -127,6 +118,17 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
fun init() {
|
|
fun init() {
|
|
hang_up_imagev.setOnClickListener(this)
|
|
hang_up_imagev.setOnClickListener(this)
|
|
hands_free_image.setOnClickListener(this)
|
|
hands_free_image.setOnClickListener(this)
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ gEngineKit = SkyEngineKit.Instance()
|
|
|
|
+ } catch (e: NotInitializedException) {
|
|
|
|
+ SkyEngineKit.init(VoipEvent()) //重新初始化
|
|
|
|
+ try {
|
|
|
|
+ gEngineKit = SkyEngineKit.Instance()
|
|
|
|
+ } catch (ex: NotInitializedException) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
fun createCallout(){
|
|
fun createCallout(){
|
|
@@ -139,22 +141,50 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
if ((interactionVO.fromClerkId!=null && interactionVO.fromClerkId>=0) && interactionVO.fromDeviceId!=Constants.deviceId){
|
|
if ((interactionVO.fromClerkId!=null && interactionVO.fromClerkId>=0) && interactionVO.fromDeviceId!=Constants.deviceId){
|
|
Handler().postDelayed({
|
|
Handler().postDelayed({
|
|
val session = gEngineKit?.currentSession
|
|
val session = gEngineKit?.currentSession
|
|
- if (session != null)
|
|
|
|
|
|
+ if (session != null) {
|
|
|
|
+ session.setSessionCallback(this)
|
|
Log.d(TAG, "session = " + session + "; session.getState() = " + session.state)
|
|
Log.d(TAG, "session = " + session + "; session.getState() = " + session.state)
|
|
- if (session != null && session.state == EnumType.CallState.Incoming) {
|
|
|
|
- session.joinHome(session.roomId)
|
|
|
|
- setAudioDeviceOut(session)
|
|
|
|
- } else if (session != null) {
|
|
|
|
- session.sendRefuse()
|
|
|
|
|
|
+ if (session.state == EnumType.CallState.Incoming){
|
|
|
|
+ session.joinHome(session.roomId)
|
|
|
|
+ setAudioDeviceOut(session)
|
|
|
|
+ } else {
|
|
|
|
+ showMessage("对方忙线中")
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ showMessage("对方已挂断")
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},1000)
|
|
},1000)
|
|
} else {
|
|
} else {
|
|
var room = UUID.randomUUID().toString() + System.currentTimeMillis()
|
|
var room = UUID.randomUUID().toString() + System.currentTimeMillis()
|
|
Log.i(TAG, "生成的房间号room " + room + "sipid targetId" + targetId)
|
|
Log.i(TAG, "生成的房间号room " + room + "sipid targetId" + targetId)
|
|
- gEngineKit?.startOutCall(applicationContext, room, targetId, true)
|
|
|
|
|
|
+ val outCallResult = gEngineKit?.startOutCall(applicationContext, room, targetId, true)
|
|
val session = gEngineKit?.currentSession
|
|
val session = gEngineKit?.currentSession
|
|
- if (session!=null) {
|
|
|
|
- setAudioDeviceOut(session)
|
|
|
|
|
|
+ if (session == null){
|
|
|
|
+ showMessage("通话失败,请重试")
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ session.setSessionCallback(this)
|
|
|
|
+ if (outCallResult!!) {
|
|
|
|
+ setAudioDeviceOut(session)
|
|
|
|
+ } else {
|
|
|
|
+ if (session.state != EnumType.CallState.Idle) {
|
|
|
|
+ showMessage("对方忙线中")
|
|
|
|
+ } else {
|
|
|
|
+ showMessage("通话失败,请重试")
|
|
|
|
+ init()
|
|
|
|
+ }
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -170,7 +200,7 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
} else {
|
|
} else {
|
|
Handler().postDelayed({
|
|
Handler().postDelayed({
|
|
//防止建立连接的时候 不能成功切换外音
|
|
//防止建立连接的时候 不能成功切换外音
|
|
- session?.toggleSpeaker(true)
|
|
|
|
|
|
+ session.toggleSpeaker(true)
|
|
}, 3000)
|
|
}, 3000)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -184,17 +214,13 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
Log.i(TAG,"声音切换点击")
|
|
Log.i(TAG,"声音切换点击")
|
|
if (!handsFree) {
|
|
if (!handsFree) {
|
|
hands_free_image.setImageResource(R.drawable.av_handfree_hover)
|
|
hands_free_image.setImageResource(R.drawable.av_handfree_hover)
|
|
- val session = gEngineKit?.getCurrentSession()
|
|
|
|
- if (session != null) {
|
|
|
|
- session?.toggleSpeaker(true)
|
|
|
|
- }
|
|
|
|
|
|
+ val session = gEngineKit?.currentSession
|
|
|
|
+ session?.toggleSpeaker(true)
|
|
handsFree = true
|
|
handsFree = true
|
|
} else {
|
|
} else {
|
|
hands_free_image.setImageResource(R.drawable.av_handfree)
|
|
hands_free_image.setImageResource(R.drawable.av_handfree)
|
|
- val session = gEngineKit?.getCurrentSession()
|
|
|
|
- if (session != null) {
|
|
|
|
- session?.toggleSpeaker(false)
|
|
|
|
- }
|
|
|
|
|
|
+ val session = gEngineKit?.currentSession
|
|
|
|
+ session?.toggleSpeaker(false)
|
|
handsFree = false
|
|
handsFree = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -223,12 +249,9 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
|
|
TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
|
|
}
|
|
}
|
|
|
|
|
|
- //webrtc
|
|
|
|
- val session = gEngineKit?.getCurrentSession()
|
|
|
|
- if (session != null) {
|
|
|
|
- session.leave()
|
|
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
}
|
|
}
|
|
- finish()
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -256,32 +279,26 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
createCallout()
|
|
createCallout()
|
|
} else if (tcpModel.action == TcpAction.VoiceAction.HANDOFF) { //对方挂断
|
|
} else if (tcpModel.action == TcpAction.VoiceAction.HANDOFF) { //对方挂断
|
|
call_duration_tv.stop()
|
|
call_duration_tv.stop()
|
|
- val session = gEngineKit?.getCurrentSession()
|
|
|
|
- if (session != null) {
|
|
|
|
- session.leave()
|
|
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
}
|
|
}
|
|
- DeviceChannel.calling = false;
|
|
|
|
- finish()
|
|
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.REJECT) {
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.REJECT) {
|
|
//voiceStatus.setText("对方拒绝接听");
|
|
//voiceStatus.setText("对方拒绝接听");
|
|
showMessage("对方拒绝接听")
|
|
showMessage("对方拒绝接听")
|
|
- MediaPlayHelper.getInstance().stopMusic()
|
|
|
|
- DeviceChannel.calling = false;
|
|
|
|
- finish()
|
|
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.CALLING) {
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.CALLING) {
|
|
- //voiceStatus.setText("对方正在通话");
|
|
|
|
showMessage("对方正在通话")
|
|
showMessage("对方正在通话")
|
|
- DeviceChannel.calling = false;
|
|
|
|
- AppTool.Time.delay(3000) {
|
|
|
|
- MediaPlayHelper.getInstance().stopMusic()
|
|
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
finish()
|
|
finish()
|
|
}
|
|
}
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.FAILED) {
|
|
} else if (tcpModel.action === TcpAction.VoiceAction.FAILED) {
|
|
//voiceStatus.setText("对方拒绝");
|
|
//voiceStatus.setText("对方拒绝");
|
|
showMessage("呼叫失败,对方可能不在线")
|
|
showMessage("呼叫失败,对方可能不在线")
|
|
- DeviceChannel.calling = false;
|
|
|
|
- MediaPlayHelper.getInstance().stopMusic()
|
|
|
|
- finish()
|
|
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -299,16 +316,94 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
|
|
|
|
|
|
override fun onDestroy() {
|
|
override fun onDestroy() {
|
|
super.onDestroy()
|
|
super.onDestroy()
|
|
- //todo 状态设置为未在通话中
|
|
|
|
DeviceChannel.calling = false
|
|
DeviceChannel.calling = false
|
|
if(countDownTimer != null){
|
|
if(countDownTimer != null){
|
|
countDownTimer.cancel()
|
|
countDownTimer.cancel()
|
|
}
|
|
}
|
|
MediaPlayHelper.getInstance().stopMusic()
|
|
MediaPlayHelper.getInstance().stopMusic()
|
|
EventBus.getDefault().unregister(this)
|
|
EventBus.getDefault().unregister(this)
|
|
|
|
+
|
|
|
|
+ val session = gEngineKit?.currentSession
|
|
|
|
+ session?.leave()
|
|
}
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
override fun onResume() {
|
|
super.onResume()
|
|
super.onResume()
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ override fun didChangeState(var1: EnumType.CallState?) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun didDisconnected(userId: String?) {
|
|
|
|
+ runOnUiThread(Runnable {
|
|
|
|
+ showMessage("对方挂断")
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun didCreateLocalVideoTrack() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun didError(error: String?) {
|
|
|
|
+ if (error != null) {
|
|
|
|
+ Log.e(TAG, error)
|
|
|
|
+ runOnUiThread(Runnable {
|
|
|
|
+ showMessage(error)
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun didReceiveRemoteVideoTrack(userId: String?) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun didCallEndWithReason(var1: EnumType.CallEndReason?) {
|
|
|
|
+ runOnUiThread(Runnable {
|
|
|
|
+ when (var1) {
|
|
|
|
+ CallEndReason.Busy -> {
|
|
|
|
+ showMessage("忙线中")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.AcceptByOtherClient -> {
|
|
|
|
+ showMessage("通话中")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.Hangup -> {
|
|
|
|
+ //showMessage("对方挂起")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.MediaError -> {
|
|
|
|
+ showMessage("系统错误,请重试")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.OpenCameraFailure -> {
|
|
|
|
+ showMessage("打开摄像头错误")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.RemoteHangup -> {
|
|
|
|
+ showMessage("对方挂断")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.RemoteSignalError -> {
|
|
|
|
+ showMessage("对方信号出错")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.SignalError -> {
|
|
|
|
+ showMessage("信号错误")
|
|
|
|
+ }
|
|
|
|
+ CallEndReason.Timeout -> {
|
|
|
|
+ showMessage("连接超时")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ AppTool.Time.delay(800) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun didChangeMode(isAudioOnly: Boolean) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun didUserLeave(userId: String?) {
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
}
|
|
}
|