|
@@ -6,13 +6,19 @@ import android.os.Looper
|
|
import android.os.SystemClock
|
|
import android.os.SystemClock
|
|
import android.util.Log
|
|
import android.util.Log
|
|
import android.view.View
|
|
import android.view.View
|
|
|
|
+import android.view.ViewGroup
|
|
import com.alibaba.android.vlayout.VirtualLayoutManager
|
|
import com.alibaba.android.vlayout.VirtualLayoutManager
|
|
import com.alibaba.fastjson.JSONObject
|
|
import com.alibaba.fastjson.JSONObject
|
|
import com.google.gson.Gson
|
|
import com.google.gson.Gson
|
|
import com.wdkl.ncs.android.component.nursehome.R
|
|
import com.wdkl.ncs.android.component.nursehome.R
|
|
import com.wdkl.ncs.android.component.nursehome.adapter.BedItemAdapter
|
|
import com.wdkl.ncs.android.component.nursehome.adapter.BedItemAdapter
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.hardware.HardWareFactroy
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.settingconfig.SettingConfig
|
|
import com.wdkl.ncs.android.middleware.common.Constant
|
|
import com.wdkl.ncs.android.middleware.common.Constant
|
|
import com.wdkl.ncs.android.component.nursehome.util.RingPlayHelper
|
|
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.base.BaseApplication
|
|
import com.wdkl.ncs.android.lib.utils.AppTool
|
|
import com.wdkl.ncs.android.lib.utils.AppTool
|
|
import com.wdkl.ncs.android.lib.utils.showMessage
|
|
import com.wdkl.ncs.android.lib.utils.showMessage
|
|
@@ -61,6 +67,10 @@ class SkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
private var room: Room?=null
|
|
private var room: Room?=null
|
|
private var videoRoomCallback: VideoRoomCallback? = null
|
|
private var videoRoomCallback: VideoRoomCallback? = null
|
|
|
|
|
|
|
|
+ private var visitUserId: BigInteger? = null
|
|
|
|
+
|
|
|
|
+ private var inVisiting = false
|
|
|
|
+
|
|
//呼叫倒计时
|
|
//呼叫倒计时
|
|
lateinit var countDownTimer: CountDownTimer
|
|
lateinit var countDownTimer: CountDownTimer
|
|
|
|
|
|
@@ -70,6 +80,8 @@ class SkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
|
|
|
|
override fun init() {
|
|
override fun init() {
|
|
initCountDownTimer()
|
|
initCountDownTimer()
|
|
|
|
+ HardWareFactroy.getHardTools().setAudioMute(BaseApplication.appContext, false)
|
|
|
|
+
|
|
//初始化 engine
|
|
//初始化 engine
|
|
WebRTCEngine.getInstance().init(true, BaseApplication.appContext)
|
|
WebRTCEngine.getInstance().init(true, BaseApplication.appContext)
|
|
//初始化 janusClient
|
|
//初始化 janusClient
|
|
@@ -298,9 +310,10 @@ class SkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
}
|
|
}
|
|
|
|
|
|
override fun didChangeState(var1: EnumType.CallState?) {
|
|
override fun didChangeState(var1: EnumType.CallState?) {
|
|
|
|
+
|
|
|
|
+ Log.e(TAG, "didChangeState: " + var1)
|
|
handler.post {
|
|
handler.post {
|
|
if (var1 == EnumType.CallState.Connected) {
|
|
if (var1 == EnumType.CallState.Connected) {
|
|
- Log.e(TAG, "didChangeState: " + var1)
|
|
|
|
if (var1 == EnumType.CallState.Connected && !callEnded) {
|
|
if (var1 == EnumType.CallState.Connected && !callEnded) {
|
|
RingPlayHelper.stopRingTone()
|
|
RingPlayHelper.stopRingTone()
|
|
Constant.CALL_STATE = Constant.CALL_CALLING
|
|
Constant.CALL_STATE = Constant.CALL_CALLING
|
|
@@ -330,6 +343,58 @@ class SkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
}
|
|
}
|
|
|
|
|
|
override fun didCreateLocalVideoTrack() {
|
|
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 didError(error: String?) {
|
|
override fun didError(error: String?) {
|
|
@@ -348,12 +413,112 @@ class SkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
}
|
|
}
|
|
|
|
|
|
override fun didReceiveRemoteVideoTrack(userId: BigInteger?) {
|
|
override fun didReceiveRemoteVideoTrack(userId: BigInteger?) {
|
|
- // TODO("Not yet implemented")
|
|
|
|
|
|
+ Log.e(TAG, "didReceiveRemoteVideoTrack userId: $userId")
|
|
|
|
+ handler.post {
|
|
|
|
+ if (!callEnded) {
|
|
|
|
+ if (visiting) {
|
|
|
|
+ //探视: 首先探视机和护士主机加入视频通话,然后床位分机加入视频通话
|
|
|
|
+ if (visitUserId == null) {
|
|
|
|
+ //当前只有探视机和主机视频
|
|
|
|
+ visitUserId = userId
|
|
|
|
+ visit_list_view.visibility = View.VISIBLE
|
|
|
|
+ val surfaceView = WebRTCEngine.getInstance().setupRemoteVideo(userId, false)
|
|
|
|
+ Log.e(TAG, "didReceiveRemoteVideoTrack, visit surfaceView = $surfaceView")
|
|
|
|
+ //探视机端画面添加到左侧frame layout中
|
|
|
|
+ if (surfaceView != null && visit_video_frame2 != null) {
|
|
|
|
+ remoteSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
+ visit_video_frame2.removeAllViews()
|
|
|
|
+ if (remoteSurfaceView!!.parent != null) {
|
|
|
|
+ (remoteSurfaceView!!.parent as ViewGroup).removeView(remoteSurfaceView)
|
|
|
|
+ }
|
|
|
|
+ visit_video_frame2.addView(remoteSurfaceView)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //分机加入视频通话,显示探视双方画面,并静音
|
|
|
|
+ visit_list_view.visibility = View.GONE
|
|
|
|
+ sky_call_speaker_on.visibility = View.VISIBLE
|
|
|
|
+ inVisiting = true
|
|
|
|
+ WebRTCEngine.getInstance().muteAudio(true)
|
|
|
|
+ HardWareFactroy.getHardTools().setAudioMute(BaseApplication.appContext, true)
|
|
|
|
+ val surfaceView = WebRTCEngine.getInstance().setupRemoteVideo(userId, false)
|
|
|
|
+ Log.e(TAG, "didReceiveRemoteVideoTrack, visit bed surfaceView = $surfaceView")
|
|
|
|
+ //床位分机端画面添加到右侧frame layout中
|
|
|
|
+ if (surfaceView != null && visit_video_frame1 != null) {
|
|
|
|
+ tv_visit_title.visibility = View.VISIBLE
|
|
|
|
+ localSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
+ visit_video_frame1.removeAllViews()
|
|
|
|
+ if (localSurfaceView!!.parent != null) {
|
|
|
|
+ (localSurfaceView!!.parent as ViewGroup).removeView(localSurfaceView)
|
|
|
|
+ }
|
|
|
|
+ visit_video_frame1.addView(localSurfaceView)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //本地画面
|
|
|
|
+ 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(var1: EnumType.CallEndReason?) {
|
|
override fun didCallEndWithReason(var1: EnumType.CallEndReason?) {
|
|
- //
|
|
|
|
|
|
+ handler.post {
|
|
|
|
+ /*when (callEndReason) {
|
|
|
|
+ EnumType.CallEndReason.Busy -> {
|
|
|
|
+ showMessage("对方忙线中")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.AcceptByOtherClient -> {
|
|
|
|
+ showMessage("通话中")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.Hangup -> {
|
|
|
|
+ showMessage("通话结束")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.MediaError -> {
|
|
|
|
+ showMessage("媒体错误")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.OpenCameraFailure -> {
|
|
|
|
+ showMessage("打开摄像头错误")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.RemoteHangup -> {
|
|
|
|
+ showMessage("对方挂断")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.RemoteSignalError -> {
|
|
|
|
+ showMessage("对方网络断开")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.SignalError -> {
|
|
|
|
+ showMessage("连接断开")
|
|
|
|
+ }
|
|
|
|
+ EnumType.CallEndReason.Timeout -> {
|
|
|
|
+ showMessage("对方未接听")
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ showMessage(R.string.call_end)
|
|
|
|
+ callEnd(true)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
override fun didUserLeave(userId: BigInteger?) {
|
|
override fun didUserLeave(userId: BigInteger?) {
|
|
@@ -396,21 +561,53 @@ class SkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
DeviceChannel.calling = false
|
|
DeviceChannel.calling = false
|
|
callEnd(false)
|
|
callEnd(false)
|
|
}
|
|
}
|
|
- } /*else if (curTcpModel.getAction() == TcpAction.VoiceAction.CALLING) {//对方通话中
|
|
|
|
- showMessage(R.string.call_busy)
|
|
|
|
- AppTool.Time.delay(800) {
|
|
|
|
- Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
|
- DeviceChannel.calling = 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)
|
|
callEnd(false)
|
|
}
|
|
}
|
|
- } else if (curTcpModel.getAction() == TcpAction.VoiceAction.FAILED) {//对方不在线 呼叫失败
|
|
|
|
- //showMessage("对方离线或不存在,呼叫失败")
|
|
|
|
- AppTool.Time.delay(800) {
|
|
|
|
- Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
|
- DeviceChannel.calling = false
|
|
|
|
- callEnd(false)
|
|
|
|
|
|
+ } else if (curTcpModel.type == TcpType.VIDEO) {
|
|
|
|
+ val curInteractionVO = Gson().fromJson(curTcpModel.data.toString(), InteractionVO::class.java)
|
|
|
|
+ if (curTcpModel.action == TcpAction.VideoAction.CANCEL) {
|
|
|
|
+ //对方取消
|
|
|
|
+ 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)*/
|
|
|
|
+ } else if (curTcpModel.action == TcpAction.VideoAction.FAILED) {
|
|
|
|
+ //分机加入视频失败
|
|
|
|
+ showMessage(R.string.extension_connect_fail)
|
|
|
|
+ } else if (curTcpModel.action == TcpAction.VideoAction.CALLING) {
|
|
|
|
+ //分机正在通话
|
|
|
|
+ showMessage(R.string.extension_call_busy)
|
|
|
|
+ } else if (curTcpModel.action == TcpAction.VideoAction.REJECT) {
|
|
|
|
+ //分机加入视频通话失败
|
|
|
|
+ showMessage(R.string.extension_call_error)
|
|
}
|
|
}
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -426,7 +623,25 @@ class SkyCallFragment: BaseCallFragment(), CallSessionCallback {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Constant.EVENT_V_HOOK_OFF -> {
|
|
|
|
+ if (!onlyAudio) {
|
|
|
|
+ //视频接听
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|