Bladeren bron

完成视频对讲界面基础

allen 4 jaren geleden
bovenliggende
commit
de37fd3fc4

+ 1 - 2
home/src/main/AndroidManifest.xml

@@ -16,8 +16,7 @@
 
         <activity android:name=".activity.HomeActivity"
             android:launchMode="singleTask"/>
-        <activity android:name=".activity.WebRTCVoipAudioActivity"/>
-        <activity android:name=".activity.WebRTCVoipAudioRingingActivity" />
+        <activity android:name=".activity.VideoActivity"/>
         <activity android:name=".activity.AppUpdateActivity" />
 
         <service android:name=".service.TcpHandleService">

+ 128 - 2
home/src/main/code/com/wdkl/ncs/android/component/home/activity/VideoActivity.kt

@@ -1,11 +1,17 @@
 package com.wdkl.ncs.android.component.home.activity
 
+import android.annotation.TargetApi
 import android.app.Activity
 import android.databinding.DataBindingUtil
+import android.graphics.Color
+import android.os.Build
 import android.os.Bundle
 import android.os.Handler
 import android.os.SystemClock
+import android.util.Log
 import android.view.View
+import android.view.ViewGroup
+import android.view.WindowManager
 import com.google.gson.Gson
 import com.wdkl.core.voip.VoipEvent
 import com.wdkl.ncs.android.component.home.R
@@ -15,6 +21,7 @@ import com.wdkl.ncs.android.lib.utils.AppTool
 import com.wdkl.ncs.android.lib.utils.showMessage
 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.VideoUtil
 import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
 import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
@@ -22,19 +29,24 @@ import com.wdkl.ncs.android.middleware.utils.MessageEvent
 import com.wdkl.skywebrtc.SkyEngineKit
 import com.wdkl.skywebrtc.except.NotInitializedException
 import kotlinx.android.synthetic.main.activity_video.*
-import kotlinx.android.synthetic.main.activity_video.call_duration_tv
 import org.greenrobot.eventbus.EventBus
 import org.greenrobot.eventbus.Subscribe
 import org.greenrobot.eventbus.ThreadMode
