|
@@ -1,569 +0,0 @@
|
|
|
-package com.wdkl.ncs.android.component.home.activity
|
|
|
-
|
|
|
-import android.app.Activity
|
|
|
-import android.bluetooth.BluetoothAdapter
|
|
|
-import android.bluetooth.BluetoothHeadset
|
|
|
-import android.os.Bundle
|
|
|
-import android.os.CountDownTimer
|
|
|
-import android.os.Handler
|
|
|
-import android.os.SystemClock
|
|
|
-import android.util.Log
|
|
|
-import android.view.KeyEvent
|
|
|
-import android.view.View
|
|
|
-import com.google.gson.Gson
|
|
|
-import com.wdkl.core.socket.SocketManager
|
|
|
-import com.wdkl.core.voip.VoipEvent
|
|
|
-import com.wdkl.ncs.android.component.home.R
|
|
|
-import com.wdkl.ncs.android.component.home.util.HandleTcpConnect
|
|
|
-import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
|
|
|
-import com.wdkl.ncs.android.component.nursehome.common.Constants
|
|
|
-import com.wdkl.ncs.android.lib.utils.AppTool
|
|
|
-import com.wdkl.ncs.android.lib.utils.showMessage
|
|
|
-import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
|
|
|
-import com.wdkl.ncs.android.middleware.tcp.NettyClient
|
|
|
-import com.wdkl.ncs.android.middleware.tcp.channel.DeviceChannel
|
|
|
-import com.wdkl.ncs.android.middleware.tcp.channel.VoiceUtil
|
|
|
-import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
|
|
|
-import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
|
|
|
-import com.wdkl.ncs.android.middleware.tcp.enums.TcpType
|
|
|
-import com.wdkl.ncs.android.middleware.utils.MessageEvent
|
|
|
-import com.wdkl.skywebrtc.CallSession
|
|
|
-import com.wdkl.skywebrtc.CallSession.CallSessionCallback
|
|
|
-import com.wdkl.skywebrtc.EnumType
|
|
|
-import com.wdkl.skywebrtc.EnumType.CallEndReason
|
|
|
-import com.wdkl.skywebrtc.SkyEngineKit
|
|
|
-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.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 org.greenrobot.eventbus.EventBus
|
|
|
-import org.greenrobot.eventbus.Subscribe
|
|
|
-import org.greenrobot.eventbus.ThreadMode
|
|
|
-import java.util.*
|
|
|
-
|
|
|
-class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCallback {
|
|
|
- var TAG = WebRTCVoipAudioActivity::class.java.simpleName
|
|
|
-
|
|
|
- var ACTION = "ACTION"
|
|
|
- var RING = "RING"
|
|
|
- var CALLING = "CALLING"
|
|
|
- var CALL = "CALL"
|
|
|
- private var action: String? = null
|
|
|
- private var targetId: String? = null
|
|
|
- var tcpModel = TcpModel()
|
|
|
-
|
|
|
- private var gEngineKit: SkyEngineKit? = null
|
|
|
- private var handsFree:Boolean = true //免提状态
|
|
|
-
|
|
|
- private var CALL_TIMEOUT = 2 //多久可以再次点击
|
|
|
- //呼叫倒计时
|
|
|
- lateinit var countDownTimer: CountDownTimer
|
|
|
- private var isClick = true //是否可点击
|
|
|
- private var createEnabled = true
|
|
|
- private var tcpHandOff = false
|
|
|
-
|
|
|
- override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
- super.onCreate(savedInstanceState)
|
|
|
-// window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
|
-// WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
|
|
- setContentView(R.layout.activity_web_rtc_voip_audio)
|
|
|
- if (!EventBus.getDefault().isRegistered(this)) {
|
|
|
- EventBus.getDefault().register(this)
|
|
|
- }
|
|
|
- MediaPlayHelper.getInstance().stopMusic()
|
|
|
- initCountDownTimer()
|
|
|
- countDownTimer.start()
|
|
|
-
|
|
|
- //设置为通话状态 有其他用户输入时 DeviceChannel设置返回通话中
|
|
|
- DeviceChannel.calling = true
|
|
|
- init()
|
|
|
-
|
|
|
- targetId = intent.getStringExtra("targetId")
|
|
|
- Log.i(TAG, "SIP账号$targetId")
|
|
|
- tcpModel = intent.getSerializableExtra("TcpModel") as TcpModel
|
|
|
- action = intent.getStringExtra(ACTION)
|
|
|
-
|
|
|
- Log.i(TAG, "tcpModel " + tcpModel.toJson())
|
|
|
-
|
|
|
- if (tcpModel.type == TcpType.VOICE) {
|
|
|
- if (tcpModel.action === TcpAction.VoiceAction.CALL) {
|
|
|
- val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- room_number_tv.text = interactionVO.fromFrameFullName
|
|
|
- bao_mother_name_tv.setText(interactionVO.fromMemberName)
|
|
|
-
|
|
|
- DeviceChannel.callId = if (interactionVO.fromDeviceId.equals(Constants.deviceId)) interactionVO.toDeviceId else interactionVO.fromDeviceId
|
|
|
- } else if (tcpModel.action === TcpAction.VoiceAction.SUCCESS) {
|
|
|
- val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- room_number_tv.text = interactionVO.toFrameFullName
|
|
|
- bao_mother_name_tv.setText(interactionVO.toMemberName)
|
|
|
-
|
|
|
- DeviceChannel.callId = if (interactionVO.fromDeviceId.equals(Constants.deviceId)) interactionVO.toDeviceId else interactionVO.fromDeviceId
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (action == CALLING) {
|
|
|
- AppTool.Time.delay(500) {
|
|
|
- createCallout()
|
|
|
- }
|
|
|
-
|
|
|
- call_duration_tv.visibility = View.VISIBLE
|
|
|
- call_duration_tv.text = "连接中...."
|
|
|
-
|
|
|
- } else if (action == RING) {
|
|
|
- Log.i(TAG, "接电话。。。")
|
|
|
- } else if (action == CALL) { //主动拨出,服务端回复success时
|
|
|
- call_duration_tv.text = "等待接听"
|
|
|
- MediaPlayHelper.getInstance().playResMusic(R.raw.outgoing_call, 0.6f, true)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fun init() {
|
|
|
- hang_up_imagev.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(){
|
|
|
- Handler().postDelayed({
|
|
|
- call_duration_tv.base = SystemClock.elapsedRealtime()
|
|
|
- call_duration_tv.start()
|
|
|
- }, 2900)
|
|
|
-
|
|
|
- val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- if ((interactionVO.fromClerkId!=null && interactionVO.fromClerkId>=0) && interactionVO.fromDeviceId!=Constants.deviceId){
|
|
|
- //6秒后仍然未连接,则断开
|
|
|
-// Handler().postDelayed({
|
|
|
-// Log.i(TAG,"session state:"+gEngineKit?.currentSession?.state+",userState:"+ SocketManager.getInstance().userState)
|
|
|
-// if (gEngineKit?.currentSession?.state != EnumType.CallState.Connected){
|
|
|
-// showMessage("连接失败,请重试")
|
|
|
-// finish()
|
|
|
-// }
|
|
|
-// },6000)
|
|
|
- } else {
|
|
|
- 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!!||session.state == EnumType.CallState.Connected || session.state == EnumType.CallState.Connecting) {
|
|
|
- setAudioDeviceOut(session)
|
|
|
-
|
|
|
- Thread(Runnable {
|
|
|
- Thread.sleep(6000)
|
|
|
- Log.i(TAG,"session state:"+gEngineKit?.currentSession?.state+",userState:"+ SocketManager.getInstance().userState)
|
|
|
- if (gEngineKit?.currentSession?.state != EnumType.CallState.Connected && !tcpHandOff){
|
|
|
- runOnUiThread {
|
|
|
- showMessage("连接失败,请重试")
|
|
|
- }
|
|
|
-
|
|
|
- gEngineKit?.endCall()
|
|
|
- val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- var toId = if (interactionVO.fromDeviceId.equals(Constants.deviceId)) interactionVO.toDeviceId else interactionVO.fromDeviceId
|
|
|
- val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Constants.deviceId, toId, interactionVO.id)
|
|
|
- NettyClient.instance.sendMsg(voiceUtilTcpModel.toJson()).subscribe {
|
|
|
- if (it) {
|
|
|
- Log.d(TAG, "TCP.发送消息完成")
|
|
|
- } else {
|
|
|
- Log.e(TAG, "TCP.发送消息失败")
|
|
|
-
|
|
|
- HandleTcpConnect.instance.tcpReConnectWithMsgShow()
|
|
|
- }
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- }).start()
|
|
|
-
|
|
|
- } else {
|
|
|
- if (session.state != EnumType.CallState.Idle) {
|
|
|
- showMessage("对方忙线中2")
|
|
|
- } else {
|
|
|
- showMessage("通话失败,请重试")
|
|
|
- }
|
|
|
- AppTool.Time.delay(800) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fun setAudioDeviceOut(session:CallSession){
|
|
|
- val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
|
|
|
- val isBluetoothHeadsetConnected = (bluetoothAdapter != null && bluetoothAdapter.isEnabled
|
|
|
- && bluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED)
|
|
|
- if (session.isHeadphonesPlugged){
|
|
|
- session.toggleHeadset(true)
|
|
|
- } else if (isBluetoothHeadsetConnected){
|
|
|
- session.toggleBluetooth()
|
|
|
- } else {
|
|
|
- Handler().postDelayed({
|
|
|
- //防止建立连接的时候 不能成功切换外音
|
|
|
- session.toggleSpeaker(true)
|
|
|
- }, 2400)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onClick(p0: View?) {
|
|
|
- when (p0?.id) {
|
|
|
- R.id.hang_up_imagev -> {
|
|
|
- countDownTimer.start()
|
|
|
- handOffCall()
|
|
|
- }
|
|
|
- R.id.hands_free_image -> {
|
|
|
- Log.i(TAG,"声音切换点击")
|
|
|
- if (!handsFree) {
|
|
|
- hands_free_image.setImageResource(R.drawable.av_handfree_hover)
|
|
|
- val session = gEngineKit?.currentSession
|
|
|
- session?.toggleSpeaker(true)
|
|
|
- handsFree = true
|
|
|
- } else {
|
|
|
- hands_free_image.setImageResource(R.drawable.av_handfree)
|
|
|
- val session = gEngineKit?.currentSession
|
|
|
- session?.toggleSpeaker(false)
|
|
|
- handsFree = false
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fun handOffCall(){
|
|
|
- if(!isClick) {
|
|
|
- showMessage("勿频繁点击,2秒后可用")
|
|
|
- return
|
|
|
- }
|
|
|
- hang_up_imagev.isEnabled = false
|
|
|
- isClick = false
|
|
|
-
|
|
|
- var interactionVO: InteractionVO? = null
|
|
|
- if (tcpModel.data.javaClass.name == String::class.java.name) {
|
|
|
- interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- } else {
|
|
|
- interactionVO = tcpModel.data as InteractionVO
|
|
|
- }
|
|
|
- Log.i(TAG, "tcpModel" + interactionVO!!.id!!)
|
|
|
- Log.i(TAG, "tcpModel" + tcpModel.toJson())
|
|
|
-
|
|
|
- //给服务器发送挂断 tcp
|
|
|
- if (tcpModel.type == TcpType.VOICE) {
|
|
|
- if (tcpModel.action === TcpAction.VoiceAction.SUCCESS) {
|
|
|
- var toId = if (interactionVO.fromDeviceId.equals(Constants.deviceId)) interactionVO.toDeviceId else interactionVO.fromDeviceId
|
|
|
- val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Constants.deviceId, toId, interactionVO.id)
|
|
|
- NettyClient.instance.sendMsg(voiceUtilTcpModel.toJson()).subscribe {
|
|
|
- if (it) {
|
|
|
- Log.d(TAG, "TCP.发送消息完成")
|
|
|
- } else {
|
|
|
- Log.e(TAG, "TCP.发送消息失败")
|
|
|
- HandleTcpConnect.instance.tcpReConnectWithMsgShow()
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (tcpModel.action === TcpAction.VoiceAction.CALL) {
|
|
|
- var toId = if (interactionVO.fromDeviceId.equals(Constants.deviceId)) interactionVO.toDeviceId else interactionVO.fromDeviceId
|
|
|
- val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Constants.deviceId, toId, interactionVO.id)
|
|
|
- NettyClient.instance.sendMsg(voiceUtilTcpModel.toJson()).subscribe {
|
|
|
- if (it) {
|
|
|
- Log.d(TAG, "TCP.发送消息完成")
|
|
|
- } else {
|
|
|
- Log.e(TAG, "TCP.发送消息失败")
|
|
|
- HandleTcpConnect.instance.tcpReConnectWithMsgShow()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- tcpHandOff = true
|
|
|
- gEngineKit?.endCall()
|
|
|
- finish()
|
|
|
- }
|
|
|
-
|
|
|
- fun initCountDownTimer() {
|
|
|
- countDownTimer = object : CountDownTimer(CALL_TIMEOUT * 1000L, 1000) {
|
|
|
- override fun onTick(millisUntilFinished: Long) {
|
|
|
- }
|
|
|
- override fun onFinish() {
|
|
|
- hang_up_imagev.isEnabled = true
|
|
|
- isClick = true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
- fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
- if (messageEvent.tag == 2) {
|
|
|
-
|
|
|
- val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
- Log.i(TAG, "收到数据 " + tcpModel.toJson())
|
|
|
- if (tcpModel.action === TcpAction.VoiceAction.ACCEPT) {
|
|
|
- MediaPlayHelper.getInstance().stopMusic()
|
|
|
- Log.i(TAG, "对方接听电话啦")
|
|
|
- call_duration_tv.visibility = View.VISIBLE
|
|
|
- call_duration_tv.text = "连接中...."
|
|
|
- AppTool.Time.delay(600) {
|
|
|
- createCallout()
|
|
|
- }
|
|
|
- } else if (tcpModel.action == TcpAction.VoiceAction.HANDOFF) { //对方挂断
|
|
|
-
|
|
|
- var interactionVO: InteractionVO? = null
|
|
|
- if (tcpModel.data.javaClass.name == String::class.java.name) {
|
|
|
- interactionVO = Gson().fromJson(this.tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- } else {
|
|
|
- interactionVO = this.tcpModel.data as InteractionVO
|
|
|
- }
|
|
|
- val currentTnVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- if (interactionVO!!.id == currentTnVO.id){
|
|
|
-
|
|
|
- if (tcpModel.fromId != Constants.deviceId) {
|
|
|
- showMessage("对方挂断")
|
|
|
- call_duration_tv.stop()
|
|
|
- createEnabled = false
|
|
|
- tcpHandOff = true
|
|
|
- gEngineKit?.endCall()
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (tcpModel.action === TcpAction.VoiceAction.REJECT) {
|
|
|
- var interactionVO: InteractionVO? = null
|
|
|
- if (tcpModel.data.javaClass.name == String::class.java.name) {
|
|
|
- interactionVO = Gson().fromJson(this.tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- } else {
|
|
|
- interactionVO = this.tcpModel.data as InteractionVO
|
|
|
- }
|
|
|
- val currentTnVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- if (interactionVO!!.id == currentTnVO.id){
|
|
|
- showMessage("对方拒绝接听")
|
|
|
- createEnabled = false
|
|
|
- tcpHandOff = true
|
|
|
- gEngineKit?.endCall()
|
|
|
- finish()
|
|
|
- }
|
|
|
-
|
|
|
- } else if (tcpModel.action === TcpAction.VoiceAction.CALLING) {
|
|
|
- createEnabled = false
|
|
|
- tcpHandOff = true
|
|
|
- //gEngineKit?.endCall()
|
|
|
- //showMessage("对方正在通话")
|
|
|
- AppTool.Time.delay(800) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- } else if (tcpModel.action === TcpAction.VoiceAction.FAILED) {
|
|
|
- gEngineKit?.endCall()
|
|
|
- //voiceStatus.setText("对方拒绝");
|
|
|
- showMessage("呼叫失败,对方可能不在线")
|
|
|
- createEnabled = false
|
|
|
- tcpHandOff = true
|
|
|
- AppTool.Time.delay(800) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- } else if (tcpModel.action === TcpAction.VoiceAction.CANCEL) {
|
|
|
- showMessage("对方取消")
|
|
|
- createEnabled = false
|
|
|
- tcpHandOff = true
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(400) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(messageEvent.tag==Constants.INCOME_CALL_READY){ //已准备好接听电话,加入房间
|
|
|
-
|
|
|
- val session = gEngineKit?.currentSession
|
|
|
- if (session != null) {
|
|
|
- session.setSessionCallback(this)
|
|
|
- Log.d(TAG, "session = " + session + "; session.getState() = " + session.state)
|
|
|
- if (session.state == EnumType.CallState.Incoming || session.state == EnumType.CallState.Connected || session.state == EnumType.CallState.Connecting){
|
|
|
- session.joinHome(session.roomId)
|
|
|
- setAudioDeviceOut(session)
|
|
|
- } else {
|
|
|
- showMessage("对方忙线中")
|
|
|
- AppTool.Time.delay(800) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- showMessage("对方已挂断")
|
|
|
- AppTool.Time.delay(800) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
|
|
- Log.i(TAG, "keyup keyCode " + keyCode)
|
|
|
- if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK){
|
|
|
- handOffCall()
|
|
|
- } else if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
-// Toast.makeText(this, "按下了back键 onKeyDown()", Toast.LENGTH_SHORT).show()
|
|
|
- return false
|
|
|
- }
|
|
|
- return super.onKeyDown(keyCode, event)
|
|
|
- }
|
|
|
-
|
|
|
- override fun onDestroy() {
|
|
|
- super.onDestroy()
|
|
|
- DeviceChannel.calling = false
|
|
|
- DeviceChannel.callId = 0
|
|
|
- if(countDownTimer != null){
|
|
|
- countDownTimer.cancel()
|
|
|
- }
|
|
|
- MediaPlayHelper.getInstance().stopMusic()
|
|
|
- EventBus.getDefault().unregister(this)
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- override fun finish() {
|
|
|
- Log.i("_sfinish","gEngineKit?.currentSession?.state="+gEngineKit?.currentSession?.state)
|
|
|
-
|
|
|
- //val session = gEngineKit?.getCurrentSession()
|
|
|
-
|
|
|
- //Log.e("结束通话",""+session?.roomId)
|
|
|
-// if (session != null) {
|
|
|
-// session?.setCallState(EnumType.CallState.Idle)
|
|
|
-// gEngineKit?.endCall()
|
|
|
-// }
|
|
|
-
|
|
|
- super.finish()
|
|
|
- }
|
|
|
-
|
|
|
- override fun onResume() {
|
|
|
- super.onResume()
|
|
|
- }
|
|
|
-
|
|
|
- override fun didChangeState(var1: EnumType.CallState?) {
|
|
|
- Log.d(TAG + "_peer","didChangeState EnumType.CallState=" + var1?.name)
|
|
|
- }
|
|
|
-
|
|
|
- override fun didDisconnected(userId: String?) {
|
|
|
- //val session = gEngineKit?.currentSession
|
|
|
- //Log.i(TAG+"_peer","userId : $userId <> myId = ${session?.mMyId} , targetId = ${session?.mTargetId}, roomId = ${session?.roomId}, state = ${session?.state}")
|
|
|
- Log.d(TAG + "_peer","didDisconnected userId=" + userId)
|
|
|
- gEngineKit?.endCall()
|
|
|
- runOnUiThread(Runnable {
|
|
|
- //showMessage("对方挂断")
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- override fun didCreateLocalVideoTrack() {
|
|
|
- }
|
|
|
-
|
|
|
- override fun didError(error: String?) {
|
|
|
- Log.d(TAG + "_peer","didError error=" + error)
|
|
|
- gEngineKit?.endCall()
|
|
|
- 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?) {
|
|
|
- Log.d(TAG + "_peer","didCallEndWithReason EnumType.CallEndReason=" + var1?.name)
|
|
|
-
|
|
|
- runOnUiThread(Runnable {
|
|
|
- when (var1) {
|
|
|
- CallEndReason.Busy -> {
|
|
|
- handOffCall()
|
|
|
- }
|
|
|
- CallEndReason.AcceptByOtherClient -> {
|
|
|
- showMessage("通话中")
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- CallEndReason.Hangup -> {
|
|
|
- //showMessage("挂断")
|
|
|
- }
|
|
|
- CallEndReason.MediaError -> {
|
|
|
- showMessage("媒体错误")
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- CallEndReason.OpenCameraFailure -> {
|
|
|
- showMessage("打开摄像头错误")
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- CallEndReason.RemoteHangup -> {
|
|
|
-// showMessage("对方挂断")
|
|
|
-// gEngineKit?.endCall()
|
|
|
-// AppTool.Time.delay(200) {
|
|
|
-// finish()
|
|
|
-// }
|
|
|
- }
|
|
|
- CallEndReason.RemoteSignalError -> {
|
|
|
- showMessage("对方网络断开")
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- CallEndReason.SignalError -> {
|
|
|
- showMessage("连接断开")
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- CallEndReason.Timeout -> {
|
|
|
- showMessage("对方未接听")
|
|
|
- gEngineKit?.endCall()
|
|
|
- AppTool.Time.delay(200) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- override fun didChangeMode(isAudioOnly: Boolean) {
|
|
|
- }
|
|
|
-
|
|
|
- override fun didUserLeave(userId: String?) {
|
|
|
- Log.d(TAG + "_peer","didUserLeave userId=" + userId)
|
|
|
- gEngineKit?.endCall()
|
|
|
- runOnUiThread {
|
|
|
- showMessage("用户 $userId 离开")
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|