|
@@ -25,6 +25,7 @@ import com.wdkl.app.ncs.conversion_box.databinding.MainActivityLayoutBinding
|
|
import com.wdkl.app.ncs.conversion_box.fragment.*
|
|
import com.wdkl.app.ncs.conversion_box.fragment.*
|
|
import com.wdkl.app.ncs.conversion_box.helper.*
|
|
import com.wdkl.app.ncs.conversion_box.helper.*
|
|
import com.wdkl.app.ncs.conversion_box.launch.MainLaunch
|
|
import com.wdkl.app.ncs.conversion_box.launch.MainLaunch
|
|
|
|
+import com.wdkl.app.ncs.conversion_box.service.WdklSipService
|
|
import com.wdkl.app.ncs.conversion_box.settings.SettingConfig
|
|
import com.wdkl.app.ncs.conversion_box.settings.SettingConfig
|
|
import com.wdkl.ncs.android.lib.base.BaseActivity
|
|
import com.wdkl.ncs.android.lib.base.BaseActivity
|
|
import com.wdkl.ncs.android.lib.base.BaseApplication
|
|
import com.wdkl.ncs.android.lib.base.BaseApplication
|
|
@@ -68,6 +69,9 @@ import okhttp3.Request
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.Subscribe
|
|
import org.greenrobot.eventbus.Subscribe
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
|
|
+import org.linphone.core.AccountCreator
|
|
|
|
+import org.linphone.core.RegistrationState
|
|
|
|
+import org.linphone.core.TransportType
|
|
import serialporttest.utils.SerialPort485Util
|
|
import serialporttest.utils.SerialPort485Util
|
|
import serialporttest.utils.SerialPortUtil
|
|
import serialporttest.utils.SerialPortUtil
|
|
import java.io.File
|
|
import java.io.File
|
|
@@ -99,6 +103,7 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
private var clickTime : Long = 0
|
|
private var clickTime : Long = 0
|
|
private var clickSosTime : Long = 0
|
|
private var clickSosTime : Long = 0
|
|
|
|
|
|
|
|
+ private var mAccountCreator: AccountCreator? = null
|
|
|
|
|
|
//网络异常计数
|
|
//网络异常计数
|
|
private var netErrCount : Int = 0
|
|
private var netErrCount : Int = 0
|
|
@@ -211,6 +216,20 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
}
|
|
}
|
|
|
|
|
|
SoundPoolManager.getInstance().init()
|
|
SoundPoolManager.getInstance().init()
|
|
|
|
+
|
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
|
+ //启动sip服务
|
|
|
|
+ val serviceIntent = Intent(BaseApplication.appContext, WdklSipService::class.java)
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
+ //android8.0以上通过startForegroundService启动service
|
|
|
|
+ startForegroundService(serviceIntent)
|
|
|
|
+ } else {
|
|
|
|
+ startService(serviceIntent)
|
|
|
|
+ }
|
|
|
|
+ view_title_layout_tv_point.text = "sip"
|
|
|
|
+ } else {
|
|
|
|
+ view_title_layout_tv_point.text = "rtc"
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private fun checkAppExist() : Boolean {
|
|
private fun checkAppExist() : Boolean {
|
|
@@ -603,6 +622,34 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
startTcp()
|
|
startTcp()
|
|
showMessage("tcp connect...host: " + Constant.TCP_SERVER_URL + ", port: " + Constant.TCP_PORT)
|
|
showMessage("tcp connect...host: " + Constant.TCP_SERVER_URL + ", port: " + Constant.TCP_PORT)
|
|
|
|
|
|
|
|
+ if (data.sipIp != null) {
|
|
|
|
+ Constant.sip_ip = data.sipIp
|
|
|
|
+ }
|
|
|
|
+ if (data.sipPort != null) {
|
|
|
|
+ Constant.sip_port = data.sipPort
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (data.voiceType != null) {
|
|
|
|
+ val orgSipEnable = SettingConfig.getSipEnabled(activity)
|
|
|
|
+ if ("sip".equals(data.voiceType)) {
|
|
|
|
+ //使用sip通话
|
|
|
|
+ SettingConfig.setSipEnable(activity, true)
|
|
|
|
+ if (!orgSipEnable) {
|
|
|
|
+ handler.postDelayed({
|
|
|
|
+ AppUpdateHelper.reboot(activity)
|
|
|
|
+ }, 5000)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //使用webrtc通话
|
|
|
|
+ SettingConfig.setSipEnable(activity, false)
|
|
|
|
+ if (orgSipEnable) {
|
|
|
|
+ handler.postDelayed({
|
|
|
|
+ AppUpdateHelper.reboot(activity)
|
|
|
|
+ }, 5000)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
Thread(Runnable {
|
|
Thread(Runnable {
|
|
while (!initialized) {
|
|
while (!initialized) {
|
|
runOnUiThread(Runnable {
|
|
runOnUiThread(Runnable {
|
|
@@ -659,7 +706,9 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
|
|
|
|
//显示设备信息
|
|
//显示设备信息
|
|
override fun showDeviceInfo(deviceInfo: DeviceNurseInfoVO) {
|
|
override fun showDeviceInfo(deviceInfo: DeviceNurseInfoVO) {
|
|
- Constant.SIP_ID = deviceInfo.sipId
|
|
|
|
|
|
+ if (deviceInfo.sipId != null) {
|
|
|
|
+ Constant.SIP_ID = deviceInfo.sipId
|
|
|
|
+ }
|
|
Constant.DEVICE_ID = deviceInfo.id
|
|
Constant.DEVICE_ID = deviceInfo.id
|
|
Constant.PART_ID = deviceInfo.partId
|
|
Constant.PART_ID = deviceInfo.partId
|
|
|
|
|
|
@@ -759,6 +808,38 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
|
|
|
|
//initCallTimer()
|
|
//initCallTimer()
|
|
updateSettings(true)
|
|
updateSettings(true)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
|
+ //配置sip账户
|
|
|
|
+ if (WdklSipService.getCore() != null) {
|
|
|
|
+ mAccountCreator = WdklSipService.getCore().createAccountCreator(null)
|
|
|
|
+ // 以下三项必须
|
|
|
|
+ if (!TextUtils.isEmpty(Constant.SIP_ID) && !TextUtils.isEmpty(Constant.sip_ip)) {
|
|
|
|
+ Log.e(TAG, "sip connect: ${Constant.SIP_ID}@${Constant.sip_ip}:${Constant.sip_port}")
|
|
|
|
+ mAccountCreator!!.setDomain(Constant.sip_ip)
|
|
|
|
+ mAccountCreator!!.setUsername(Constant.SIP_ID)
|
|
|
|
+ mAccountCreator!!.setPassword(Constant.SIP_ID)
|
|
|
|
+ //默认使用udp
|
|
|
|
+ mAccountCreator!!.transport = TransportType.Udp
|
|
|
|
+
|
|
|
|
+ // 这里会自动创建代理配置、认证信息到 SIP核心
|
|
|
|
+ val cfg = mAccountCreator!!.createProxyConfig()
|
|
|
|
+ // 确保新创建的是最新
|
|
|
|
+ WdklSipService.getCore().defaultProxyConfig = cfg
|
|
|
|
+
|
|
|
|
+ /*if (Constants.sip_port != null) {
|
|
|
|
+ var transports = WdklSipService.getCore().transports
|
|
|
|
+ transports.udpPort = Constants.sip_port!!
|
|
|
|
+ transports.tcpPort = Constants.sip_port!!
|
|
|
|
+ transports.tlsPort = -1
|
|
|
|
+ WdklSipService.getCore().transports = transports
|
|
|
|
+ }*/
|
|
|
|
+ } else {
|
|
|
|
+ showMessage("SIP empty")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
override fun loadAppVersion(appInfo: AppVersionDO) {
|
|
override fun loadAppVersion(appInfo: AppVersionDO) {
|
|
@@ -843,8 +924,8 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
} else if (Constant.CALL_STATE == Constant.CALL_INCOMING && addr.equals(curDeviceUart, true)) {
|
|
} else if (Constant.CALL_STATE == Constant.CALL_INCOMING && addr.equals(curDeviceUart, true)) {
|
|
//分机接听
|
|
//分机接听
|
|
RingPlayHelper.stopRingTone()
|
|
RingPlayHelper.stopRingTone()
|
|
- VoiceUtil.acceptAudioCall(tid, curDeviceId, fromId, curInteractionVO!!.id)
|
|
|
|
showCallFragment()
|
|
showCallFragment()
|
|
|
|
+ VoiceUtil.acceptAudioCall(tid, curDeviceId, fromId, curInteractionVO!!.id)
|
|
} else {
|
|
} else {
|
|
//分机呼叫
|
|
//分机呼叫
|
|
startCall(addr)
|
|
startCall(addr)
|
|
@@ -1379,10 +1460,10 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
|
|
|
|
//Sip注册状态
|
|
//Sip注册状态
|
|
Constant.EVENT_SIP_REGISTER_STATUS -> {
|
|
Constant.EVENT_SIP_REGISTER_STATUS -> {
|
|
- if (messageEvent.message is String) run {
|
|
|
|
- val status = messageEvent.message as String
|
|
|
|
- Log.d("sip", "sip regist status: " + status)
|
|
|
|
- updateStatus(status)
|
|
|
|
|
|
+ if (messageEvent.getMessage() is RegistrationState) {
|
|
|
|
+ val state = messageEvent.getMessage() as RegistrationState
|
|
|
|
+ Log.d(TAG, "sip register state: $state")
|
|
|
|
+ //updateSipState(state)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1423,8 +1504,8 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
Constant.CALL_STATE = Constant.CALL_INCOMING
|
|
Constant.CALL_STATE = Constant.CALL_INCOMING
|
|
if (Constant.autoAnswer) {
|
|
if (Constant.autoAnswer) {
|
|
//自动接听
|
|
//自动接听
|
|
- VoiceUtil.acceptAudioCall(tid, tcpModel.toId, fromId, interactionVO?.id)
|
|
|
|
showCallFragment()
|
|
showCallFragment()
|
|
|
|
+ VoiceUtil.acceptAudioCall(tid, tcpModel.toId, fromId, interactionVO?.id)
|
|
} else {
|
|
} else {
|
|
//响铃并手动接听
|
|
//响铃并手动接听
|
|
SerialPortHelper.callInChannel(curDeviceUart)
|
|
SerialPortHelper.callInChannel(curDeviceUart)
|
|
@@ -1449,6 +1530,21 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
if (!TextUtils.isEmpty(doorAddr)) {
|
|
if (!TextUtils.isEmpty(doorAddr)) {
|
|
SerialPortHelper.closeDoorLight(doorAddr)
|
|
SerialPortHelper.closeDoorLight(doorAddr)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ val sipCore = WdklSipService.getCore()
|
|
|
|
+ if (sipCore == null || TextUtils.isEmpty(targetSip)) {
|
|
|
|
+ //通话失败,重置并返回主界面
|
|
|
|
+ showMessage("Core或targetSipId为空!")
|
|
|
|
+ handoffCall()
|
|
|
|
+ } else {
|
|
|
|
+ val addressToCall = sipCore.interpretUrl(targetSip)
|
|
|
|
+ val params = sipCore.createCallParams(null)
|
|
|
|
+ params?.isVideoEnabled = false
|
|
|
|
+ if (addressToCall != null) {
|
|
|
|
+ sipCore.inviteAddressWithParams(addressToCall, params!!)
|
|
|
|
+ Log.d(TAG, ">>>>>>>>>>> invite address: " + addressToCall.asString())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} else if (tcpModel.getAction() == TcpAction.VoiceAction.SUCCESS) {
|
|
} else if (tcpModel.getAction() == TcpAction.VoiceAction.SUCCESS) {
|
|
//呼叫成功
|
|
//呼叫成功
|
|
val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
@@ -1618,8 +1714,8 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
outCallList.remove(ethMac.toUpperCase(Locale.ROOT))
|
|
outCallList.remove(ethMac.toUpperCase(Locale.ROOT))
|
|
}
|
|
}
|
|
RingPlayHelper.stopRingTone()
|
|
RingPlayHelper.stopRingTone()
|
|
- VoiceUtil.acceptAudioCall(tid, curDeviceId, fromId, curInteractionVO!!.id)
|
|
|
|
showCallFragment()
|
|
showCallFragment()
|
|
|
|
+ VoiceUtil.acceptAudioCall(tid, curDeviceId, fromId, curInteractionVO!!.id)
|
|
} else if (tcpModel.action == TcpAction.VoiceAction.RS485HANDOFF) {
|
|
} else if (tcpModel.action == TcpAction.VoiceAction.RS485HANDOFF) {
|
|
/*EventBus.getDefault().post(MessageEvent("handoff", Constant.EVENT_END_CALL))
|
|
/*EventBus.getDefault().post(MessageEvent("handoff", Constant.EVENT_END_CALL))
|
|
Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
Constant.CALL_STATE = Constant.CALL_STANDBY
|
|
@@ -1840,13 +1936,23 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
//模拟分机呼叫特殊性,所有呼叫都是通过转换盒,但是转换盒只有一台,同一时间只能建立一个呼叫,为保证其他分机也能呼叫(不是通话),
|
|
//模拟分机呼叫特殊性,所有呼叫都是通过转换盒,但是转换盒只有一台,同一时间只能建立一个呼叫,为保证其他分机也能呼叫(不是通话),
|
|
//所有模拟分机的通话都由对方来创建room,然后转换盒加入room来通话,所以房间id都是对方的,转换盒是被动加入通话
|
|
//所有模拟分机的通话都由对方来创建room,然后转换盒加入room来通话,所以房间id都是对方的,转换盒是被动加入通话
|
|
if (callFragment == null) {
|
|
if (callFragment == null) {
|
|
- var fragment = CallFragment()
|
|
|
|
- var bundle = Bundle()
|
|
|
|
- bundle.putInt("call_state", 1)
|
|
|
|
- bundle.putBoolean("audio_only", true)
|
|
|
|
- bundle.putString("targetSip", targetSip)
|
|
|
|
- fragment.arguments = bundle
|
|
|
|
- addCallFragment(fragment)
|
|
|
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
|
+ var fragment = SipCallFragment()
|
|
|
|
+ var bundle = Bundle()
|
|
|
|
+ bundle.putInt("call_state", 1)
|
|
|
|
+ bundle.putBoolean("audio_only", true)
|
|
|
|
+ bundle.putString("tcp_tid", tid)
|
|
|
|
+ fragment.arguments = bundle
|
|
|
|
+ addCallFragment(fragment)
|
|
|
|
+ } else {
|
|
|
|
+ var fragment = CallFragment()
|
|
|
|
+ var bundle = Bundle()
|
|
|
|
+ bundle.putInt("call_state", 1)
|
|
|
|
+ bundle.putBoolean("audio_only", true)
|
|
|
|
+ bundle.putString("targetSip", targetSip)
|
|
|
|
+ fragment.arguments = bundle
|
|
|
|
+ addCallFragment(fragment)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1890,6 +1996,33 @@ class MainActivity :BaseActivity<MainActivityPresenter, MainActivityLayoutBindin
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun updateSipState(state: RegistrationState) {
|
|
|
|
+ runOnUiThread {
|
|
|
|
+ when (state) {
|
|
|
|
+ RegistrationState.Ok -> {
|
|
|
|
+ //连接完成
|
|
|
|
+ view_title_layout_tv_point.setBackgroundResource(R.color.green)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ RegistrationState.Failed -> {
|
|
|
|
+ //连接错误
|
|
|
|
+ view_title_layout_tv_point.setBackgroundResource(R.color.red_color)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ RegistrationState.Progress -> {
|
|
|
|
+ //正在连接
|
|
|
|
+ view_title_layout_tv_point.setBackgroundResource(R.color.yellow_color)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ RegistrationState.None, RegistrationState.Cleared -> {
|
|
|
|
+ //默认状态,断开连接
|
|
|
|
+ view_title_layout_tv_point.setBackgroundResource(R.color.register_text_color)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ view_title_layout_tv_point.text = "sip"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private fun updateNetState() {
|
|
private fun updateNetState() {
|
|
if (NetHelper.getInstance().networkType == ConnectivityManager.TYPE_WIFI) {
|
|
if (NetHelper.getInstance().networkType == ConnectivityManager.TYPE_WIFI) {
|
|
view_title_layout_iv_wifi.visibility = View.VISIBLE
|
|
view_title_layout_iv_wifi.visibility = View.VISIBLE
|