+import org.webrtc.SurfaceViewRenderer
 
 class VideoActivity:Activity(){
+    val TAG = "VideoActivity"
 
     lateinit var mViewBinding: ActivityVideoBinding
     lateinit var gEngineKit: SkyEngineKit
+    lateinit var localSurfaceView: SurfaceViewRenderer
+    lateinit var remoteSurfaceView: SurfaceViewRenderer
+
     var interactionVOId: Int = -1
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
+        setStatusBarOrScreenStatus(this)
         //eventbus
         if(!EventBus.getDefault().isRegistered(this)){
             EventBus.getDefault().register(this)
@@ -43,6 +55,7 @@ class VideoActivity:Activity(){
         val rootView = layoutInflater.inflate(R.layout.activity_video, null, false)
         /**初始化Databinding对象*/
         mViewBinding = DataBindingUtil.bind(rootView)
+
         //初始化RTC引擎
         try {
             gEngineKit = SkyEngineKit.Instance()
@@ -59,14 +72,125 @@ class VideoActivity:Activity(){
         //当前对话id
         interactionVOId = intent.getIntExtra("iaId",-1)
 
+        didCreateLocalVideoTrack()
+
         //挂断按钮
         iv_handoff.setOnClickListener {
             val tcpModel = VideoUtil.handOff(interactionVOId)
             TcpClient.getInstance().sendMsg(tcpModel.toJson())
             Handler().postDelayed({
+                DeviceChannel.calling = false
                 finish()
             },1000)
         }
+
+        //小窗切换
+        pip_video_view.setOnClickListener {
+            val isFullScreenRemote = fullscreen_video_view.getChildAt(0) === remoteSurfaceView
+            fullscreen_video_view.removeAllViews()
+            pip_video_view.removeAllViews()
+            if (isFullScreenRemote) {
+                remoteSurfaceView.setZOrderMediaOverlay(true)
+                pip_video_view.addView(remoteSurfaceView)
+                localSurfaceView.setZOrderMediaOverlay(false)
+                fullscreen_video_view.addView(localSurfaceView)
+            } else {
+                localSurfaceView.setZOrderMediaOverlay(true)
+                pip_video_view.addView(localSurfaceView)
+                remoteSurfaceView.setZOrderMediaOverlay(false)
+                fullscreen_video_view.addView(remoteSurfaceView)
+            }
+        }
+    }
+
+    //创建本地视频
+    fun didCreateLocalVideoTrack() {
+        if (localSurfaceView == null) {
+            val surfaceView = gEngineKit.currentSession.setupLocalVideo(true)
+            localSurfaceView = if (surfaceView != null) {
+                surfaceView as SurfaceViewRenderer
+            } else {
+                finish()
+                return
+            }
+        } else {
+            localSurfaceView.setZOrderMediaOverlay(true)
+        }
+        Log.d(TAG,
+                "didCreateLocalVideoTrack localSurfaceView != null is " + (localSurfaceView != null) + "; remoteSurfaceView == null = " + (remoteSurfaceView == null)
+        )
+        if (localSurfaceView.parent != null) {
+            (localSurfaceView.parent as ViewGroup).removeView(localSurfaceView)
+        }
+        if (remoteSurfaceView == null) {
+            if (fullscreen_video_view != null && fullscreen_video_view.getChildCount() != 0) fullscreen_video_view.removeAllViews()
+            fullscreen_video_view.addView(localSurfaceView)
+        } else {
+            if (pip_video_view.getChildCount() != 0) pip_video_view.removeAllViews()
+            pip_video_view.addView(localSurfaceView)
+        }
+    }
+
+    //创建远端视频
+    fun didReceiveRemoteVideoTrack(userId: String?) {
+        pip_video_view.setVisibility(View.VISIBLE)
+        if (localSurfaceView != null) {
+            localSurfaceView.setZOrderMediaOverlay(true)
+            if (localSurfaceView.parent != null) {
+                (localSurfaceView.parent as ViewGroup).removeView(localSurfaceView)
+            }
+            pip_video_view.addView(localSurfaceView)
+        }
+        val surfaceView = gEngineKit.currentSession.setupRemoteVideo(userId, false)
+        Log.d(TAG, "didReceiveRemoteVideoTrack,surfaceView = $surfaceView")
+        if (surfaceView != null) {
+            fullscreen_video_view.setVisibility(View.VISIBLE)
+            remoteSurfaceView = surfaceView as SurfaceViewRenderer
+            fullscreen_video_view.removeAllViews()
+            if (remoteSurfaceView.parent != null) {
+                (remoteSurfaceView.parent as ViewGroup).removeView(remoteSurfaceView)
+            }
+            fullscreen_video_view.addView(remoteSurfaceView)
+        }
+    }
+
+
+    @TargetApi(19)
+    private fun getSystemUiVisibility(): Int {
+        var flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or
+                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+            flags = flags or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
+        }
+        return flags
+    }
+    /**
+     * 设置状态栏透明
+     */
+    @TargetApi(19)
+    fun setStatusBarOrScreenStatus(activity: Activity) {
+        val window = activity.window
+        //全屏+锁屏+常亮显示
+        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN or
+                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
+                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
+                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
+        window.decorView.systemUiVisibility = getSystemUiVisibility()
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+            val layoutParams = getWindow().attributes
+            layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
+            window.attributes = layoutParams
+        }
+        // 5.0以上系统状态栏透明
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            //清除透明状态栏
+            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
+            //设置状态栏颜色必须添加
+            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
+            window.statusBarColor = Color.TRANSPARENT //设置透明
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //19
+            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
+        }
     }
 
     override fun onDestroy() {
@@ -87,6 +211,7 @@ class VideoActivity:Activity(){
             when (tcpModel.action){
                 TcpAction.VideoAction.REJECT->{
                     showMessage("对方拒绝")
+                    DeviceChannel.calling = false
                     AppTool.Time.delay(1500){
                         finish()
                     }
@@ -109,13 +234,14 @@ class VideoActivity:Activity(){
                 }
                 TcpAction.VideoAction.HANDOFF->{
                     showMessage("已挂断")
+                    DeviceChannel.calling = false
                     gEngineKit.leaveRoom()
                     Handler().postDelayed({
                         finish()
                     },1000)
                 }
                 TcpAction.VideoAction.VIDEO_ON->{
-
+                    didReceiveRemoteVideoTrack(""+tcpModel.fromId)
                 }
             }
         }

+ 0 - 279
home/src/main/code/com/wdkl/ncs/android/component/home/activity/WebRTCVoipAudioActivity.kt

@@ -1,279 +0,0 @@
-package com.wdkl.ncs.android.component.home.activity
-
-import android.app.Activity
-import android.bluetooth.BluetoothAdapter
-import android.bluetooth.BluetoothHeadset
-import android.media.AudioManager
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.os.Handler
-import android.os.SystemClock
-import android.util.Log
-import android.view.KeyEvent
-import android.view.View
-import com.google.gson.Gson
-import com.wdkl.core.voip.VoipEvent
-import com.wdkl.ncs.android.component.home.R
-import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
-import com.wdkl.ncs.android.component.nursehome.common.Constants
-import com.wdkl.ncs.android.lib.utils.AppTool
-import com.wdkl.ncs.android.lib.utils.showMessage
-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.VoiceUtil
-import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
-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.MessageEvent
-import com.wdkl.skywebrtc.SkyEngineKit
-import com.wdkl.skywebrtc.except.NotInitializedException
-import kotlinx.android.synthetic.main.activity_sip_voip_audio.bao_mother_name_tv
-import kotlinx.android.synthetic.main.activity_sip_voip_audio.call_duration_tv
-import kotlinx.android.synthetic.main.activity_sip_voip_audio.hang_up_imagev
-import kotlinx.android.synthetic.main.activity_sip_voip_audio.room_number_tv
-import kotlinx.android.synthetic.main.activity_web_rtc_voip_audio.*
-import org.greenrobot.eventbus.EventBus
-import org.greenrobot.eventbus.Subscribe
-import org.greenrobot.eventbus.ThreadMode
-import java.util.*
-
-class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
-    var TAG = WebRTCVoipAudioActivity::class.java.simpleName
-
-    var ACTION = "ACTION"
-    var RING = "RING"
-    var CALLING = "CALLING"
-    var CALL = "CALL"
-    private var action: String? = null
-    private var targetId: String? = null
-    var tcpModel = TcpModel()
-
-    private var gEngineKit: SkyEngineKit? = null
-    private var handsFree:Boolean = false  //免提状态
-
-    private var CALL_TIMEOUT = 2 //多久可以再次点击
-    //呼叫倒计时
-    lateinit var countDownTimer: CountDownTimer
-    private var isClick = false //是否可点击
-
-
-    override fun onCreate(savedInstanceState: Bundle?) {
-        super.onCreate(savedInstanceState)
-//        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
-//                WindowManager.LayoutParams.FLAG_FULLSCREEN)
-        setContentView(R.layout.activity_web_rtc_voip_audio)
-        if (!EventBus.getDefault().isRegistered(this)) {
-            EventBus.getDefault().register(this)
-        }
-        MediaPlayHelper.getInstance().stopMusic()
-        initCountDownTimer()
-        countDownTimer.start()
-
-        //设置为通话状态 有其他用户输入时 DeviceChannel设置返回通话中
-        DeviceChannel.calling = true
-        init()
-
-        try {
-            gEngineKit = SkyEngineKit.Instance()
-        } catch (e: NotInitializedException) {
-            SkyEngineKit.init(VoipEvent()) //重新初始化
-            try {
-                gEngineKit = SkyEngineKit.Instance()
-            } catch (ex: NotInitializedException) {
-                finish()
-            }
-        }
-
-        targetId = intent.getStringExtra("targetId")
-        Log.i(TAG, "SIP账号$targetId")
-        tcpModel = intent.getSerializableExtra("TcpModel") as TcpModel
-        action = intent.getStringExtra(ACTION)
-
-        Log.i(TAG, "tcpModel" + tcpModel.action)
-
-        if (tcpModel.type == TcpType.VOICE) {
-            if (tcpModel.action === TcpAction.VoiceAction.CALL) {
-                val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-                room_number_tv.text = interactionVO.fromFrameFullName
-                bao_mother_name_tv.setText(interactionVO.fromMemberName)
-            } else if (tcpModel.action === TcpAction.VoiceAction.SUCCESS) {
-                val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-                room_number_tv.text = interactionVO.toFrameFullName
-                bao_mother_name_tv.setText(interactionVO.toMemberName)
-            }
-        }
-
-        if (action == CALLING) {
-            Log.i(TAG, "自己同意 拨打过去。。。")
-            createCallout()
-
-            call_duration_tv.visibility = View.VISIBLE
-            call_duration_tv.text = "连接中...."
-
-        } else if (action == RING) {
-            Log.i(TAG, "接电话。。。")
-        } else if (action == CALL) { //主动拨出,服务端回复success时
-            MediaPlayHelper.getInstance().playResMusic(R.raw.outgoing_call, 0.6f, true)
-        }
-    }
-
-    override fun onStart() {
-        super.onStart()
-    }
-
-    fun init() {
-        hang_up_imagev.setOnClickListener(this)
-        hands_free_image.setOnClickListener(this)
-    }
-
-    fun createCallout(){
-        Handler().postDelayed({
-            call_duration_tv.base = SystemClock.elapsedRealtime()
-            call_duration_tv.start()
-        }, 2900)
-
-        var room = UUID.randomUUID().toString() + System.currentTimeMillis()
-        Log.i(TAG, "生成的房间号room " + room + "sipid targetId" + targetId)
-
-        val b = gEngineKit?.startOutCall(applicationContext, room, targetId, true)
-        val session = gEngineKit?.getCurrentSession()
-        Handler().postDelayed({
-            //防止建立连接的时候 不能成功切换外音
-            session?.toggleSpeaker(true)
-        }, 3500)
-    }
-
-    override fun onClick(p0: View?) {
-        when (p0?.id) {
-            R.id.hang_up_imagev -> {
-                handOffCall()
-            }
-            R.id.hands_free_image -> {
-                Log.i(TAG,"声音切换点击")
-                if (!handsFree) {
-                    hands_free_image.setImageResource(R.drawable.av_handfree_hover)
-                    val session = gEngineKit?.getCurrentSession()
-                    if (session != null) {
-                        session?.toggleSpeaker(true)
-                    }
-                    handsFree = true
-                } else {
-                    hands_free_image.setImageResource(R.drawable.av_handfree)
-                    val session = gEngineKit?.getCurrentSession()
-                    if (session != null) {
-                        session?.toggleSpeaker(false)
-                    }
-                    handsFree = false
-                }
-            }
-        }
-    }
-
-    fun handOffCall(){
-        if(!isClick)return
-
-        var interactionVO: InteractionVO? = null
-        if (tcpModel.data.javaClass.name == String::class.java.name) {
-            interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-        } else {
-            interactionVO = tcpModel.data as InteractionVO
-        }
-        Log.i(TAG, "tcpModel" + interactionVO!!.id!!)
-        Log.i(TAG, "tcpModel" + tcpModel.toJson())
-
-        //给服务器发送挂断 tcp
-        if (tcpModel.type == TcpType.VOICE) {
-            if (tcpModel.action === TcpAction.VoiceAction.SUCCESS) {
-                val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Constants.deviceId, tcpModel.toId, interactionVO.id)
-                TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-            } else if (tcpModel.action === TcpAction.VoiceAction.CALL) {
-                val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Constants.deviceId, tcpModel.fromId, interactionVO.id)
-                TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-            }
-
-            //webrtc
-            val session = gEngineKit?.getCurrentSession()
-            if (session != null) {
-                session.leave()
-            }
-            finish()
-        }
-    }
-
-    fun initCountDownTimer() {
-        countDownTimer = object : CountDownTimer(CALL_TIMEOUT * 1000L, 1000) {
-            override fun onTick(millisUntilFinished: Long) {
-            }
-            override fun onFinish() {
-                isClick = true
-            }
-        }
-    }
-
-    @Subscribe(threadMode = ThreadMode.MAIN)
-    fun onMoonEvent(messageEvent: MessageEvent) {
-        if (messageEvent.tag == 2) {
-
-            val tcpModel = messageEvent.getMessage() as TcpModel
-            Log.i(TAG, "收到数据 " + tcpModel.toJson())
-            if (tcpModel.action === TcpAction.VoiceAction.ACCEPT) {
-                MediaPlayHelper.getInstance().stopMusic()
-                Log.i(TAG, "对方接听电话啦")
-                call_duration_tv.visibility = View.VISIBLE
-                call_duration_tv.text = "连接中...."
-                createCallout()
-            } else if (tcpModel.action == TcpAction.VoiceAction.HANDOFF) { //对方挂断
-                call_duration_tv.stop()
-                val session = gEngineKit?.getCurrentSession()
-                if (session != null) {
-                    session.leave()
-                }
-                DeviceChannel.calling = false;
-                finish()
-            } else if (tcpModel.action === TcpAction.VoiceAction.REJECT) {
-                //voiceStatus.setText("对方拒绝接听");
-                showMessage("对方拒绝接听")
-                MediaPlayHelper.getInstance().stopMusic()
-                DeviceChannel.calling = false;
-                finish()
-            } else if (tcpModel.action === TcpAction.VoiceAction.CALLING) {
-                //voiceStatus.setText("对方正在通话");
-                showMessage("对方正在通话")
-                DeviceChannel.calling = false;
-                AppTool.Time.delay(3000) {
-                    MediaPlayHelper.getInstance().stopMusic()
-                    finish()
-                }
-            } else if (tcpModel.action === TcpAction.VoiceAction.FAILED) {
-                //voiceStatus.setText("对方拒绝");
-                showMessage("呼叫失败,对方可能不在线")
-                DeviceChannel.calling = false;
-                MediaPlayHelper.getInstance().stopMusic()
-                finish()
-            }
-        }
-    }
-
-    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
-        Log.i(TAG, "keyup keyCode " + keyCode)
-        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK){
-            handOffCall()
-        } else if (keyCode == KeyEvent.KEYCODE_BACK) {
-//            Toast.makeText(this, "按下了back键   onKeyDown()", Toast.LENGTH_SHORT).show()
-            return false
-        }
-        return super.onKeyDown(keyCode, event)
-    }
-
-    override fun onDestroy() {
-        super.onDestroy()
-        //todo 状态设置为未在通话中
-        DeviceChannel.calling = false
-        if(countDownTimer != null){
-            countDownTimer.cancel()
-        }
-        MediaPlayHelper.getInstance().stopMusic()
-        EventBus.getDefault().unregister(this)
-    }
-}

