|
@@ -9,6 +9,7 @@ import android.graphics.Color
|
|
|
import android.net.ConnectivityManager
|
|
|
import android.net.Uri
|
|
|
import android.os.Build
|
|
|
+import android.os.Bundle
|
|
|
import android.os.CountDownTimer
|
|
|
import android.provider.Settings
|
|
|
import android.support.v4.app.Fragment
|
|
@@ -24,12 +25,10 @@ import com.google.gson.Gson
|
|
|
import com.wdkl.core.consts.Urls
|
|
|
import com.wdkl.core.socket.IUserState
|
|
|
import com.wdkl.core.socket.SocketManager
|
|
|
-import com.wdkl.core.voip.CallSingleActivity
|
|
|
import com.wdkl.core.voip.SpeechUtil
|
|
|
import com.wdkl.core.window.VisitingWindow
|
|
|
import com.wdkl.ncs.android.component.nursehome.BuildConfig
|
|
|
import com.wdkl.ncs.android.component.nursehome.R
|
|
|
-import com.wdkl.ncs.android.component.nursehome.SipUtil.SipCallBack
|
|
|
import com.wdkl.ncs.android.component.nursehome.common.Constants
|
|
|
import com.wdkl.ncs.android.component.nursehome.databinding.ActivityNurseHomeBinding
|
|
|
import com.wdkl.ncs.android.component.nursehome.fragment.*
|
|
@@ -83,6 +82,10 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
var currentFragmentTwo:Fragment? = null
|
|
|
var currentFragmentThree:Fragment? = null
|
|
|
|
|
|
+ //通话界面fragment
|
|
|
+ private var skyCallFragment: Fragment? = null
|
|
|
+ private var targetId: String? = null
|
|
|
+
|
|
|
var receiver :TimeReceiver? = null
|
|
|
|
|
|
lateinit var countDownTimer: CountDownTimer
|
|
@@ -531,6 +534,24 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun addCallFragment(fragment: Fragment) {
|
|
|
+ skyCallFragment = fragment
|
|
|
+ supportFragmentManager.beginTransaction()
|
|
|
+ .setCustomAnimations(R.anim.slide_down_in, R.anim.slide_up_out)
|
|
|
+ .add(R.id.call_frame, fragment)
|
|
|
+ .commit()
|
|
|
+ }
|
|
|
+
|
|
|
+ fun removeCallFragment() {
|
|
|
+ if (skyCallFragment != null) {
|
|
|
+ supportFragmentManager.beginTransaction()
|
|
|
+ //.setCustomAnimations(R.anim.slide_down_in, R.anim.slide_down_out)
|
|
|
+ .remove(skyCallFragment)
|
|
|
+ .commit()
|
|
|
+ skyCallFragment = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
inline fun FragmentManager.inTransaction(func: FragmentTransaction.() -> FragmentTransaction) {
|
|
|
beginTransaction().func().commit()
|
|
@@ -558,6 +579,7 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
} else if (intent.action == Constants.HOOK_ON) {
|
|
|
Log.e(TAG,"手柄放下 ")
|
|
|
Constants.hookOn = true
|
|
|
+ VoiceManagerUtil.switchAudioMode(activity, true)
|
|
|
if (Constants.CALL_STATE == Constants.CALL_OUTGOING) {
|
|
|
//呼出取消
|
|
|
Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
@@ -571,16 +593,23 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
DeviceChannel.calling = false
|
|
|
VoiceUtil.rejectAudioCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
+ } else if (Constants.CALL_STATE == Constants.CALL_CALLING) {
|
|
|
+ Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ SocketManager.getInstance().endCall()
|
|
|
}
|
|
|
} else if (intent.action == Constants.HOOK_OFF) {
|
|
|
Log.e(TAG,"手柄拿起 ")
|
|
|
Constants.hookOn = false
|
|
|
+ VoiceManagerUtil.switchAudioMode(activity, false)
|
|
|
if (Constants.CALL_STATE == Constants.CALL_INCOMING) {
|
|
|
//来电接听
|
|
|
Constants.CALL_STATE = Constants.CALL_CALLING
|
|
|
DeviceChannel.calling = true
|
|
|
VoiceUtil.acceptAudioCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
+ } else if (Constants.CALL_STATE == Constants.CALL_VISITING) {
|
|
|
+ acceptVisit()
|
|
|
}
|
|
|
} else if (intent.action == ConnectivityManager.CONNECTIVITY_ACTION) {
|
|
|
updateNetState()
|
|
@@ -681,12 +710,12 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
wifi_state_imagev.visibility = View.GONE
|
|
|
}
|
|
|
|
|
|
- if (NetHelper.isBTConnected()) {
|
|
|
+ /*if (NetHelper.isBTConnected()) {
|
|
|
bluetooth_state_imagev.visibility = View.VISIBLE
|
|
|
bluetooth_state_imagev.setImageResource(R.drawable.ic_bt_success)
|
|
|
} else {
|
|
|
bluetooth_state_imagev.visibility = View.GONE
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
private fun updateTcpState() {
|
|
@@ -710,9 +739,44 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
//继续执行父类其他点击事件
|
|
|
}
|
|
|
|
|
|
+ //探视接听
|
|
|
+ fun acceptVisit() {
|
|
|
+ CallDialogHelper.dismissCallDialog()
|
|
|
+ //发送tcp,同时发起视频通话
|
|
|
+ VideoUtil.sendVideoInCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
+
|
|
|
+ Constants.CALL_STATE = Constants.CALL_VISIT_CALLING
|
|
|
+ DeviceChannel.calling = true
|
|
|
+ //通话之前先判断webrtc socket是否连接上,否则不能建立通话
|
|
|
+ if (SocketManager.getInstance().socketOpen()) {
|
|
|
+ var fragment = SkyCallFragment()
|
|
|
+ var bundle = Bundle()
|
|
|
+ bundle.putBoolean("audio_only", false)
|
|
|
+ bundle.putInt("call_state", 0)
|
|
|
+ bundle.putInt("fromId", Constants.fromId!!)
|
|
|
+ bundle.putInt("interactionId", Constants.interactionId!!)
|
|
|
+ bundle.putString("targetId", targetId)
|
|
|
+ bundle.putBoolean("visiting", true)
|
|
|
+ fragment.arguments = bundle
|
|
|
+ addCallFragment(fragment)
|
|
|
+ } else {
|
|
|
+ showMessage("通话服务还未建立连接,请稍后")
|
|
|
+ Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ VoiceUtil.rejectAudioCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
when (messageEvent.getType()) {
|
|
|
+ //退出通话界面
|
|
|
+ Constants.EVENT_REMOVE_CALL_FRAGMENT -> {
|
|
|
+ if (skyCallFragment != null) {
|
|
|
+ removeCallFragment()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Constants.EVENT_TCP_MSG -> {
|
|
|
var tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
Log.e(TAG, "收到tcp消息" + tcpModel.getType() + " " + tcpModel.getAction())
|
|
@@ -729,15 +793,15 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
val text = "来自: " + interactionVO.fromFrameFullName + " 的通话请求"
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
CallDialogHelper.showCallDialog(this@NurseHomeActivity, 1, text,
|
|
|
- View.OnClickListener {
|
|
|
+ {
|
|
|
//呼出取消
|
|
|
},
|
|
|
- View.OnClickListener {
|
|
|
+ {
|
|
|
//来电接听
|
|
|
VoiceUtil.acceptAudioCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
},
|
|
|
- View.OnClickListener {
|
|
|
+ {
|
|
|
//来电拒接
|
|
|
DeviceChannel.calling = false
|
|
|
VoiceUtil.rejectAudioCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
@@ -754,16 +818,39 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
Log.e(TAG, "对方接受语音" + tcpModel.toJson())
|
|
|
Constants.interactionId = interactionVO.id
|
|
|
Constants.fromId = tcpModel.fromId
|
|
|
+ targetId = interactionVO.toSipId
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
countDownTimer.cancel()
|
|
|
|
|
|
DeviceChannel.calling = true
|
|
|
Constants.CALL_STATE = Constants.CALL_CALLING
|
|
|
- if (Constants.call_type == 1) {
|
|
|
+
|
|
|
+ /*if (Constants.call_type == 1) {
|
|
|
CallSingleActivity.openActivity(activity, interactionVO.toSipId, true, interactionVO.toSipId, false, false, false)
|
|
|
} else {
|
|
|
CallSingleActivity.openActivity(activity, interactionVO.toSipId, true, interactionVO.toSipId, true, false, false)
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ //通话之前先判断webrtc socket是否连接上,否则不能建立通话
|
|
|
+ if (SocketManager.getInstance().socketOpen()) {
|
|
|
+ var fragment = SkyCallFragment()
|
|
|
+ var bundle = Bundle()
|
|
|
+ bundle.putBoolean("audio_only", Constants.call_type == 0)
|
|
|
+ bundle.putInt("call_state", 0)
|
|
|
+ bundle.putInt("fromId", tcpModel.fromId)
|
|
|
+ bundle.putInt("interactionId", interactionVO.id)
|
|
|
+ bundle.putBoolean("visiting", false)
|
|
|
+ bundle.putString("targetId", interactionVO.toSipId)
|
|
|
+ fragment.arguments = bundle
|
|
|
+ addCallFragment(fragment)
|
|
|
+ } else {
|
|
|
+ showMessage("通话服务还未建立连接,请稍后")
|
|
|
+ Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ VoiceUtil.rejectAudioCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
}
|
|
|
+
|
|
|
} else if (tcpModel.getAction() == TcpAction.VoiceAction.REJECT) {//对方拒绝
|
|
|
Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
DeviceChannel.calling = false
|
|
@@ -792,23 +879,27 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
countDownTimer.cancel()
|
|
|
} else if (tcpModel.getAction() == TcpAction.VoiceAction.SUCCESS) {//服务器返回的呼叫成功tcp
|
|
|
+ Constants.interactionId = interactionVO.id
|
|
|
callTargetId = interactionVO.toDeviceId
|
|
|
countDownTimer.start()
|
|
|
Constants.CALL_STATE = Constants.CALL_OUTGOING
|
|
|
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
- CallDialogHelper.showCallDialog(this@NurseHomeActivity, 0, "正在呼叫,等待接听中...", View.OnClickListener {
|
|
|
- //呼出取消
|
|
|
- Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
- DeviceChannel.calling = false
|
|
|
- VoiceUtil.cancelAudioCall(Integer.parseInt(Constants.ids), callTargetId)
|
|
|
- CallDialogHelper.dismissCallDialog()
|
|
|
- countDownTimer.cancel()
|
|
|
- }, View.OnClickListener {
|
|
|
- //来电接听
|
|
|
- }, View.OnClickListener {
|
|
|
- //来电拒接
|
|
|
- })
|
|
|
+ CallDialogHelper.showCallDialog(this@NurseHomeActivity, 0, "正在呼叫,等待接听中...",
|
|
|
+ {
|
|
|
+ //呼出取消
|
|
|
+ Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ VoiceUtil.cancelAudioCall(Integer.parseInt(Constants.ids), callTargetId)
|
|
|
+ CallDialogHelper.dismissCallDialog()
|
|
|
+ countDownTimer.cancel()
|
|
|
+ },
|
|
|
+ {
|
|
|
+ //来电接听
|
|
|
+ },
|
|
|
+ {
|
|
|
+ //来电拒接
|
|
|
+ })
|
|
|
|
|
|
EventBus.getDefault().post(MessageEvent(0, Constants.EVENT_REFRESH_CALL_LIST))
|
|
|
}
|
|
@@ -856,26 +947,17 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
//收到探视请求,弹出提示
|
|
|
Constants.fromId = tcpModel.fromId
|
|
|
Constants.interactionId = interactionVO.id
|
|
|
- Constants.CALL_STATE = Constants.CALL_INCOMING
|
|
|
+ Constants.CALL_STATE = Constants.CALL_VISITING
|
|
|
+ //因为探视请求是探视机发起的,所以这里发起通话的时候对方设备应该是探视机的sipId,也即是fromSipId
|
|
|
+ targetId = interactionVO.fromSipId
|
|
|
DeviceChannel.calling = true
|
|
|
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
- CallDialogHelper.showCallDialog(this@NurseHomeActivity, 1, "您有新的探视请求", View.OnClickListener {
|
|
|
+ CallDialogHelper.showCallDialog(this@NurseHomeActivity, 1, "您有新的探视请求", {
|
|
|
//呼出取消
|
|
|
- }, View.OnClickListener {
|
|
|
- //接受探视,创建多人视频房间
|
|
|
- //VideoUtil.acceptVideoCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
- //VideoUtil.sendVideoInCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
- CallDialogHelper.dismissCallDialog()
|
|
|
-
|
|
|
- //发送tcp,同时发起视频通话
|
|
|
- VideoUtil.sendVideoInCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
|
- CallSingleActivity.openActivity(activity, interactionVO.fromSipId, true, interactionVO.fromSipId, false, false, true)
|
|
|
-
|
|
|
- // 创建一个房间并进入
|
|
|
- //val roomId = "visit-room-" + Constants.interactionId
|
|
|
- //CallMultiActivity.openActivity(activity, roomId, true)
|
|
|
- }, View.OnClickListener {
|
|
|
+ }, {
|
|
|
+ acceptVisit()
|
|
|
+ }, {
|
|
|
//拒接探视
|
|
|
DeviceChannel.calling = false
|
|
|
VideoUtil.rejectVideoCall(Integer.parseInt(Constants.ids), Constants.fromId, Constants.interactionId)
|
|
@@ -895,7 +977,7 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
VisitingWindow.release()
|
|
|
} else if (tcpModel.action == TcpAction.VideoAction.SUCCESS) {
|
|
|
//显示探视窗口
|
|
|
- Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
+ Constants.CALL_STATE = Constants.CALL_VISITING
|
|
|
DeviceChannel.calling = true
|
|
|
VisitingWindow.createFloatView(activity, Constants.visit_bed_name)
|
|
|
} else if (tcpModel.action == TcpAction.VideoAction.FAILED) {
|
|
@@ -908,6 +990,11 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
DeviceChannel.calling = false
|
|
|
CallDialogHelper.dismissCallDialog()
|
|
|
showMessage("分机正在通话中,请稍后再试...")
|
|
|
+ } else if (tcpModel.action == TcpAction.VideoAction.REJECT) {
|
|
|
+ Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
+ DeviceChannel.calling = false
|
|
|
+ CallDialogHelper.dismissCallDialog()
|
|
|
+ showMessage("通话异常,请稍后再试...")
|
|
|
}
|
|
|
} else if (tcpModel.type == TcpType.DEVICE) {
|
|
|
if (tcpModel.action == TcpAction.DeviceAction.SYSTEM_SETTING) {
|
|
@@ -944,6 +1031,24 @@ class NurseHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //对方发起sip通话请求,我方接受
|
|
|
+ Constants.EVENT_CALL_STATE -> {
|
|
|
+ if (messageEvent.getMessage() is String) {
|
|
|
+ val call = messageEvent.getMessage() as String
|
|
|
+ var fragment = SkyCallFragment()
|
|
|
+ var bundle = Bundle()
|
|
|
+ bundle.putInt("call_state", 1)
|
|
|
+ bundle.putBoolean("visiting", false)
|
|
|
+ if (call.equals("video_call")) {
|
|
|
+ bundle.putBoolean("audio_only", false)
|
|
|
+ } else {
|
|
|
+ bundle.putBoolean("audio_only", true)
|
|
|
+ }
|
|
|
+ fragment.arguments = bundle
|
|
|
+ addCallFragment(fragment)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|