|
@@ -40,6 +40,8 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
|
|
|
|
private val handler = Handler(Looper.getMainLooper())
|
|
private val handler = Handler(Looper.getMainLooper())
|
|
|
|
|
|
|
|
+ private var callEnded: Boolean = false
|
|
|
|
+
|
|
override fun getLayId(): Int {
|
|
override fun getLayId(): Int {
|
|
return R.layout.sky_voice_call_layout
|
|
return R.layout.sky_voice_call_layout
|
|
}
|
|
}
|
|
@@ -79,14 +81,20 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
|
|
|
|
1 -> {
|
|
1 -> {
|
|
//接受通话
|
|
//接受通话
|
|
|
|
+ Constants.CALL_STATE = Constants.CALL_CALLING
|
|
|
|
+ DeviceChannel.calling = true
|
|
|
|
+ val session = gEngineKit?.getCurrentSession()
|
|
|
|
+ if (session != null) {
|
|
|
|
+ session.setSessionCallback(this)
|
|
|
|
+ }
|
|
if (onlyAudio) {
|
|
if (onlyAudio) {
|
|
Handler().postDelayed({
|
|
Handler().postDelayed({
|
|
joinAudioCall()
|
|
joinAudioCall()
|
|
- }, 1500)
|
|
|
|
|
|
+ }, 500)
|
|
} else {
|
|
} else {
|
|
Handler().postDelayed({
|
|
Handler().postDelayed({
|
|
joinVideoCall()
|
|
joinVideoCall()
|
|
- }, 2000)
|
|
|
|
|
|
+ }, 500)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -119,15 +127,11 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
//通话挂断
|
|
//通话挂断
|
|
sky_voice_call_hangup.setOnClickListener {
|
|
sky_voice_call_hangup.setOnClickListener {
|
|
//结束sip通话
|
|
//结束sip通话
|
|
- val session = gEngineKit?.getCurrentSession()
|
|
|
|
- if (session != null) {
|
|
|
|
- session.leave()
|
|
|
|
- }
|
|
|
|
|
|
+ gEngineKit?.endCall()
|
|
|
|
|
|
Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
DeviceChannel.calling = false
|
|
DeviceChannel.calling = false
|
|
sky_voice_call_timer.stop()
|
|
sky_voice_call_timer.stop()
|
|
- backToMain()
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -151,11 +155,23 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
val session = gEngineKit?.getCurrentSession()
|
|
val session = gEngineKit?.getCurrentSession()
|
|
if (session != null) {
|
|
if (session != null) {
|
|
Log.e("dds", "audio call session state: " + session.state)
|
|
Log.e("dds", "audio call session state: " + session.state)
|
|
- session.setSessionCallback(this)
|
|
|
|
- }
|
|
|
|
- if (session != null && session.state == EnumType.CallState.Incoming) {
|
|
|
|
- session.joinHome(session.roomId)
|
|
|
|
- session.toggleSpeaker(true)
|
|
|
|
|
|
+
|
|
|
|
+ if (session.state == EnumType.CallState.Incoming) {
|
|
|
|
+ session.joinHome(session.roomId)
|
|
|
|
+ session.toggleSpeaker(true)
|
|
|
|
+ } else if (session.state == EnumType.CallState.Idle) {
|
|
|
|
+ callEnd()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Handler().postDelayed({
|
|
|
|
+ if (session.state == EnumType.CallState.Connected){
|
|
|
|
+ showCalling(onlyAudio)
|
|
|
|
+ } else {
|
|
|
|
+ gEngineKit?.endCall()
|
|
|
|
+ callEnd()
|
|
|
|
+ }
|
|
|
|
+ }, 1500)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -164,18 +180,30 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
val session = gEngineKit?.getCurrentSession()
|
|
val session = gEngineKit?.getCurrentSession()
|
|
if (session != null) {
|
|
if (session != null) {
|
|
Log.e("dds", "video call session state: " + session.state)
|
|
Log.e("dds", "video call session state: " + session.state)
|
|
- session.setSessionCallback(this)
|
|
|
|
- }
|
|
|
|
- if (session != null && session.state == EnumType.CallState.Incoming) {
|
|
|
|
- val surfaceView = gEngineKit!!.currentSession.setupLocalVideo(false)
|
|
|
|
- if (surfaceView != null) {
|
|
|
|
- localSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
- localSurfaceView!!.setZOrderMediaOverlay(false)
|
|
|
|
- fullscreen_video_frame.addView(localSurfaceView)
|
|
|
|
|
|
+
|
|
|
|
+ if (session.state == EnumType.CallState.Incoming) {
|
|
|
|
+ val surfaceView = gEngineKit!!.currentSession.setupLocalVideo(false)
|
|
|
|
+ if (surfaceView != null) {
|
|
|
|
+ localSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
+ localSurfaceView!!.setZOrderMediaOverlay(false)
|
|
|
|
+ fullscreen_video_frame.addView(localSurfaceView)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ session.joinHome(session.roomId)
|
|
|
|
+ session.toggleSpeaker(true)
|
|
|
|
+ } else if (session.state == EnumType.CallState.Idle) {
|
|
|
|
+ callEnd()
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
- session.joinHome(session.roomId)
|
|
|
|
- session.toggleSpeaker(true)
|
|
|
|
|
|
+ Handler().postDelayed({
|
|
|
|
+ if (session.state == EnumType.CallState.Connected){
|
|
|
|
+ showCalling(onlyAudio)
|
|
|
|
+ } else {
|
|
|
|
+ gEngineKit?.endCall()
|
|
|
|
+ callEnd()
|
|
|
|
+ }
|
|
|
|
+ }, 2000)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -192,8 +220,6 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
ll_voice_call.visibility = View.GONE
|
|
ll_voice_call.visibility = View.GONE
|
|
}
|
|
}
|
|
|
|
|
|
- Constants.CALL_STATE = Constants.CALL_CALLING
|
|
|
|
- DeviceChannel.calling = true
|
|
|
|
sky_voice_call_calling_text.text = "通话中..."
|
|
sky_voice_call_calling_text.text = "通话中..."
|
|
sky_voice_call_timer.visibility = View.VISIBLE
|
|
sky_voice_call_timer.visibility = View.VISIBLE
|
|
sky_voice_call_timer.base = SystemClock.elapsedRealtime()
|
|
sky_voice_call_timer.base = SystemClock.elapsedRealtime()
|
|
@@ -217,8 +243,20 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
if (session == null) {
|
|
if (session == null) {
|
|
return false
|
|
return false
|
|
} else {
|
|
} else {
|
|
|
|
+ Constants.CALL_STATE = Constants.CALL_CALLING
|
|
|
|
+ DeviceChannel.calling = true
|
|
session.setSessionCallback(this)
|
|
session.setSessionCallback(this)
|
|
session.toggleSpeaker(true)
|
|
session.toggleSpeaker(true)
|
|
|
|
+
|
|
|
|
+ //3s还未连接上则判定为通话失败
|
|
|
|
+ Handler().postDelayed({
|
|
|
|
+ if (session.state == EnumType.CallState.Connected){
|
|
|
|
+ showCalling(onlyAudio)
|
|
|
|
+ } else {
|
|
|
|
+ gEngineKit?.endCall()
|
|
|
|
+ callEnd()
|
|
|
|
+ }
|
|
|
|
+ }, 3000)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return b
|
|
return b
|
|
@@ -227,6 +265,11 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
//通话结束
|
|
//通话结束
|
|
private fun callEnd() {
|
|
private fun callEnd() {
|
|
Log.e("dds", "call end !!!!!!!!!!!!!!!!!!")
|
|
Log.e("dds", "call end !!!!!!!!!!!!!!!!!!")
|
|
|
|
+ if (callEnded) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ callEnded = true
|
|
|
|
+
|
|
Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
DeviceChannel.calling = false
|
|
DeviceChannel.calling = false
|
|
|
|
|
|
@@ -246,22 +289,24 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
*******************************************************/
|
|
*******************************************************/
|
|
override fun didChangeState(state: EnumType.CallState?) {
|
|
override fun didChangeState(state: EnumType.CallState?) {
|
|
Log.e("dds", "didChangeState: " + state)
|
|
Log.e("dds", "didChangeState: " + state)
|
|
- handler.post {
|
|
|
|
|
|
+ /*handler.post {
|
|
if (state == EnumType.CallState.Connected) {
|
|
if (state == EnumType.CallState.Connected) {
|
|
//更新界面显示
|
|
//更新界面显示
|
|
showCalling(onlyAudio)
|
|
showCalling(onlyAudio)
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
}
|
|
}
|
|
|
|
|
|
override fun didDisconnected(userId: String?) {
|
|
override fun didDisconnected(userId: String?) {
|
|
handler.post {
|
|
handler.post {
|
|
|
|
+ showMessage("断开连接")
|
|
callEnd()
|
|
callEnd()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
override fun didError(error: String?) {
|
|
override fun didError(error: String?) {
|
|
handler.post {
|
|
handler.post {
|
|
|
|
+ showMessage("通话错误")
|
|
callEnd()
|
|
callEnd()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -270,11 +315,14 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
override fun didCreateLocalVideoTrack() {
|
|
override fun didCreateLocalVideoTrack() {
|
|
Log.e("dds", "didCreateLocalVideoTrack")
|
|
Log.e("dds", "didCreateLocalVideoTrack")
|
|
handler.post {
|
|
handler.post {
|
|
- if (localSurfaceView == null) {
|
|
|
|
- val surfaceView = gEngineKit!!.currentSession.setupLocalVideo(true)
|
|
|
|
- Log.e("dds", "didCreateLocalVideoTrack surfaceView: " + surfaceView)
|
|
|
|
- if (surfaceView != null) {
|
|
|
|
- localSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
|
|
+ val session = gEngineKit!!.currentSession
|
|
|
|
+ if (session != null && !callEnded) {
|
|
|
|
+ if (localSurfaceView == null) {
|
|
|
|
+ val surfaceView = gEngineKit!!.currentSession.setupLocalVideo(true)
|
|
|
|
+ Log.e("dds", "didCreateLocalVideoTrack surfaceView: " + surfaceView)
|
|
|
|
+ if (surfaceView != null) {
|
|
|
|
+ localSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -284,25 +332,28 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
override fun didReceiveRemoteVideoTrack(userId: String?) {
|
|
override fun didReceiveRemoteVideoTrack(userId: String?) {
|
|
Log.e("dds", "didReceiveRemoteVideoTrack userId: " + userId)
|
|
Log.e("dds", "didReceiveRemoteVideoTrack userId: " + userId)
|
|
handler.post {
|
|
handler.post {
|
|
- //本地画面
|
|
|
|
- if (localSurfaceView != null) {
|
|
|
|
- localSurfaceView!!.setZOrderMediaOverlay(true)
|
|
|
|
- if (localSurfaceView!!.parent != null) {
|
|
|
|
- (localSurfaceView!!.parent as ViewGroup).removeView(localSurfaceView)
|
|
|
|
|
|
+ val session = gEngineKit!!.currentSession
|
|
|
|
+ if (session != null && !callEnded) {
|
|
|
|
+ //本地画面
|
|
|
|
+ if (localSurfaceView != null) {
|
|
|
|
+ localSurfaceView!!.setZOrderMediaOverlay(true)
|
|
|
|
+ if (localSurfaceView!!.parent != null) {
|
|
|
|
+ (localSurfaceView!!.parent as ViewGroup).removeView(localSurfaceView)
|
|
|
|
+ }
|
|
|
|
+ pip_video_frame!!.addView(localSurfaceView)
|
|
}
|
|
}
|
|
- pip_video_frame!!.addView(localSurfaceView)
|
|
|
|
- }
|
|
|
|
|
|
|
|
- //远端画面
|
|
|
|
- val surfaceView = gEngineKit!!.currentSession.setupRemoteVideo(userId, false)
|
|
|
|
- Log.e("dds", "didReceiveRemoteVideoTrack,surfaceView = $surfaceView")
|
|
|
|
- if (surfaceView != null) {
|
|
|
|
- remoteSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
- fullscreen_video_frame.removeAllViews()
|
|
|
|
- if (remoteSurfaceView!!.parent != null) {
|
|
|
|
- (remoteSurfaceView!!.parent as ViewGroup).removeView(remoteSurfaceView)
|
|
|
|
|
|
+ //远端画面
|
|
|
|
+ val surfaceView = gEngineKit!!.currentSession.setupRemoteVideo(userId, false)
|
|
|
|
+ Log.e("dds", "didReceiveRemoteVideoTrack,surfaceView = $surfaceView")
|
|
|
|
+ if (surfaceView != null) {
|
|
|
|
+ remoteSurfaceView = surfaceView as SurfaceViewRenderer
|
|
|
|
+ fullscreen_video_frame.removeAllViews()
|
|
|
|
+ if (remoteSurfaceView!!.parent != null) {
|
|
|
|
+ (remoteSurfaceView!!.parent as ViewGroup).removeView(remoteSurfaceView)
|
|
|
|
+ }
|
|
|
|
+ fullscreen_video_frame.addView(remoteSurfaceView)
|
|
}
|
|
}
|
|
- fullscreen_video_frame.addView(remoteSurfaceView)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -317,7 +368,7 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
showMessage("通话中")
|
|
showMessage("通话中")
|
|
}
|
|
}
|
|
EnumType.CallEndReason.Hangup -> {
|
|
EnumType.CallEndReason.Hangup -> {
|
|
- //showMessage("挂断")
|
|
|
|
|
|
+ showMessage("通话结束")
|
|
}
|
|
}
|
|
EnumType.CallEndReason.MediaError -> {
|
|
EnumType.CallEndReason.MediaError -> {
|
|
showMessage("媒体错误")
|
|
showMessage("媒体错误")
|
|
@@ -351,6 +402,7 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
|
|
|
|
override fun didUserLeave(userId: String?) {
|
|
override fun didUserLeave(userId: String?) {
|
|
handler.post {
|
|
handler.post {
|
|
|
|
+ showMessage("通话结束")
|
|
callEnd()
|
|
callEnd()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -368,6 +420,7 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
|
|
if (curTcpModel.getAction() == TcpAction.VoiceAction.HANDOFF) {
|
|
if (curTcpModel.getAction() == TcpAction.VoiceAction.HANDOFF) {
|
|
//对方挂断,不论我方呼出或呼入
|
|
//对方挂断,不论我方呼出或呼入
|
|
if (Constants.interactionId == curInteractionVO.id) {
|
|
if (Constants.interactionId == curInteractionVO.id) {
|
|
|
|
+ gEngineKit?.endCall()
|
|
callEnd()
|
|
callEnd()
|
|
}
|
|
}
|
|
}
|
|
}
|