+ 0 - 236
home/src/main/code/com/wdkl/ncs/android/component/home/activity/WebRTCVoipAudioRingingActivity.kt

@@ -1,236 +0,0 @@
-package com.wdkl.ncs.android.component.home.activity
-
-import android.app.Activity
-import android.content.ComponentName
-import android.content.Context
-import android.content.Intent
-import android.media.AudioManager
-import android.media.session.MediaSession
-import android.os.Bundle
-import android.os.CountDownTimer
-import android.os.VibrationEffect
-import android.os.Vibrator
-import android.support.v4.media.session.MediaSessionCompat
-import android.text.TextUtils
-import android.util.Log
-import android.view.KeyEvent
-import android.view.View
-import com.google.gson.Gson
-import com.wdkl.core.voip.AsyncPlayer
-import com.wdkl.ncs.android.component.home.R
-import com.wdkl.ncs.android.component.home.settingconfig.SettingConfig
-import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
-import com.wdkl.ncs.android.component.nursehome.common.Constants
-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.VoiceUtil
-import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
-import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
-import com.wdkl.ncs.android.middleware.utils.MessageEvent
-import kotlinx.android.synthetic.main.activity_sip_voip_audio_ringing.*
-import org.greenrobot.eventbus.EventBus
-import org.greenrobot.eventbus.Subscribe
-import org.greenrobot.eventbus.ThreadMode
-
-class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
-    var TAG = WebRTCVoipAudioRingingActivity::class.java.simpleName
-
-    private var targetId: String? = null
-    private var interactionVO = InteractionVO()
-    private var tcpModel = TcpModel()
-
-    private var countDownTimer: CountDownTimer? = null//倒计时控制器
-    private var countdownTime = 15//默认转接时间
-    private var isAnswerOrHangUp = false//加一个变量防止在最后一秒点击了接听或者挂断 还是会转发出去
-    lateinit var mVibrator: Vibrator
-//    lateinit var asyncPlayer: AsyncPlayer
-
-    override fun onCreate(savedInstanceState: Bundle?) {
-        super.onCreate(savedInstanceState)
-//        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
-//                WindowManager.LayoutParams.FLAG_FULLSCREEN)
-        setContentView(R.layout.activity_web_rtc_voip_audio_ringing)
-        //todo 设置为通话状态 有其他用户输入时 DeviceChannel设置返回通话中
-        DeviceChannel.calling = true
-
-        targetId = intent.getStringExtra("targetId")
-        tcpModel = intent.getSerializableExtra("TcpModel") as TcpModel
-        interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-        init()
-
-        //震动
-        mVibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
-        mVibrator.cancel()
-        //开启振动后 等待0.1s振动 振动2s 等待1s 振动2s 等待1s
-        val pattern = longArrayOf(100, 2000, 1000, 2000, 1000, 2000)
-        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
-            mVibrator.vibrate(VibrationEffect.createWaveform(pattern, 0))
-        } else {
-            mVibrator.vibrate(pattern, 0)
-        }
-
-        initCountDownTimer()
-        //没有护士说明是其他角色 不要转接功能
-        if (!Constants.userRoleName!!.contains("护士")) {
-            change_over_relayout.setVisibility(View.GONE)
-        } else {
-            // 是护士才开启自动转接
-            countDownTimer?.start()
-        }
-//        asyncPlayer = AsyncPlayer(TAG)
-//        asyncPlayer.play(this,R.raw.incoming_call,true, AudioManager.STREAM_MUSIC)
-        MediaPlayHelper.getInstance().playResMusic(R.raw.incoming_call, 1.0f, true)
-    }
-
-    fun init(){
-        room_number_tv.text =  interactionVO.fromFrameFullName
-        bao_mother_name_tv.text = interactionVO.getFromMemberName()
-
-        change_over_relayout.setOnClickListener(this)
-        hang_up_imagev.setOnClickListener(this)
-        call_the_voice_imagev.setOnClickListener(this)
-    }
-
-    override fun onStart() {
-        super.onStart()
-        if(!EventBus.getDefault().isRegistered(this)) {
-            EventBus.getDefault().register(this)
-        }
-    }
-
-    override fun onClick(p0: View?) {
-        when(p0?.id){
-            R.id.change_over_relayout ->{
-                MediaPlayHelper.getInstance().stopMusic()
-                countDownTimer?.cancel()
-                //todo 给服务器发送转接 tcp
-                DeviceChannel.calling = false
-                val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-                val voiceTransferTcpModel = VoiceUtil.voiceTransfer(Constants.deviceId, tcpModel.fromId, interactionVO)
-                TcpClient.getInstance().sendMsg(voiceTransferTcpModel.toJson())
-                mVibrator.cancel()
-//                asyncPlayer.stop()
-                finish()
-            }
-            R.id.hang_up_imagev ->{
-                rejectCall()
-            }
-            R.id.call_the_voice_imagev ->{
-                answerCall()
-            }
-        }
-    }
-
-    fun rejectCall(){
-        DeviceChannel.calling = false
-        isAnswerOrHangUp = true
-        MediaPlayHelper.getInstance().stopMusic()
-        countDownTimer?.cancel()
-        //t给服务器发送拒接 tcp
-        val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-        val voiceUtilTcpModel = VoiceUtil.voiceReject(Constants.deviceId, tcpModel.fromId, interactionVO.id)
-        TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-        mVibrator.cancel()
-//        asyncPlayer.stop()
-        finish()
-    }
-
-    fun answerCall(){
-//        asyncPlayer.stop()
-        DeviceChannel.calling = true
-        isAnswerOrHangUp = true
-        MediaPlayHelper.getInstance().stopMusic()
-        countDownTimer?.cancel()
-        //给服务器发送接听 tcp
-        val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-        val voiceUtilTcpModel = VoiceUtil.voiceAccept(Constants.deviceId, tcpModel.fromId, interactionVO.id)
-        TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-        mVibrator.cancel()
-        val intent = Intent(this, WebRTCVoipAudioActivity::class.java)
-        intent.putExtra("targetId", targetId)
-        intent.putExtra("TcpModel", tcpModel)
-        intent.putExtra(WebRTCVoipAudioActivity().ACTION, WebRTCVoipAudioActivity().CALLING)
-        startActivity(intent)
-        finish()
-    }
-
-    private fun initCountDownTimer() {
-
-        countdownTime = SettingConfig.getCountdownTime(this)
-        countDownTimer = object : CountDownTimer((countdownTime * 1000).toLong(), 1000) {
-            override fun onTick(l: Long) {
-
-            }
-
-            override fun onFinish() {
-                if (isAnswerOrHangUp) return
-                DeviceChannel.calling = false
-                Log.i(TAG, "时间到 转发了")
-                MediaPlayHelper.getInstance().stopMusic()
-                //todo 给服务器发送转接 tcp
-                val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-                val voiceTransferTcpModel = VoiceUtil.voiceTransfer(Constants.deviceId, tcpModel.fromId, interactionVO)
-                TcpClient.getInstance().sendMsg(voiceTransferTcpModel.toJson())
-                mVibrator.cancel()
-//                asyncPlayer.stop()
-                 finish()
-            }
-        }
-
-    }
-
-    override fun onStop() {
-        super.onStop()
-    }
-
-
-    override fun onBackPressed() {
-    }
-
-    override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
-        Log.i(TAG, "keyup keyCode " + keyCode)
-        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK){
-            answerCall()
-        }
-        return if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
-            true
-        } else {
-            super.onKeyUp(keyCode, event)
-            //继续执行父类其他点击事件
-        }
-    }
-
-    @Subscribe(threadMode = ThreadMode.MAIN)
-    fun onMoonEvent(messageEvent: MessageEvent) {
-        if (messageEvent.tag == 2) {
-            val tcpModel = messageEvent.getMessage() as TcpModel?
-            Log.i(TAG,"收到tcp"+tcpModel!!.action)
-            if (tcpModel!!.action === TcpAction.VoiceAction.CANCEL || tcpModel!!.action === TcpAction.VoiceAction.HANDOFF) {
-                //对方取消;
-                countDownTimer?.cancel()
-                MediaPlayHelper.getInstance().stopMusic()
-                mVibrator.cancel()
-                DeviceChannel.calling = false
-//                asyncPlayer.stop()
-                finish()
-            }
-        } else if (messageEvent.tag == Constants.EVENT_BLUETOOTH_ACCEPT_CALL){
-            answerCall()
-        }
-    }
-
-    override fun onDestroy() {
-        super.onDestroy()
-
-        isAnswerOrHangUp = false
-        if (countDownTimer != null) {
-            countDownTimer?.cancel()
-        }
-
-//        asyncPlayer.stop()
-        MediaPlayHelper.getInstance().stopMusic()
-        mVibrator.cancel()
-        EventBus.getDefault().unregister(this)
-    }
-}

