|
@@ -0,0 +1,798 @@
|
|
|
+package com.wdkl.ncs.android.component.nursehome.dorm
|
|
|
+
|
|
|
+import android.media.AudioManager
|
|
|
+import android.os.CountDownTimer
|
|
|
+import android.os.Handler
|
|
|
+import android.os.Looper
|
|
|
+import android.os.SystemClock
|
|
|
+import android.util.Log
|
|
|
+import android.view.View
|
|
|
+import android.view.ViewGroup
|
|
|
+import android.widget.SeekBar
|
|
|
+import com.alibaba.android.vlayout.VirtualLayoutManager
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.wdkl.ncs.android.component.nursehome.R
|
|
|
+import com.wdkl.ncs.android.component.nursehome.adapter.BedItemAdapter
|
|
|
+import com.wdkl.ncs.android.component.nursehome.fragment.BaseCallFragment
|
|
|
+import com.wdkl.ncs.android.component.nursehome.helper.SoundPoolManager
|
|
|
+import com.wdkl.ncs.android.component.nursehome.settingconfig.SettingConfig
|
|
|
+import com.wdkl.ncs.android.component.nursehome.util.RingPlayHelper
|
|
|
+import com.wdkl.ncs.android.component.nursehome.util.SpeechUtil
|
|
|
+import com.wdkl.ncs.android.component.nursehome.util.Util
|
|
|
+import com.wdkl.ncs.android.component.nursehome.util.VoiceManagerUtil
|
|
|
+import com.wdkl.ncs.android.lib.base.BaseApplication
|
|
|
+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.bean.SettingConfiguration
|
|
|
+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.DeviceChannel
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.channel.OtherUtil
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.channel.VideoUtil
|
|
|
+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.DeviceTypeEnum
|
|
|
+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.CommonUtils
|
|
|
+import com.wdkl.ncs.android.middleware.utils.StringUtil
|
|
|
+import com.wdkl.ncs.janus.client.CallSessionCallback
|
|
|
+import com.wdkl.ncs.janus.client.JanusClient
|
|
|
+import com.wdkl.ncs.janus.client.VideoRoomCallback
|
|
|
+import com.wdkl.ncs.janus.entity.Room
|
|
|
+import com.wdkl.ncs.janus.rtc.WebRTCEngine
|
|
|
+import com.wdkl.ncs.janus.util.EnumType
|
|
|
+import com.wdkl.ncs.janus.util.JanusConstant
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.*
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.call_volume_bar
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.fullscreen_video_frame
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.ll_voice_call
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.ll_voice_volume_bar
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.pip_video_frame
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.sky_voice_call_calling_text
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.sky_voice_call_hangup
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.sky_voice_call_incoming
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.sky_voice_call_mute
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.sky_voice_call_outgoing
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.sky_voice_call_timer
|
|
|
+import kotlinx.android.synthetic.main.dorm_sky_voice_call_layout.tv_volume
|
|
|
+import kotlinx.android.synthetic.main.sky_voice_call_layout.*
|
|
|
+
|
|
|
+import org.greenrobot.eventbus.Subscribe
|
|
|
+import org.greenrobot.eventbus.ThreadMode
|
|
|
+import org.webrtc.SurfaceViewRenderer
|
|
|
+import java.math.BigInteger
|
|
|
+
|
|
|
+class DormSkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
|
+ private val TAG = "SkyCallFragment"
|
|
|
+
|
|
|
+ private var localSurfaceView: SurfaceViewRenderer? = null
|
|
|
+ private var remoteSurfaceView: SurfaceViewRenderer? = null
|
|
|
+
|
|
|
+ private var bedItemAdapter: BedItemAdapter? = null
|
|
|
+ private val handler = Handler(Looper.getMainLooper())
|
|
|
+
|
|
|
+ private var callEnded: Boolean = false
|
|
|
+ private var outGoing: Boolean = false
|
|
|
+ private var acceptCall = false
|
|
|
+
|
|
|
+ //呼叫倒计时
|
|
|
+ lateinit var countDownTimer: CountDownTimer
|
|
|
+
|
|
|
+ private var janusClient: JanusClient? = null
|
|
|
+ private var room: Room?=null
|
|
|
+ private var videoRoomCallback: VideoRoomCallback? = null
|
|
|
+
|
|
|
+ private var visitUserId: BigInteger? = null
|
|
|
+ private var inVisiting = false
|
|
|
+ private var inCallShow = false
|
|
|
+ private var invitedBed = false
|
|
|
+ private var speakerMute = false
|
|
|
+
|
|
|
+ private var micMute: Boolean = false // 是否关闭麦克风
|
|
|
+
|
|
|
+ private var volume = 60
|
|
|
+
|
|
|
+ override fun getLayId(): Int {
|
|
|
+ return R.layout.dorm_sky_voice_call_layout
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun init() {
|
|
|
+ //设置主题背景
|
|
|
+ try {
|
|
|
+ val resId = SettingConfig.getDormThemeBgId(BaseApplication.appContext)
|
|
|
+ if (resId != 0) {
|
|
|
+ dorm_calling_bed_layout_call_main.setBackgroundResource(resId)
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+
|
|
|
+ showui()
|
|
|
+ initCountDownTimer()
|
|
|
+ volume = SettingConfig.getHostCallVolume(activity)
|
|
|
+ if (volume < 0 || volume > 100) {
|
|
|
+ volume = 60
|
|
|
+ }
|
|
|
+ call_volume_bar.progress = volume/10
|
|
|
+ tv_volume.text = "" + volume/10
|
|
|
+
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, volume)
|
|
|
+ VoiceManagerUtil.setAudioMute(BaseApplication.appContext, false)
|
|
|
+
|
|
|
+ //初始化 engine
|
|
|
+ if (onlyAudio) {
|
|
|
+ WebRTCEngine.getInstance().init(true, BaseApplication.appContext)
|
|
|
+ } else {
|
|
|
+ WebRTCEngine.getInstance().init(false, BaseApplication.appContext)
|
|
|
+ }
|
|
|
+ //初始化 janusClient
|
|
|
+ janusClient = JanusClient(JanusConstant.JANUS_URL, Constant.SIP_ID!!.toBigInteger())
|
|
|
+
|
|
|
+
|
|
|
+ Log.d(TAG, "out call callState: $callState, local sip: ${Constant.SIP_ID}, target sip: ${Constant.targetSipId}")
|
|
|
+ when (callState) {
|
|
|
+ 0 -> {
|
|
|
+ //发起通话
|
|
|
+ outGoing = true
|
|
|
+ janusClient!!.callState = EnumType.CallState.Outgoing
|
|
|
+ room = Room(Constant.SIP_ID!!.toBigInteger())
|
|
|
+ showCallView(true)
|
|
|
+ Constant.CALL_STATE = Constant.CALL_OUTGOING
|
|
|
+ DeviceChannel.calling = true
|
|
|
+ RingPlayHelper.playRingTone(BaseApplication.appContext, R.raw.ring_back2, true)
|
|
|
+ Constant.IN_CALL = true
|
|
|
+ }
|
|
|
+
|
|
|
+ 1 -> {
|
|
|
+ //来电,如果是模拟分机呼叫则需要主机来创建房间发起通过
|
|
|
+ if (Constant.fromDeviceType == DeviceTypeEnum.SIMULATE_BED_DEVICE.value()) {
|
|
|
+ outGoing = true
|
|
|
+ janusClient!!.callState = EnumType.CallState.Outgoing
|
|
|
+ room = Room(Constant.SIP_ID!!.toBigInteger())
|
|
|
+ showCallView(false)
|
|
|
+ } else {
|
|
|
+ //接受通话
|
|
|
+ outGoing = false
|
|
|
+ janusClient!!.callState = EnumType.CallState.Incoming
|
|
|
+ room = Room(Constant.targetSipId!!.toBigInteger())
|
|
|
+ showCallView(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!visiting && onlyAudio) {
|
|
|
+ //接听呼叫
|
|
|
+ acceptCall = true
|
|
|
+ }
|
|
|
+ Constant.CALL_STATE = Constant.CALL_CALLING
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ videoRoomCallback = VideoRoomCallback(janusClient, room, Constant.SIP_ID!!.toBigInteger())
|
|
|
+ videoRoomCallback!!.callSessionCallback = this
|
|
|
+ janusClient!!.setJanusCallback(videoRoomCallback)
|
|
|
+
|
|
|
+ if (!visiting) {
|
|
|
+ if (onlyAudio || outGoing) {
|
|
|
+ if (outGoing) {
|
|
|
+ if (SettingConfig.getRecordEnable(activity)) {
|
|
|
+ janusClient!!.connect(interactionVO!!.id, true)
|
|
|
+ } else {
|
|
|
+ janusClient!!.connect(-1, false)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ janusClient!!.connect(-1, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ WebRTCEngine.getInstance().setVolumeMute(false)
|
|
|
+ }
|
|
|
+ private fun showui(){
|
|
|
+ //网络图标
|
|
|
+ if (Constant.network_state == 1){
|
|
|
+ title_layout_iv_hl_wifi.visibility = View.VISIBLE
|
|
|
+ title_layout_iv_hl_ethernet.visibility = View.GONE
|
|
|
+ title_layout_iv_hl_wifi.setImageResource(R.mipmap.ic_wifi_fail)
|
|
|
+ }else if ( Constant.network_state == 2){
|
|
|
+ title_layout_iv_hl_wifi.visibility = View.GONE
|
|
|
+ title_layout_iv_hl_ethernet.visibility = View.VISIBLE
|
|
|
+ title_layout_iv_hl_ethernet.setImageResource(R.mipmap.ic_ethernet_success_w)
|
|
|
+ }else{
|
|
|
+ title_layout_iv_hl_wifi.visibility = View.GONE
|
|
|
+ title_layout_iv_hl_ethernet.visibility = View.VISIBLE
|
|
|
+ title_layout_iv_hl_ethernet.setImageResource(R.mipmap.ic_ethernet_fail)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
+ title_layout_tv_hl_point.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ title_layout_tv_hl_point.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ //蓝牙图标
|
|
|
+ if (Constant.BT_state == 0) {
|
|
|
+ title_layout_iv_hl_bt.setImageResource(R.mipmap.lanya_b)
|
|
|
+ title_layout_iv_hl_bt.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ title_layout_iv_hl_bt.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ //白天/黑夜
|
|
|
+ if (Constant.day_state == 0){
|
|
|
+ title_layout_iv_day_hl_night.setImageResource(R.mipmap.ic_daylight_w)
|
|
|
+ }else{
|
|
|
+ title_layout_iv_day_hl_night.setImageResource(R.mipmap.ic_night_w)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private fun initCountDownTimer() {
|
|
|
+ if (SettingConfiguration.getInstance().sipOvertime <= 0) {
|
|
|
+ SettingConfiguration.getInstance().sipOvertime = 30
|
|
|
+ }
|
|
|
+
|
|
|
+ countDownTimer = object: CountDownTimer(SettingConfiguration.getInstance().sipOvertime*1000L, 1000) {
|
|
|
+ override fun onTick(millisUntilFinished: Long) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFinish() {
|
|
|
+ //呼叫超时,退出呼叫界面
|
|
|
+ showMessage(R.string.no_response)
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
+ cancelCall(Constant.DEVICE_ID, Constant.targetDeviceId, Constant.interactionId)
|
|
|
+ callEnd(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun bindListener() {
|
|
|
+ bedItemAdapter!!.setInvitClickListener { bedVO ->
|
|
|
+ if (!invitedBed) {
|
|
|
+ invitedBed = true
|
|
|
+ Constant.visitedId = bedVO.bedDeviceId
|
|
|
+ visit_list_view.visibility = View.GONE
|
|
|
+ Constant.visit_bed_name = bedVO.frameBed.fullName
|
|
|
+
|
|
|
+ //邀请分机加入探视
|
|
|
+ val callTcp = VideoUtil.videoInvite(tid, Constant.DEVICE_ID, bedVO.bedDeviceId, Constant.interactionId, Constant.targetSipId)
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+ } else {
|
|
|
+ showMessage("invited..." + Constant.visit_bed_name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun bindEvent() {
|
|
|
+ //通话挂断
|
|
|
+ sky_voice_call_hangup.setOnClickListener {
|
|
|
+ if (Constant.CALL_STATE == Constant.CALL_CALLING) {
|
|
|
+ callEnd(true)
|
|
|
+ } else if (Constant.CALL_STATE == Constant.CALL_OUTGOING) {
|
|
|
+ countDownTimer.cancel()
|
|
|
+ cancelCall(Constant.DEVICE_ID, Constant.targetDeviceId, Constant.interactionId)
|
|
|
+ callEnd(false)
|
|
|
+ } else {
|
|
|
+ callEnd(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ dorm_sos_but.setOnClickListener {
|
|
|
+ //紧急呼叫
|
|
|
+ if (Constant.TCP_CONNECTED) {
|
|
|
+ val tcpModel = OtherUtil.SOSCall(Constant.DEVICE_ID)
|
|
|
+ TcpClient.getInstance().sendMsg(tcpModel.toJson())
|
|
|
+ SoundPoolManager.getInstance().playSound(7, 1.0f, 1.0f, 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// iv_accept_call.setOnClickListener {
|
|
|
+// //视频接听
|
|
|
+// RingPlayHelper.stopRingTone()
|
|
|
+// SpeechUtil.getInstance().stopSpeak(true)
|
|
|
+// if (visiting) {
|
|
|
+// val callTcp = VideoUtil.videoInCall(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
+// TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+// } else {
|
|
|
+// val callTcp = VoiceUtil.voiceAccept(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
+// TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+// }
|
|
|
+//
|
|
|
+// janusClient!!.connect(-1, false)
|
|
|
+// }
|
|
|
+
|
|
|
+// iv_reject_call.setOnClickListener {
|
|
|
+// //视频拒绝
|
|
|
+// RingPlayHelper.stopRingTone()
|
|
|
+// SpeechUtil.getInstance().stopSpeak(true)
|
|
|
+// if (visiting) {
|
|
|
+// val callTcp = VideoUtil.videoReject(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
+// TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+// } else {
|
|
|
+// val callTcp = VoiceUtil.voiceReject(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
+// TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+// }
|
|
|
+//
|
|
|
+// callEnd(false)
|
|
|
+// }
|
|
|
+
|
|
|
+ sky_voice_call_speaker.setOnClickListener {
|
|
|
+ speakerMute = !speakerMute
|
|
|
+ Log.d(TAG,"Speaker enable: $speakerMute")
|
|
|
+
|
|
|
+ WebRTCEngine.getInstance().setVolumeMute(speakerMute)
|
|
|
+ sky_voice_call_speaker.isSelected = speakerMute
|
|
|
+ }
|
|
|
+
|
|
|
+ sky_voice_call_mute.setOnClickListener {
|
|
|
+ micMute = !micMute
|
|
|
+ Log.d(TAG,"静音切换: $micMute")
|
|
|
+
|
|
|
+ WebRTCEngine.getInstance().muteAudio(micMute)
|
|
|
+ sky_voice_call_mute.isSelected = micMute
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun destroy() {
|
|
|
+ Constant.IN_CALL = false
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ if (sky_voice_call_timer != null) {
|
|
|
+ sky_voice_call_timer.stop()
|
|
|
+ }
|
|
|
+ handler.removeCallbacksAndMessages(null)
|
|
|
+ VoiceManagerUtil.setAudioMode(BaseApplication.appContext, AudioManager.MODE_NORMAL)
|
|
|
+ }
|
|
|
+
|
|
|
+ //开始接听
|
|
|
+ private fun showCallView(outgoing: Boolean) {
|
|
|
+ if (outgoing) {
|
|
|
+ countDownTimer.start()
|
|
|
+ sky_voice_call_calling_text.text = StringUtil.getResString(R.string.call_in_calling) + " " + callName
|
|
|
+ sky_voice_call_outgoing.visibility = View.VISIBLE
|
|
|
+ sky_voice_call_incoming.visibility = View.GONE
|
|
|
+
|
|
|
+ if (!onlyAudio) {
|
|
|
+ //显示视频画面
|
|
|
+ fullscreen_video_frame.visibility = View.VISIBLE
|
|
|
+ pip_video_frame.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ dorm_sky_call_name.text = callName
|
|
|
+ if (onlyAudio) {
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_connecting)
|
|
|
+ sky_voice_call_outgoing.visibility = View.VISIBLE
|
|
|
+ sky_voice_call_incoming.visibility = View.GONE
|
|
|
+ } else {
|
|
|
+ if (visiting) {
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_visiting)
|
|
|
+ } else {
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_video_call)
|
|
|
+ }
|
|
|
+ sky_voice_call_outgoing.visibility = View.GONE
|
|
|
+ sky_voice_call_incoming.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //sky_voice_call_outgoing.visibility = View.VISIBLE
|
|
|
+ sky_voice_call_timer.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showCalling(audioOnly: Boolean) {
|
|
|
+ if (callEnded || inCallShow) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ inCallShow = true
|
|
|
+ dorm_sky_call_name.text = callName
|
|
|
+ if (audioOnly) {
|
|
|
+ ll_voice_call.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ //显示视频画面
|
|
|
+ fullscreen_video_frame.visibility = View.VISIBLE
|
|
|
+ pip_video_frame.visibility = View.VISIBLE
|
|
|
+
|
|
|
+// if (visiting) {
|
|
|
+// video_visit_call_view.visibility = View.VISIBLE
|
|
|
+// video_call_view.visibility = View.GONE
|
|
|
+// } else {
|
|
|
+// video_visit_call_view.visibility = View.GONE
|
|
|
+// video_call_view.visibility = View.VISIBLE
|
|
|
+// }
|
|
|
+ ll_voice_call.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ sky_voice_call_outgoing.visibility = View.VISIBLE
|
|
|
+ sky_voice_call_incoming.visibility = View.GONE
|
|
|
+
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_in_call)
|
|
|
+ sky_voice_call_timer.visibility = View.VISIBLE
|
|
|
+ sky_voice_call_timer.base = SystemClock.elapsedRealtime()
|
|
|
+ sky_voice_call_timer.start()
|
|
|
+
|
|
|
+ sky_voice_call_speaker.visibility = View.VISIBLE
|
|
|
+ sky_voice_call_mute.visibility = View.VISIBLE
|
|
|
+ ll_voice_volume_bar.visibility = View.VISIBLE
|
|
|
+
|
|
|
+ if (Constant.hookOn) {
|
|
|
+ //手柄放下,免提模式
|
|
|
+ //VoiceManagerUtil.switchAudioMode(BaseApplication.appContext, true)
|
|
|
+ WebRTCEngine.getInstance().toggleSpeaker(true)
|
|
|
+ } else {
|
|
|
+ //手柄拿起,听筒模式
|
|
|
+ //VoiceManagerUtil.switchAudioMode(BaseApplication.appContext, false)
|
|
|
+ WebRTCEngine.getInstance().toggleSpeaker(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun cancelCall(fromId: Int, toId: Int?, interactionId: Int?) {
|
|
|
+ val callTcp = VoiceUtil.voiceCancel(tid, fromId, toId, interactionId)
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+ }
|
|
|
+
|
|
|
+ //通话结束
|
|
|
+ private fun callEnd(handoff: Boolean) {
|
|
|
+ Log.e(TAG, "call end !!!!!!!!!!!!!!!!!!")
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
+ countDownTimer.cancel()
|
|
|
+
|
|
|
+ Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+
|
|
|
+ synchronized(this) {
|
|
|
+ if (callEnded) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callEnded = true
|
|
|
+
|
|
|
+ if (sky_voice_call_timer != null) {
|
|
|
+ sky_voice_call_timer.stop()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (janusClient != null && janusClient!!.webSocketChannel !=null) {
|
|
|
+ janusClient!!.callState = EnumType.CallState.Idle
|
|
|
+ if (outGoing){
|
|
|
+ if (janusClient!!.currentHandleId !=null) {
|
|
|
+ janusClient!!.destroyRoom(janusClient!!.currentHandleId, null)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ janusClient!!.leaveRoom()
|
|
|
+ }
|
|
|
+
|
|
|
+ janusClient!!.setJanusCallback(null)
|
|
|
+ janusClient!!.disConnect()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (handoff) {
|
|
|
+ if (visiting) {
|
|
|
+ val callTcp = VideoUtil.videoHandoff(tid, Constant.DEVICE_ID, Constant.fromId, Constant.interactionId)
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+ } else {
|
|
|
+ val callTcp = VoiceUtil.voiceHandoff(tid, Constant.DEVICE_ID, Constant.fromId, Constant.interactionId)
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Constant.interactionId = null
|
|
|
+
|
|
|
+ backToMain()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /********************************************************
|
|
|
+ ********************* webrtc通话回调 ********************
|
|
|
+ * 注意: 如涉及到UI更新的需要在主线程处理,务必注意
|
|
|
+ *******************************************************/
|
|
|
+ override fun didRoomCreated() {
|
|
|
+ //房间创建成功,如果是接听通话则通知对方加入通话
|
|
|
+ if (!callEnded && acceptCall) {
|
|
|
+ Log.d(TAG, "room created, accept call...")
|
|
|
+ val callTcp = VoiceUtil.voiceAccept(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didIceConnectFail() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didSlowLink() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didChangeState(state: EnumType.CallState?) {
|
|
|
+ Log.e(TAG, "didChangeState: " + state)
|
|
|
+ handler.post {
|
|
|
+ if (state == EnumType.CallState.Connected && !callEnded) {
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
+ Constant.CALL_STATE = Constant.CALL_CALLING
|
|
|
+ DeviceChannel.calling = true
|
|
|
+ Constant.IN_CALL = true
|
|
|
+ //更新界面显示
|
|
|
+ showCalling(onlyAudio)
|
|
|
+
|
|
|
+ if (!outGoing) {
|
|
|
+ //被叫接听时开始录音录像
|
|
|
+ if (SettingConfig.getRecordEnable(activity)) {
|
|
|
+ janusClient!!.beginRecord()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didDisconnected(userId: String?) {
|
|
|
+ handler.post {
|
|
|
+ if (userId.equals(Constant.targetSipId)) {
|
|
|
+ showMessage(R.string.call_disconnect)
|
|
|
+ callEnd(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didError(error: String?) {
|
|
|
+ handler.post {
|
|
|
+ showMessage(R.string.call_error)
|
|
|
+ callEnd(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didHangUp(handlerId: BigInteger) {
|
|
|
+ Log.e("hangup", "socket hangup")
|
|
|
+ handler.post {
|
|
|
+ callEnd(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理本地视频画面
|
|
|
+ override fun didCreateLocalVideoTrack() {
|
|
|
+ Log.e(TAG, "didCreateLocalVideoTrack")
|
|
|
+ handler.post {
|
|
|
+ if (!callEnded) {
|
|
|
+ if (visiting) {
|
|
|
+ //探视
|
|
|
+ /*if (localSurfaceView == null) {
|
|
|
+ val surfaceView = WebRTCEngine.getInstance().startPreview(true)
|
|
|
+ Log.e(TAG, "didCreateLocalVideoTrack visit surfaceView: $surfaceView")
|
|
|
+ if (surfaceView != null) {
|
|
|
+ localSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (localSurfaceView!!.parent != null) {
|
|
|
+ (localSurfaceView!!.parent as ViewGroup).removeView(localSurfaceView)
|
|
|
+ }
|
|
|
+ video_frame2.addView(localSurfaceView)*/
|
|
|
+ } else {
|
|
|
+ //普通视频通话
|
|
|
+ if (localSurfaceView == null) {
|
|
|
+ val surfaceView = WebRTCEngine.getInstance().startPreview(true)
|
|
|
+ Log.e(TAG, "didCreateLocalVideoTrack surfaceView: $surfaceView")
|
|
|
+ if (surfaceView != null) {
|
|
|
+ localSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ localSurfaceView!!.setZOrderMediaOverlay(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (localSurfaceView!!.parent != null) {
|
|
|
+ (localSurfaceView!!.parent as ViewGroup).removeView(localSurfaceView)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (outGoing && remoteSurfaceView == null) {
|
|
|
+ if (fullscreen_video_frame != null) {
|
|
|
+ if (fullscreen_video_frame.getChildCount() != 0) {
|
|
|
+ fullscreen_video_frame.removeAllViews()
|
|
|
+ }
|
|
|
+ fullscreen_video_frame.addView(localSurfaceView)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (pip_video_frame != null) {
|
|
|
+ if (pip_video_frame.getChildCount() != 0) {
|
|
|
+ pip_video_frame.removeAllViews()
|
|
|
+ }
|
|
|
+ pip_video_frame.addView(localSurfaceView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理远端视频画面
|
|
|
+ override fun didReceiveRemoteVideoTrack(userId: BigInteger?) {
|
|
|
+ Log.e(TAG, "didReceiveRemoteVideoTrack userId: $userId")
|
|
|
+ handler.post {
|
|
|
+ if (!callEnded) {
|
|
|
+ //本地画面
|
|
|
+ if (localSurfaceView != null) {
|
|
|
+ localSurfaceView!!.setZOrderMediaOverlay(true)
|
|
|
+ if (outGoing) {
|
|
|
+ if (localSurfaceView!!.parent != null) {
|
|
|
+ (localSurfaceView!!.parent as ViewGroup).removeView(localSurfaceView)
|
|
|
+ }
|
|
|
+ if (pip_video_frame != null) {
|
|
|
+ pip_video_frame.addView(localSurfaceView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //远端画面
|
|
|
+ val surfaceView = WebRTCEngine.getInstance().setupRemoteVideo(userId, false)
|
|
|
+ Log.e(TAG, "didReceiveRemoteVideoTrack,surfaceView = $surfaceView")
|
|
|
+ if (surfaceView != null && fullscreen_video_frame != null) {
|
|
|
+ remoteSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
+ fullscreen_video_frame.removeAllViews()
|
|
|
+ if (remoteSurfaceView!!.parent != null) {
|
|
|
+ (remoteSurfaceView!!.parent as ViewGroup).removeView(remoteSurfaceView)
|
|
|
+ }
|
|
|
+ fullscreen_video_frame.addView(remoteSurfaceView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didCallEndWithReason(callEndReason: EnumType.CallEndReason?) {
|
|
|
+ handler.post {
|
|
|
+
|
|
|
+
|
|
|
+ showMessage(R.string.call_end)
|
|
|
+ callEnd(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didChangeMode(isAudioOnly: Boolean) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun didUserLeave(userId: BigInteger?) {
|
|
|
+ handler.post {
|
|
|
+ showMessage(R.string.call_end)
|
|
|
+ callEnd(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
+ fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
+ when (messageEvent.getType()) {
|
|
|
+ Constant.EVENT_TCP_MSG -> {
|
|
|
+ if (messageEvent.getMessage() is TcpModel) {
|
|
|
+ val curTcpModel = messageEvent.getMessage() as TcpModel
|
|
|
+ if (curTcpModel.type == TcpType.VOICE) {
|
|
|
+ val curInteractionVO = Gson().fromJson(curTcpModel.data.toString(), InteractionVO::class.java)
|
|
|
+ if (curTcpModel.action == TcpAction.VoiceAction.HANDOFF) {
|
|
|
+ //对方挂断,不论我方呼出或呼入
|
|
|
+ if (Constant.interactionId == curInteractionVO.id) {
|
|
|
+ callEnd(false)
|
|
|
+ }
|
|
|
+ } else if (curTcpModel.action == TcpAction.VoiceAction.ACCEPT) {//对方接受语音
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
+ sky_voice_call_calling_text.setText(R.string.call_connecting)
|
|
|
+ Constant.interactionId = curInteractionVO.id
|
|
|
+ Constant.fromId = curTcpModel.fromId
|
|
|
+ interactionVO = curInteractionVO
|
|
|
+ fromId = curTcpModel.fromId
|
|
|
+ DeviceChannel.calling = true
|
|
|
+ Constant.CALL_STATE = Constant.CALL_CALLING
|
|
|
+ countDownTimer.cancel()
|
|
|
+ } else if (curTcpModel.action == TcpAction.VoiceAction.REJECT) {//对方拒绝
|
|
|
+ if (Constant.interactionId == curInteractionVO.id) {
|
|
|
+ showMessage(R.string.call_reject)
|
|
|
+ callEnd(false)
|
|
|
+ }
|
|
|
+ } else if (curTcpModel.action == TcpAction.VoiceAction.CANCEL || curTcpModel.action == TcpAction.VoiceAction.VOICE_OFF) {
|
|
|
+ if (Constant.interactionId == curInteractionVO.id) {
|
|
|
+ if (SettingConfig.getTtsMode(activity) == SettingConfig.TTS_ON) {
|
|
|
+ //val frameName = curInteractionVO.fromFrameFullName.replace("-", "")
|
|
|
+ val frameName = Util.appendSpace(curInteractionVO.fromFrameFullName.replace("-", ","))
|
|
|
+ val text = BaseApplication.appContext.getString(R.string.call_video, frameName)
|
|
|
+ SpeechUtil.getInstance().removeSpeak(text)
|
|
|
+ } else {
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
+ }
|
|
|
+
|
|
|
+ callEnd(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (curTcpModel.type == TcpType.VIDEO) {
|
|
|
+ if (curTcpModel.action == TcpAction.VideoAction.FAILED) {
|
|
|
+ //分机加入视频失败
|
|
|
+ showMessage(R.string.extension_connect_fail)
|
|
|
+
|
|
|
+ return
|
|
|
+ } else if (curTcpModel.action == TcpAction.VideoAction.CALLING) {
|
|
|
+ //分机正在通话
|
|
|
+ showMessage(R.string.extension_call_busy)
|
|
|
+
|
|
|
+ return
|
|
|
+ } else if (curTcpModel.action == TcpAction.VideoAction.REJECT) {
|
|
|
+ //分机加入视频通话失败
|
|
|
+ showMessage(R.string.extension_call_error)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ val curInteractionVO = Gson().fromJson(curTcpModel.data.toString(), InteractionVO::class.java)
|
|
|
+ if (curTcpModel.action == TcpAction.VideoAction.CANCEL || curTcpModel.action == TcpAction.VideoAction.VIDEO_OFF) {
|
|
|
+ //对方取消或被其他设备处理
|
|
|
+ if (Constant.interactionId == curInteractionVO.id) {
|
|
|
+ if (SettingConfig.getTtsMode(activity) == SettingConfig.TTS_ON) {
|
|
|
+ SpeechUtil.getInstance().removeSpeak(StringUtil.getResString(R.string.call_visiting))
|
|
|
+ } else {
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
+ }
|
|
|
+
|
|
|
+ callEnd(false)
|
|
|
+ }
|
|
|
+ } else if (curTcpModel.action == TcpAction.VideoAction.HANDOFF) {
|
|
|
+ //挂断
|
|
|
+ if (Constant.interactionId == curInteractionVO.id) {
|
|
|
+ callEnd(false)
|
|
|
+ }
|
|
|
+ } else if (curTcpModel.action == TcpAction.VideoAction.SUCCESS) {
|
|
|
+ //分机加入探视成功
|
|
|
+ /*Constants.CALL_STATE = Constants.CALL_VISITING
|
|
|
+ DeviceChannel.calling = true
|
|
|
+ VisitingWindow.createFloatView(activity, Constants.visit_bed_name)*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Constant.EVENT_END_CALL -> {
|
|
|
+ if (messageEvent.getMessage() is String) {
|
|
|
+ val str = messageEvent.getMessage() as String
|
|
|
+ if (str.equals("cancel")) {
|
|
|
+ cancelCall(Constant.DEVICE_ID, Constant.targetDeviceId, Constant.interactionId)
|
|
|
+ callEnd(false)
|
|
|
+ } else {
|
|
|
+ if (!inVisiting) {
|
|
|
+ callEnd(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Constant.EVENT_V_HOOK_OFF -> {
|
|
|
+ if (!onlyAudio) {
|
|
|
+ //视频接听
|
|
|
+ RingPlayHelper.stopRingTone()
|
|
|
+ SpeechUtil.getInstance().stopSpeak(true)
|
|
|
+ val callTcp = VoiceUtil.voiceAccept(tid, Constant.DEVICE_ID, fromId, interactionVO?.id)
|
|
|
+ TcpClient.getInstance().sendMsg(callTcp.toJson())
|
|
|
+
|
|
|
+ janusClient!!.connect(-1, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|