|
@@ -12,6 +12,7 @@ import com.wdkl.ncs.android.component.nursehome.activity.NurseHomeActivity
|
|
|
import com.wdkl.ncs.android.component.nursehome.adapter.AudioBroadcastAdapter
|
|
|
import com.wdkl.ncs.android.component.nursehome.databinding.FragmentBroadcastBinding
|
|
|
import com.wdkl.ncs.android.component.nursehome.launch.NurseHomeLaunch
|
|
|
+import com.wdkl.ncs.android.component.nursehome.settingconfig.SettingConfig
|
|
|
import com.wdkl.ncs.android.lib.base.BaseFragment
|
|
|
import com.wdkl.ncs.android.lib.utils.showMessage
|
|
|
import com.wdkl.ncs.android.middleware.common.Constants
|
|
@@ -25,10 +26,14 @@ 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.ncs.host.service.WdklSipService
|
|
|
import kotlinx.android.synthetic.main.fragment_broadcast.*
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
|
+import org.linphone.core.CallParams
|
|
|
+import org.linphone.core.Core
|
|
|
+import org.linphone.core.MediaEncryption
|
|
|
|
|
|
/**
|
|
|
* 广播管理界面
|
|
@@ -38,10 +43,11 @@ class BroadcastFragment : BaseFragment<BroadcastPresenter, FragmentBroadcastBind
|
|
|
|
|
|
var audioBcAdapter: AudioBroadcastAdapter? = null
|
|
|
|
|
|
- private var bcVoiceOn = false
|
|
|
private var initDone = false
|
|
|
private var clickTime: Long = 0
|
|
|
|
|
|
+ var core: Core? = null
|
|
|
+
|
|
|
/**
|
|
|
* 提供layoutID
|
|
|
*/
|
|
@@ -99,6 +105,10 @@ class BroadcastFragment : BaseFragment<BroadcastPresenter, FragmentBroadcastBind
|
|
|
}
|
|
|
|
|
|
btn_record.setOnClickListener {
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
+ return@setOnClickListener
|
|
|
+ }
|
|
|
+
|
|
|
if (!Constants.gstreamer_init) {
|
|
|
tv_broadcast_title.setText(R.string.broadcast_init_error)
|
|
|
showMessage(R.string.broadcast_init_error)
|
|
@@ -106,12 +116,12 @@ class BroadcastFragment : BaseFragment<BroadcastPresenter, FragmentBroadcastBind
|
|
|
tv_broadcast_title.setText(R.string.broadcast_start_warning)
|
|
|
showMessage(R.string.broadcast_start_warning)
|
|
|
} else {
|
|
|
- if (!bcVoiceOn) {
|
|
|
+ if (!Constants.bcVoiceOn) {
|
|
|
//start broadcast
|
|
|
tv_broadcast_title.setText(R.string.broadcast_playing)
|
|
|
btn_record.setImageResource(R.drawable.mic_off)
|
|
|
tv_record.setText(R.string.broadcast_record_stop)
|
|
|
- bcVoiceOn = true
|
|
|
+ Constants.bcVoiceOn = true
|
|
|
|
|
|
MyGStreamManager.getInstance().play()
|
|
|
my_voice_load_view.start()
|
|
@@ -120,7 +130,7 @@ class BroadcastFragment : BaseFragment<BroadcastPresenter, FragmentBroadcastBind
|
|
|
tv_broadcast_title.setText(R.string.broadcast_stop)
|
|
|
btn_record.setImageResource(R.drawable.mic_on)
|
|
|
tv_record.setText(R.string.broadcast_record_start)
|
|
|
- bcVoiceOn = false
|
|
|
+ Constants.bcVoiceOn = false
|
|
|
|
|
|
MyGStreamManager.getInstance().pause()
|
|
|
my_voice_load_view.stop()
|
|
@@ -131,56 +141,105 @@ class BroadcastFragment : BaseFragment<BroadcastPresenter, FragmentBroadcastBind
|
|
|
btn_broadcast.setOnClickListener {
|
|
|
if (Constants.bcStart) {
|
|
|
showMessage(R.string.broadcast_playing)
|
|
|
- } else if (!Constants.gstreamer_init) {
|
|
|
- tv_broadcast_title.setText(R.string.broadcast_init_error)
|
|
|
- } else {
|
|
|
- MyGStreamManager.getInstance().setCallBack(object : MyGStreamManager.StreamerCallBack {
|
|
|
- override fun onMessage(message: String?) {
|
|
|
- Log.d(TAG, "广播 ==> onMessage: $message")
|
|
|
- }
|
|
|
+ return@setOnClickListener
|
|
|
+ }
|
|
|
|
|
|
- override fun onStreamerInitialized() {
|
|
|
- Log.d(TAG, "广播 ==> 初始化完成...开始喊话")
|
|
|
- initDone = true
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
+ val tcpModel = BroadcastUtil.startVoiceBroadcast(Constants.ids, "[0]") //给所有分机设备发
|
|
|
+ val transaction = object : TcpCallback(tcpModel.tid) {
|
|
|
+ override fun onSuccess(jsonObject: JSONObject) {
|
|
|
+ try {
|
|
|
+ val port = jsonObject.get(CALLBACK_DATA)
|
|
|
+ core = WdklSipService.getCore()
|
|
|
+ val addressToCall = core?.interpretUrl(port.toString())
|
|
|
+ val params = core?.createCallParams(null)
|
|
|
+ params?.isVideoEnabled = false
|
|
|
+ if (addressToCall != null) {
|
|
|
+ Log.e(TAG, "addressToCall: " + addressToCall.asString() + ", param: " + params.toString())
|
|
|
+ core?.inviteAddressWithParams(addressToCall, params!!)
|
|
|
+ }
|
|
|
+ } catch (ex: Exception) {
|
|
|
+ ex.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ override fun onFailed(jsonObject: JSONObject) {
|
|
|
+ // 这里写发送失败的方法
|
|
|
activity.runOnUiThread {
|
|
|
- tv_broadcast_title.setText(R.string.broadcast_playing)
|
|
|
- btn_record.setImageResource(R.drawable.mic_off)
|
|
|
- tv_record.setText(R.string.broadcast_record_stop)
|
|
|
- btn_broadcast.setText(R.string.broadcast_exit)
|
|
|
- my_voice_load_view.start()
|
|
|
- showMessage(R.string.broadcast_record_start)
|
|
|
- bcVoiceOn = true
|
|
|
+ showMessage("broadcast send fail")
|
|
|
}
|
|
|
-
|
|
|
- MyGStreamManager.getInstance().play()
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
|
|
|
- if (initDone) {
|
|
|
+ if (Constants.bcVoiceOn) {
|
|
|
(activity as NurseHomeActivity).showHome(false)
|
|
|
} else {
|
|
|
- //先发起喊话广播请求,服务端返回端口再初始化
|
|
|
- val tcpModel = BroadcastUtil.startVoiceBroadcast(Constants.ids, "[0]") //给所有分机设备发
|
|
|
- val transaction = object : TcpCallback(tcpModel.tid) {
|
|
|
- override fun onSuccess(jsonObject: JSONObject) {
|
|
|
- try {
|
|
|
- val port = jsonObject.get(CALLBACK_DATA)
|
|
|
- //gstream初始化,指定服务器 IP 和端口
|
|
|
- MyGStreamManager.getInstance().init("host=172.28.100.100 port=" + port)
|
|
|
- } catch (ex: Exception) {
|
|
|
- ex.printStackTrace()
|
|
|
+ tv_broadcast_title.setText(R.string.broadcast_playing)
|
|
|
+ btn_record.setImageResource(R.drawable.mic_off)
|
|
|
+ tv_record.setText(R.string.broadcast_record_stop)
|
|
|
+ btn_broadcast.setText(R.string.broadcast_exit)
|
|
|
+ my_voice_load_view.start()
|
|
|
+ showMessage(R.string.broadcast_record_start)
|
|
|
+ Constants.bcVoiceOn = true
|
|
|
+
|
|
|
+ TcpClient.getInstance().sendTcp(tcpModel, false, transaction)
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //gstream + webrtc喊话广播
|
|
|
+ if (!Constants.gstreamer_init) {
|
|
|
+ tv_broadcast_title.setText(R.string.broadcast_init_error)
|
|
|
+ } else {
|
|
|
+ MyGStreamManager.getInstance()
|
|
|
+ .setCallBack(object : MyGStreamManager.StreamerCallBack {
|
|
|
+ override fun onMessage(message: String?) {
|
|
|
+ Log.d(TAG, "广播 ==> onMessage: $message")
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- override fun onFailed(jsonObject: JSONObject) {
|
|
|
- // 这里写发送失败的方法
|
|
|
- activity.runOnUiThread {
|
|
|
- showMessage("broadcast send fail")
|
|
|
+ override fun onStreamerInitialized() {
|
|
|
+ Log.d(TAG, "广播 ==> 初始化完成...开始喊话")
|
|
|
+ initDone = true
|
|
|
+
|
|
|
+ activity.runOnUiThread {
|
|
|
+ tv_broadcast_title.setText(R.string.broadcast_playing)
|
|
|
+ btn_record.setImageResource(R.drawable.mic_off)
|
|
|
+ tv_record.setText(R.string.broadcast_record_stop)
|
|
|
+ btn_broadcast.setText(R.string.broadcast_exit)
|
|
|
+ my_voice_load_view.start()
|
|
|
+ showMessage(R.string.broadcast_record_start)
|
|
|
+ Constants.bcVoiceOn = true
|
|
|
+ }
|
|
|
+
|
|
|
+ MyGStreamManager.getInstance().play()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (initDone) {
|
|
|
+ (activity as NurseHomeActivity).showHome(false)
|
|
|
+ } else {
|
|
|
+ //先发起喊话广播请求,服务端返回端口再初始化
|
|
|
+ val tcpModel = BroadcastUtil.startVoiceBroadcast(Constants.ids, "[0]") //给所有分机设备发
|
|
|
+ val transaction = object : TcpCallback(tcpModel.tid) {
|
|
|
+ override fun onSuccess(jsonObject: JSONObject) {
|
|
|
+ try {
|
|
|
+ val port = jsonObject.get(CALLBACK_DATA)
|
|
|
+ val uri = "host=" + Constants.media_ip + " port=" + port
|
|
|
+ //gstream初始化,指定服务器 IP 和端口
|
|
|
+ MyGStreamManager.getInstance().init(uri)
|
|
|
+ } catch (ex: Exception) {
|
|
|
+ ex.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailed(jsonObject: JSONObject) {
|
|
|
+ // 这里写发送失败的方法
|
|
|
+ activity.runOnUiThread {
|
|
|
+ showMessage("broadcast send fail")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ TcpClient.getInstance().sendTcp(tcpModel, false, transaction)
|
|
|
}
|
|
|
- TcpClient.getInstance().sendTcp(tcpModel, false, transaction)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -233,11 +292,25 @@ class BroadcastFragment : BaseFragment<BroadcastPresenter, FragmentBroadcastBind
|
|
|
*页面销毁回调
|
|
|
*/
|
|
|
override fun destory() {
|
|
|
- if (initDone && !Constants.bcStart) {
|
|
|
+ if ((initDone || Constants.bcVoiceOn) && !Constants.bcStart) {
|
|
|
val tcpModel = BroadcastUtil.stopBroadcast(Constants.ids, Constants.bcInteractionId)
|
|
|
TcpClient.getInstance().sendMsg(tcpModel.toJson())
|
|
|
}
|
|
|
- MyGStreamManager.getInstance().release()
|
|
|
+ Constants.bcVoiceOn = false
|
|
|
+
|
|
|
+ if (SettingConfig.getSipEnabled(getActivity())) {
|
|
|
+ if (core != null) {
|
|
|
+ if (core!!.callsNb > 0) {
|
|
|
+ var call = core!!.currentCall
|
|
|
+ if (call == null) {
|
|
|
+ call = core!!.calls[0]
|
|
|
+ }
|
|
|
+ call!!.terminate()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ MyGStreamManager.getInstance().release()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|