+ 10 - 10
home/src/main/code/com/wdkl/ncs/android/component/home/service/TcpHandleService.kt

@@ -71,19 +71,19 @@ class TcpHandleService : Service(){
 
                     if (tcpModel.action == TcpAction.VoiceAction.SUCCESS){  //拨出成功
                         DeviceChannel.calling = true;
-                        intent.setClass(this, WebRTCVoipAudioActivity::class.java)
-                        intent.putExtra("targetId", interactionVO?.toSipId)
-                        intent.putExtra("TcpModel", tcpModel)
-                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-                        intent.putExtra(WebRTCVoipAudioActivity().ACTION, WebRTCVoipAudioActivity().CALL)
+//                        intent.setClass(this, WebRTCVoipAudioActivity::class.java)
+//                        intent.putExtra("targetId", interactionVO?.toSipId)
+//                        intent.putExtra("TcpModel", tcpModel)
+//                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+//                        intent.putExtra(WebRTCVoipAudioActivity().ACTION, WebRTCVoipAudioActivity().CALL)
                         startActivity(intent)
                     } else if (tcpModel.action == TcpAction.VoiceAction.CALL){  //有来电
                         DeviceChannel.calling = true;
-                        intent.setClass(this, WebRTCVoipAudioRingingActivity::class.java)
-                        intent.putExtra("targetId", interactionVO?.fromSipId)
-                        intent.putExtra("TcpModel", tcpModel)
-                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-                        startActivity(intent)
+//                        intent.setClass(this, WebRTCVoipAudioRingingActivity::class.java)
+//                        intent.putExtra("targetId", interactionVO?.fromSipId)
+//                        intent.putExtra("TcpModel", tcpModel)
+//                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+//                        startActivity(intent)
                     }
                 }
             }

