Skip to content

Commit

Permalink
hua an customer
Browse files Browse the repository at this point in the history
Change-Id: I6937bf7358c7a6d3377da1cfdf907298e9447cd2
  • Loading branch information
archurtan committed Jul 23, 2021
1 parent e340af8 commit b29ff46
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
18 changes: 16 additions & 2 deletions app/src/main/java/com/tencent/iot/explorer/link/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.tencent.iot.explorer.link.core.auth.message.MessageConst
import com.tencent.iot.explorer.link.core.auth.message.payload.Payload
import com.tencent.iot.explorer.link.core.auth.message.upload.ArrayString
import com.tencent.iot.explorer.link.core.auth.response.*
import com.tencent.iot.explorer.link.core.auth.socket.callback.ConnectionCallback
import com.tencent.iot.explorer.link.core.auth.socket.callback.PayloadMessageCallback
import com.tencent.iot.explorer.link.core.auth.util.JsonManager
import com.tencent.iot.explorer.link.core.auth.util.Weak
Expand All @@ -43,7 +44,8 @@ import kotlin.collections.ArrayList
/**
* APP
*/
class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessageCallback {
class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessageCallback,
ConnectionCallback {

companion object {
//app数据
Expand Down Expand Up @@ -129,13 +131,14 @@ class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessag
super.onCreate()
MultiDex.install(this)
IoTAuth.setWebSocketTag(Utils.getAndroidID(this)) // 设置wss的uin
IoTAuth.setWebSocketCallback(this) // 设置WebSocket连接状态回调
IoTAuth.init(BuildConfig.TencentIotLinkAppkey, BuildConfig.TencentIotLinkAppSecret)
//初始化弹框
T.setContext(this.applicationContext)
//日志开关
L.isLog = DEBUG_VERSION
//日志等级
L.LOG_LEVEL = L.LEVEL_INFO
L.LOG_LEVEL = L.LEVEL_DEBUG
//信鸽推送日志开关
XGPushConfig.enableDebug(applicationContext, DEBUG_VERSION)
XGPushConfig.enablePullUpOtherApp(applicationContext, PULL_OTHER)
Expand Down Expand Up @@ -557,6 +560,17 @@ class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessag

})
}

override fun connected() {
L.d("WebSocket已连接")
if (data.rtcDeviceIdList != null) {
IoTAuth.registerActivePush(data.rtcDeviceIdList!!, null)
}
}

override fun disconnected() {
L.e("WebSocket已断开连接")
}
}

interface AppLifeCircleListener {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/tencent/iot/explorer/link/AppData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.tencent.iot.explorer.link.core.auth.entity.DeviceEntity
import com.tencent.iot.explorer.link.core.auth.entity.FamilyEntity
import com.tencent.iot.explorer.link.core.auth.entity.RoomEntity
import com.tencent.iot.explorer.link.core.auth.entity.User
import com.tencent.iot.explorer.link.core.auth.message.upload.ArrayString
import com.tencent.iot.explorer.link.core.log.L
import com.tencent.iot.explorer.link.kitlink.activity.BaseActivity
import com.tencent.iot.explorer.link.kitlink.consts.CommonField
Expand Down Expand Up @@ -44,6 +45,7 @@ class AppData private constructor() {
var isForeground = false
var callingDeviceId = "" //主动呼叫的设备的id
var rtcNotificationClicked = false
var rtcDeviceIdList: ArrayString? = null

//activity列表
val activityList = LinkedList<BaseActivity>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel<HomeFragmentView>(
}
// TRTC: trtc设备注册websocket监听
IoTAuth.registerActivePush(trtcDeviceIdList, null)
App.data.rtcDeviceIdList = trtcDeviceIdList
}
}
if (callingMyApp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.tencent.iot.explorer.link.core.auth.message.upload.ArrayString
import com.tencent.iot.explorer.link.core.auth.service.*
import com.tencent.iot.explorer.link.core.auth.socket.WSClientManager
import com.tencent.iot.explorer.link.core.auth.socket.callback.ActivePushCallback
import com.tencent.iot.explorer.link.core.auth.socket.callback.ConnectionCallback
import com.tencent.iot.explorer.link.core.auth.socket.callback.PayloadMessageCallback
import com.tencent.iot.explorer.link.core.auth.socket.callback.MessageCallback
import com.tencent.iot.explorer.link.core.log.L
Expand Down Expand Up @@ -214,6 +215,13 @@ object IoTAuth {
WSClientManager.setDebugTag(tag)
}

/**
* 设置WebSocket连接状态回调
*/
fun setWebSocketCallback(callback: ConnectionCallback) {
WSClientManager.instance.setSocketCallback(callback)
}

/**
* 注册监听
* @param deviceIds 多个设备的deviceId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tencent.iot.explorer.link.core.auth.socket

import android.text.TextUtils
import com.tencent.iot.explorer.link.core.auth.IoTAuth
import com.tencent.iot.explorer.link.core.auth.message.MessageConst
import com.tencent.iot.explorer.link.core.auth.message.payload.Payload
import com.tencent.iot.explorer.link.core.auth.message.resp.RespFailMessage
Expand Down Expand Up @@ -60,6 +61,7 @@ internal class WSClientManager private constructor() {
//enterRoom监听使能参数
public var enablePayloadMessageCallback = true

private var socketCallback: ConnectionCallback? = null

/**
* 单例
Expand Down Expand Up @@ -93,6 +95,13 @@ internal class WSClientManager private constructor() {
startHeartJob()
}

/**
* 设置WebSocket连接状态回调
*/
fun setSocketCallback(callback: ConnectionCallback) {
socketCallback = callback
}

fun setBrokerUrl(value: String) {
host = value
}
Expand All @@ -102,7 +111,10 @@ internal class WSClientManager private constructor() {
*/
fun addDeviceIds(ids: ArrayString) {
for (i in 0 until ids.size()) {
heartMessageList.addValue(ids.getValue(i))
val id = ids.getValue(i)
if (!heartMessageList.contains(id)) {
heartMessageList.addValue(id)
}
}
}

Expand Down Expand Up @@ -258,18 +270,20 @@ internal class WSClientManager private constructor() {

override fun connected() {
resend()
if (job != null)
if (job != null) {
activePushCallbacks.forEach {
it.reconnected()
}
}
stopJob()
socketCallback?.connected()
}

override fun disconnected() {
L.d("连接断开")
client?.destroy()
client = null
startJob()
socketCallback?.disconnected()
}
}

Expand Down

0 comments on commit b29ff46

Please sign in to comment.