|
@@ -0,0 +1,514 @@
|
|
|
|
+package com.wdkl.app.ncs.callingdoor.fragment
|
|
|
|
+
|
|
|
|
+import android.os.Build
|
|
|
|
+import android.os.Handler
|
|
|
|
+import android.os.Looper
|
|
|
|
+import android.os.SystemClock
|
|
|
|
+import android.text.TextUtils
|
|
|
|
+import android.util.Log
|
|
|
|
+import android.view.View
|
|
|
|
+import android.widget.SeekBar
|
|
|
|
+import com.alibaba.fastjson.JSONObject
|
|
|
|
+import com.google.gson.Gson
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.R
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.activity.CallingdoorActivity
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.helper.DoorLightHelper
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.helper.RingPlayHelper
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.helper.VoiceManagerUtil
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.settings.SettingConfig
|
|
|
|
+import com.wdkl.ncs.android.lib.utils.AppTool
|
|
|
|
+import com.wdkl.ncs.android.lib.utils.showMessage
|
|
|
|
+import com.wdkl.ncs.android.middleware.common.Constant
|
|
|
|
+import com.wdkl.ncs.android.middleware.common.MessageEvent
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.TcpClient
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.channel.VoiceUtil
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.dto.TcpCallback
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.enums.DeviceTypeEnum
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.enums.RoleTypeEnum
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.enums.TcpType
|
|
|
|
+import com.wdkl.ncs.host.service.WdklSipService
|
|
|
|
+import com.wdkl.ncs.host.util.AudioRouteUtils
|
|
|
|
+import com.wdkl.ncs.janus.entity.Room
|
|
|
|
+import com.wdkl.ncs.janus.util.EnumType
|
|
|
|
+import kotlinx.android.synthetic.main.sky_voice_call_layout.*
|
|
|
|
+import org.greenrobot.eventbus.Subscribe
|
|
|
|
+import org.greenrobot.eventbus.ThreadMode
|
|
|
|
+import org.linphone.core.Core
|
|
|
|
+
|
|
|
|
+class SipCallFragment: BaseCallFragment() {
|
|
|
|
+ private val TAG = "SipCallFragment"
|
|
|
|
+
|
|
|
|
+ //来电设备id
|
|
|
|
+ var fromId: Int = -1
|
|
|
|
+ private var interactionVO: InteractionVO? = null
|
|
|
|
+
|
|
|
|
+ private var callEnded: Boolean = false
|
|
|
|
+ private var outGoing: Boolean = false
|
|
|
|
+ private var audioCall: Boolean = true
|
|
|
|
+ private var callSuccess: Boolean = false
|
|
|
|
+
|
|
|
|
+ private var sipCore: Core? = null
|
|
|
|
+ private var volume = 60
|
|
|
|
+
|
|
|
|
+ private val handler = Handler(Looper.getMainLooper())
|
|
|
|
+
|
|
|
|
+ override fun getLayId(): Int {
|
|
|
|
+ if ("rk3288".equals(Build.MODEL)) {
|
|
|
|
+ return R.layout.sky_voice_call_layout_rk3288
|
|
|
|
+ } else {
|
|
|
|
+ return R.layout.sky_voice_call_layout
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun init() {
|
|
|
|
+ //初始化计时器
|
|
|
|
+ initCountDownTimer(sky_voice_call_timeout)
|
|
|
|
+
|
|
|
|
+ sipCore = WdklSipService.getCore()
|
|
|
|
+
|
|
|
|
+ /*volume = SettingConfig.getExtensionCallVolume(activity)
|
|
|
|
+ if (volume < 0 || volume > 100) {
|
|
|
|
+ volume = 60
|
|
|
|
+ }
|
|
|
|
+ call_volume_bar.progress = volume/10
|
|
|
|
+ tv_volume.text = "" + volume/10
|
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, volume)*/
|
|
|
|
+
|
|
|
|
+ //tcp参数
|
|
|
|
+ if (tcpModel != null) {
|
|
|
|
+ fromId = tcpModel!!.fromId
|
|
|
|
+ interactionVO = Gson().fromJson(tcpModel!!.data.toString(), InteractionVO::class.java)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Log.e(TAG, "udpPort: ${sipCore!!.transports.udpPort}, tcpPort: ${sipCore!!.transports.tcpPort}")
|
|
|
|
+ //Log.d(TAG, "callState: $callState, local sip: ${Constants.sip_id}, target sip: ${Constants.targetSipId}")
|
|
|
|
+ when (callState) {
|
|
|
|
+ 0 -> {
|
|
|
|
+ //去电
|
|
|
|
+ outGoing = true
|
|
|
|
+ startOutgoing()
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_OUTGOING
|
|
|
|
+ RingPlayHelper.playRingTone(baseActivity, R.raw.ring_back2, true)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 1 -> {
|
|
|
|
+ //来电
|
|
|
|
+ outGoing = false
|
|
|
|
+ showIncomingCall()
|
|
|
|
+ RingPlayHelper.playRingTone(baseActivity, R.raw.ring_tone, true)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 2 -> {
|
|
|
|
+ //呼叫分机
|
|
|
|
+ outGoing = true
|
|
|
|
+ startOutgoing()
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_OUTGOING
|
|
|
|
+ RingPlayHelper.playRingTone(baseActivity, R.raw.ring_back2, true)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun bindEvent() {
|
|
|
|
+ //通话挂断
|
|
|
|
+ sky_voice_call_hangup.setOnClickListener {
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
|
+ if (Constant.CALL_STATE == Constant.CALL_CALLING) {
|
|
|
|
+ //结束通话
|
|
|
|
+ if (sky_voice_call_timer != null) {
|
|
|
|
+ sky_voice_call_timer.stop()
|
|
|
|
+ }
|
|
|
|
+ callEnd(true)
|
|
|
|
+ } else {
|
|
|
|
+ if (callState == 0) {
|
|
|
|
+ voiceCancel()
|
|
|
|
+ } else if (callState == 2) {
|
|
|
|
+ if (bedId != -1) {
|
|
|
|
+ voiceCancelBed()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cancelCall()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //来电拒绝
|
|
|
|
+ sky_voice_call_ring_reject.setOnClickListener {
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
|
+ voiceReject()
|
|
|
|
+ callEnd(false)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //来电接听
|
|
|
|
+ sky_voice_call_ring_pickup_audio.setOnClickListener {
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_INCOMING
|
|
|
|
+ voiceAccept()
|
|
|
|
+ acceptCall()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*sky_voice_call_mute.setOnClickListener {
|
|
|
|
+ val micEnable = sipCore!!.isMicEnabled
|
|
|
|
+ Log.d(TAG,"mic enable: $micEnable")
|
|
|
|
+
|
|
|
|
+ if (micEnable) {
|
|
|
|
+ sipCore!!.isMicEnabled = false
|
|
|
|
+ sky_voice_call_mute.isSelected = true
|
|
|
|
+ } else {
|
|
|
|
+ sipCore!!.isMicEnabled = true
|
|
|
|
+ sky_voice_call_mute.isSelected = false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ call_volume_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{
|
|
|
|
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
+ tv_volume.text = "" + progress
|
|
|
|
+ if (seekBar!!.progress <= 1) {
|
|
|
|
+ tv_volume.text = "1"
|
|
|
|
+ } else {
|
|
|
|
+ tv_volume.text = "" + progress
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStartTrackingTouch(seekBar: SeekBar?) {
|
|
|
|
+ //
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStopTrackingTouch(seekBar: SeekBar?) {
|
|
|
|
+ if (seekBar!!.progress <= 2) {
|
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, 20)
|
|
|
|
+ } else {
|
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, seekBar.progress*10)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })*/
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun callTerminate() {
|
|
|
|
+ if (sipCore != null && sipCore!!.callsNb > 0) {
|
|
|
|
+ var call = sipCore!!.currentCall
|
|
|
|
+ if (call == null) {
|
|
|
|
+ call = sipCore!!.calls[0]
|
|
|
|
+ }
|
|
|
|
+ call!!.terminate()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun destroy() {
|
|
|
|
+ cancelTimer()
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
|
+ if (sky_voice_call_timer != null) {
|
|
|
|
+ sky_voice_call_timer.stop()
|
|
|
|
+ }
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ handler.removeCallbacksAndMessages(null)
|
|
|
|
+
|
|
|
|
+ //如果当前在护理中则不操作门灯,如果不在护理中则重置门灯
|
|
|
|
+ if (("rk3128".equals(Build.MODEL) || "rk3368".equals(Build.MODEL)) && !Constant.inNursing && !Constant.sosOn) {
|
|
|
|
+ //SerialPortHelper.setDoorLight(1, "111") //白色
|
|
|
|
+ if (SettingConfig.getDoorLightAlwaysOn(activity) == 0) {
|
|
|
|
+ DoorLightHelper.resetDoorLight()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun voiceAccept() {
|
|
|
|
+ val callTcp = VoiceUtil.voiceAccept(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
|
+ val transaction = object : TcpCallback(callTcp.tid) {
|
|
|
|
+ override fun onSuccess(jsonObject: JSONObject) {
|
|
|
|
+ //
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onFailed(jsonObject: JSONObject) {
|
|
|
|
+ // 这里写发送失败的方法
|
|
|
|
+ val callbackString = jsonObject.getString(CALLBACK)
|
|
|
|
+ handler.post {
|
|
|
|
+ showMessage("accept fail: $callbackString")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ TcpClient.getInstance().sendTcp(callTcp, false, transaction)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun voiceReject() {
|
|
|
|
+ val callTcp = VoiceUtil.voiceReject(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun startOutgoing() {
|
|
|
|
+ if (callState == 0) {
|
|
|
|
+ val outCallTcp = VoiceUtil.voiceCall(Constant.DEVICE_ID, RoleTypeEnum.NURSE.name)
|
|
|
|
+
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_OUTGOING
|
|
|
|
+ sky_voice_call_outgoing.visibility = View.VISIBLE
|
|
|
|
+ sky_voice_call_incoming.visibility = View.GONE
|
|
|
|
+ sky_voice_call_timeout.visibility = View.VISIBLE
|
|
|
|
+ sky_voice_call_timer.visibility = View.GONE
|
|
|
|
+ startTimer()
|
|
|
|
+
|
|
|
|
+ val transaction: TcpCallback = object : TcpCallback(outCallTcp!!.tid) {
|
|
|
|
+ override fun onSuccess(jsonObject: JSONObject) {
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_OUTGOING
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onFailed(jsonObject: JSONObject) {
|
|
|
|
+ // 这里写发送失败的方法
|
|
|
|
+ val callbackString = jsonObject.getString(CALLBACK)
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+
|
|
|
|
+ handler.post {
|
|
|
|
+ cancelCall()
|
|
|
|
+ showMessage("outgoing call failed: $callbackString")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ TcpClient.getInstance().sendTcp(outCallTcp, false, transaction)
|
|
|
|
+ } else if (callState == 2) {
|
|
|
|
+ if (bedId != -1) {
|
|
|
|
+ val outCallTcp = VoiceUtil.voiceCallBed(Constant.DEVICE_ID, bedId)
|
|
|
|
+
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_OUTGOING
|
|
|
|
+ sky_voice_call_outgoing.visibility = View.VISIBLE
|
|
|
|
+ sky_voice_call_incoming.visibility = View.GONE
|
|
|
|
+ sky_voice_call_timeout.visibility = View.VISIBLE
|
|
|
|
+ sky_voice_call_timer.visibility = View.GONE
|
|
|
|
+ startTimer()
|
|
|
|
+
|
|
|
|
+ val transaction: TcpCallback = object : TcpCallback(outCallTcp!!.tid) {
|
|
|
|
+ override fun onSuccess(jsonObject: JSONObject) {
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_OUTGOING
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onFailed(jsonObject: JSONObject) {
|
|
|
|
+ // 这里写发送失败的方法
|
|
|
|
+ val callbackString = jsonObject.getString(CALLBACK)
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+
|
|
|
|
+ handler.post {
|
|
|
|
+ cancelCall()
|
|
|
|
+ showMessage("outgoing call failed: $callbackString")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ TcpClient.getInstance().sendTcp(outCallTcp, false, transaction)
|
|
|
|
+ } else {
|
|
|
|
+ showMessage("bed_id null")
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //去电界面
|
|
|
|
+ private fun showOutgoingCall() {
|
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_success)
|
|
|
|
+
|
|
|
|
+ if (!audioCall) {
|
|
|
|
+ //显示视频画面
|
|
|
|
+ fullscreen_video_frame.visibility = View.VISIBLE
|
|
|
|
+ pip_video_frame.visibility = View.VISIBLE
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //来电界面
|
|
|
|
+ private fun showIncomingCall() {
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_INCOMING
|
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_incoming)
|
|
|
|
+ sky_voice_call_outgoing.visibility = View.GONE
|
|
|
|
+ sky_voice_call_incoming.visibility = View.VISIBLE
|
|
|
|
+ sky_voice_call_timeout.visibility = View.GONE
|
|
|
|
+ sky_voice_call_timer.visibility = View.GONE
|
|
|
|
+ cancelTimer()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //开始接听
|
|
|
|
+ private fun acceptCall() {
|
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_connecting)
|
|
|
|
+ sky_voice_call_outgoing.visibility = View.VISIBLE
|
|
|
|
+ sky_voice_call_incoming.visibility = View.GONE
|
|
|
|
+ sky_voice_call_timeout.visibility = View.GONE
|
|
|
|
+ sky_voice_call_timer.visibility = View.GONE
|
|
|
|
+ cancelTimer()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //呼叫取消
|
|
|
|
+ private fun cancelCall() {
|
|
|
|
+ cancelTimer()
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
|
+ if (sky_voice_call_timer != null) {
|
|
|
|
+ sky_voice_call_timer.stop()
|
|
|
|
+ }
|
|
|
|
+ callEnd(false)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun showCalling(audioOnly: Boolean) {
|
|
|
|
+ if (callEnded) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (audioOnly) {
|
|
|
|
+ ll_voice_call.visibility = View.VISIBLE
|
|
|
|
+ } else {
|
|
|
|
+ //显示视频画面
|
|
|
|
+ fullscreen_video_frame.visibility = View.VISIBLE
|
|
|
|
+ pip_video_frame.visibility = View.VISIBLE
|
|
|
|
+ ll_voice_call.visibility = View.GONE
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_CALLING
|
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_in_call)
|
|
|
|
+ sky_voice_call_timeout.visibility = View.GONE
|
|
|
|
+ cancelTimer()
|
|
|
|
+ sky_voice_call_timer.visibility = View.VISIBLE
|
|
|
|
+ sky_voice_call_timer.base = SystemClock.elapsedRealtime()
|
|
|
|
+ sky_voice_call_timer.start()
|
|
|
|
+ //sky_voice_call_mute.visibility = View.VISIBLE
|
|
|
|
+ //ll_voice_volume_bar.visibility = View.VISIBLE
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //通话结束
|
|
|
|
+ override fun callEnd(handoff: Boolean) {
|
|
|
|
+ Log.e(TAG, ">>>>>>>>>>> call end !!!!!!!!!!!!!!!!!!")
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ countDownTimer.cancel()
|
|
|
|
+
|
|
|
|
+ synchronized(this) {
|
|
|
|
+ if (callEnded) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ callEnded = true
|
|
|
|
+
|
|
|
|
+ if (sky_voice_call_timer != null) {
|
|
|
|
+ sky_voice_call_timer.stop()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ callTerminate()
|
|
|
|
+
|
|
|
|
+ if (handoff) {
|
|
|
|
+ val callTcp = VoiceUtil.voiceHandoff(tid, Constant.DEVICE_ID, fromId, Constant.interactionId)
|
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
|
+ Constant.interactionId = null
|
|
|
|
+
|
|
|
|
+ backToMain()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun toggleSpeaker(enable: Boolean) {
|
|
|
|
+ Log.d(TAG, "toggle speaker: $enable, sipCore: $sipCore")
|
|
|
|
+ if ( sipCore == null) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (enable) {
|
|
|
|
+ AudioRouteUtils.routeAudioToSpeaker(sipCore!!)
|
|
|
|
+ } else {
|
|
|
|
+ AudioRouteUtils.routeAudioToEarpiece(sipCore!!)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
+ fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
|
+ when (messageEvent.getType()) {
|
|
|
|
+ Constant.EVENT_TCP_MSG -> {
|
|
|
|
+ if (messageEvent.message is TcpModel) {
|
|
|
|
+ val curTcpModel = messageEvent.message as TcpModel
|
|
|
|
+ if (curTcpModel.type == TcpType.VOICE) {
|
|
|
|
+ if (curTcpModel.data != null) {
|
|
|
|
+ val curInteractionVO = Gson().fromJson(curTcpModel.data.toString(), InteractionVO::class.java)
|
|
|
|
+ if (curTcpModel.getAction() == TcpAction.VoiceAction.ACCEPT) {
|
|
|
|
+ //我方呼出,对方接受
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ Constant.interactionId = curInteractionVO.id
|
|
|
|
+ fromId = curTcpModel.fromId
|
|
|
|
+ acceptCall()
|
|
|
|
+
|
|
|
|
+ if (sipCore == null || TextUtils.isEmpty(curInteractionVO.toSipId)) {
|
|
|
|
+ //通话失败,重置并返回主界面
|
|
|
|
+ showMessage("sip_core targetSipId empty!")
|
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
|
+ if (sky_voice_call_timer != null) {
|
|
|
|
+ sky_voice_call_timer.stop()
|
|
|
|
+ }
|
|
|
|
+ callEnd(true)
|
|
|
|
+ } else {
|
|
|
|
+ val addressToCall = sipCore!!.interpretUrl(curInteractionVO.toSipId)
|
|
|
|
+ val params = sipCore!!.createCallParams(null)
|
|
|
|
+ params?.isVideoEnabled = false
|
|
|
|
+ if (addressToCall != null) {
|
|
|
|
+ sipCore!!.inviteAddressWithParams(addressToCall, params!!)
|
|
|
|
+ Log.d(TAG, ">>>>>>>>>>> invite address: " + addressToCall.asString())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (curTcpModel.getAction() == TcpAction.VoiceAction.REJECT) {
|
|
|
|
+ //我方呼出,对方拒绝
|
|
|
|
+ showMessage(R.string.call_reject)
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ cancelCall()
|
|
|
|
+ } else if (curTcpModel.getAction() == TcpAction.VoiceAction.CALLING) {
|
|
|
|
+ //我方呼出,对方通话中
|
|
|
|
+ showMessage(R.string.call_busy)
|
|
|
|
+ AppTool.Time.delay(2000) {
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ cancelCall()
|
|
|
|
+ }
|
|
|
|
+ } else if (curTcpModel.getAction() == TcpAction.VoiceAction.SUCCESS) {
|
|
|
|
+ //呼叫成功
|
|
|
|
+ showOutgoingCall()
|
|
|
|
+ //本机呼叫的时候tcpModel为空,只有呼叫成功的时候才能获得对应tcp相关数据
|
|
|
|
+ callSuccess = true
|
|
|
|
+ interactionVO = curInteractionVO
|
|
|
|
+ fromId = curTcpModel.fromId
|
|
|
|
+ tid = curTcpModel.tid
|
|
|
|
+ Constant.interactionId = curInteractionVO.id
|
|
|
|
+ } else if (curTcpModel.getAction() == TcpAction.VoiceAction.FAILED) {
|
|
|
|
+ //我方呼出,对方不在线,设备离线或其它错误
|
|
|
|
+ callSuccess = true
|
|
|
|
+ showMessage(R.string.call_failed)
|
|
|
|
+ AppTool.Time.delay(2000) {
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ cancelCall()
|
|
|
|
+ }
|
|
|
|
+ } else if (curTcpModel.getAction() == TcpAction.VoiceAction.HANDOFF) {
|
|
|
|
+ //对方挂断,不论我方呼出或呼入
|
|
|
|
+ if (Constant.interactionId == curInteractionVO.id) {
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ cancelCall()
|
|
|
|
+ }
|
|
|
|
+ } else if (curTcpModel.getAction() == TcpAction.VoiceAction.CANCEL) {
|
|
|
|
+ //对方呼叫时取消
|
|
|
|
+ if (Constant.interactionId == curInteractionVO.id) {
|
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
|
+ cancelCall()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constant.EVENT_END_CALL -> {
|
|
|
|
+ Log.d(TAG, ">>>>>>>>>>>>>> EVENT_END_CALL")
|
|
|
|
+ if (messageEvent.getMessage() is String) {
|
|
|
|
+ val str = messageEvent.message as String
|
|
|
|
+ if (str.equals("cancel")) {
|
|
|
|
+ voiceCancel()
|
|
|
|
+ cancelCall()
|
|
|
|
+ } else {
|
|
|
|
+ callEnd(true)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constant.SIP_CONNECTED -> {
|
|
|
|
+ sipCore!!.isMicEnabled = true
|
|
|
|
+ showCalling(true)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|