+ 60 - 34
home/src/main/res/layout/activity_video.xml

@@ -1,43 +1,69 @@
 <?xml version="1.0" encoding="utf-8"?>
-<layout>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<layout xmlns:tools="http://schemas.android.com/tools">
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:background="@android:color/black"
+    tools:ignore="MergeRootFrame"
     android:keepScreenOn="true">
 
-    <LinearLayout
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignParentBottom="true"
-        android:gravity="center_horizontal"
-        android:layout_marginBottom="11dp"
-        android:orientation="vertical">
-
-        <Chronometer
-            android:id="@+id/call_duration_tv"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center_horizontal"
-            android:text="00:00"
-            android:textSize="12sp"
-            android:visibility="gone"/>
-
-        <TextView
-            android:id="@+id/tv_connecting"
-            android:text="呼叫中"
-            android:textSize="14dp"
-            android:visibility="gone"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"/>
-
-        <ImageView
-            android:id="@+id/iv_handoff"
-            android:layout_width="wrap_content"
+    <FrameLayout
+        android:id="@+id/fullscreen_video_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_gravity="center" />
+
+    <FrameLayout
+        android:id="@+id/pip_video_view"
+        android:layout_width="100dp"
+        android:layout_height="140dp"
+        android:layout_gravity="top|end"
+        android:layout_marginHorizontal="10dp"
+        android:layout_marginTop="10dp" />
+
+    <RelativeLayout
+        android:id="@+id/lytParent"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="@android:color/transparent">
+
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="13dp"
-            android:src="@drawable/yu_yin_gua_duan" />
+            android:layout_alignParentBottom="true"
+            android:gravity="center_horizontal"
+            android:layout_marginBottom="11dp"
+            android:orientation="vertical">
+
+            <Chronometer
+                android:id="@+id/call_duration_tv"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_horizontal"
+                android:text="00:00"
+                android:textSize="12dp"
+                android:textColor="#FFFFFF"
+                android:visibility="gone"/>
+
+            <TextView
+                android:id="@+id/tv_connecting"
+                android:text="呼叫中"
+                android:textSize="14dp"
+                android:visibility="gone"
+                android:textColor="#FFFFFF"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+
+            <ImageView
+                android:id="@+id/iv_handoff"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="13dp"
+                android:src="@drawable/yu_yin_gua_duan" />
+
+        </LinearLayout>
 
-    </LinearLayout>
+    </RelativeLayout>
 
-</LinearLayout>
+</FrameLayout>
 </layout>

+ 5 - 1
rtc-chat/src/main/java/com/wdkl/skywebrtc/SkyEngineKit.java

@@ -146,6 +146,10 @@ public class SkyEngineKit {
 
     // 加入房间
     public void joinRoom(Context context, String room) {
+        joinRoom(context, room, false);
+    }
+
+    public void joinRoom(Context context, String room, Boolean audioOnly){
         if (avEngineKit == null) {
             Log.e(TAG, "joinRoom error,init is not set");
             return;
@@ -155,7 +159,7 @@ public class SkyEngineKit {
             Log.e(TAG, "joinRoom error,currentCallSession is exist");
             return;
         }
-        mCurrentCallSession = new CallSession(context, room, false, mEvent);
+        mCurrentCallSession = new CallSession(context, room, audioOnly, mEvent);
         mCurrentCallSession.setIsComing(true);
         mCurrentCallSession.joinHome(room);
     }