Skip to content

Commit b29ff46

Browse files
author
archurtan
committed
hua an customer
Change-Id: I6937bf7358c7a6d3377da1cfdf907298e9447cd2
1 parent e340af8 commit b29ff46

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

app/src/main/java/com/tencent/iot/explorer/link/App.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.tencent.iot.explorer.link.core.auth.message.MessageConst
1818
import com.tencent.iot.explorer.link.core.auth.message.payload.Payload
1919
import com.tencent.iot.explorer.link.core.auth.message.upload.ArrayString
2020
import com.tencent.iot.explorer.link.core.auth.response.*
21+
import com.tencent.iot.explorer.link.core.auth.socket.callback.ConnectionCallback
2122
import com.tencent.iot.explorer.link.core.auth.socket.callback.PayloadMessageCallback
2223
import com.tencent.iot.explorer.link.core.auth.util.JsonManager
2324
import com.tencent.iot.explorer.link.core.auth.util.Weak
@@ -43,7 +44,8 @@ import kotlin.collections.ArrayList
4344
/**
4445
* APP
4546
*/
46-
class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessageCallback {
47+
class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessageCallback,
48+
ConnectionCallback {
4749

4850
companion object {
4951
//app数据
@@ -129,13 +131,14 @@ class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessag
129131
super.onCreate()
130132
MultiDex.install(this)
131133
IoTAuth.setWebSocketTag(Utils.getAndroidID(this)) // 设置wss的uin
134+
IoTAuth.setWebSocketCallback(this) // 设置WebSocket连接状态回调
132135
IoTAuth.init(BuildConfig.TencentIotLinkAppkey, BuildConfig.TencentIotLinkAppSecret)
133136
//初始化弹框
134137
T.setContext(this.applicationContext)
135138
//日志开关
136139
L.isLog = DEBUG_VERSION
137140
//日志等级
138-
L.LOG_LEVEL = L.LEVEL_INFO
141+
L.LOG_LEVEL = L.LEVEL_DEBUG
139142
//信鸽推送日志开关
140143
XGPushConfig.enableDebug(applicationContext, DEBUG_VERSION)
141144
XGPushConfig.enablePullUpOtherApp(applicationContext, PULL_OTHER)
@@ -557,6 +560,17 @@ class App : Application(), Application.ActivityLifecycleCallbacks, PayloadMessag
557560

558561
})
559562
}
563+
564+
override fun connected() {
565+
L.d("WebSocket已连接")
566+
if (data.rtcDeviceIdList != null) {
567+
IoTAuth.registerActivePush(data.rtcDeviceIdList!!, null)
568+
}
569+
}
570+
571+
override fun disconnected() {
572+
L.e("WebSocket已断开连接")
573+
}
560574
}
561575

562576
interface AppLifeCircleListener {

app/src/main/java/com/tencent/iot/explorer/link/AppData.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.tencent.iot.explorer.link.core.auth.entity.DeviceEntity
77
import com.tencent.iot.explorer.link.core.auth.entity.FamilyEntity
88
import com.tencent.iot.explorer.link.core.auth.entity.RoomEntity
99
import com.tencent.iot.explorer.link.core.auth.entity.User
10+
import com.tencent.iot.explorer.link.core.auth.message.upload.ArrayString
1011
import com.tencent.iot.explorer.link.core.log.L
1112
import com.tencent.iot.explorer.link.kitlink.activity.BaseActivity
1213
import com.tencent.iot.explorer.link.kitlink.consts.CommonField
@@ -44,6 +45,7 @@ class AppData private constructor() {
4445
var isForeground = false
4546
var callingDeviceId = "" //主动呼叫的设备的id
4647
var rtcNotificationClicked = false
48+
var rtcDeviceIdList: ArrayString? = null
4749

4850
//activity列表
4951
val activityList = LinkedList<BaseActivity>()

app/src/main/java/com/tencent/iot/explorer/link/mvp/model/HomeFragmentModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel<HomeFragmentView>(
440440
}
441441
// TRTC: trtc设备注册websocket监听
442442
IoTAuth.registerActivePush(trtcDeviceIdList, null)
443+
App.data.rtcDeviceIdList = trtcDeviceIdList
443444
}
444445
}
445446
if (callingMyApp) {

sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/auth/IoTAuth.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.tencent.iot.explorer.link.core.auth.message.upload.ArrayString
1010
import com.tencent.iot.explorer.link.core.auth.service.*
1111
import com.tencent.iot.explorer.link.core.auth.socket.WSClientManager
1212
import com.tencent.iot.explorer.link.core.auth.socket.callback.ActivePushCallback
13+
import com.tencent.iot.explorer.link.core.auth.socket.callback.ConnectionCallback
1314
import com.tencent.iot.explorer.link.core.auth.socket.callback.PayloadMessageCallback
1415
import com.tencent.iot.explorer.link.core.auth.socket.callback.MessageCallback
1516
import com.tencent.iot.explorer.link.core.log.L
@@ -214,6 +215,13 @@ object IoTAuth {
214215
WSClientManager.setDebugTag(tag)
215216
}
216217

218+
/**
219+
* 设置WebSocket连接状态回调
220+
*/
221+
fun setWebSocketCallback(callback: ConnectionCallback) {
222+
WSClientManager.instance.setSocketCallback(callback)
223+
}
224+
217225
/**
218226
* 注册监听
219227
* @param deviceIds 多个设备的deviceId

sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/auth/socket/WSClientManager.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.tencent.iot.explorer.link.core.auth.socket
22

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

64+
private var socketCallback: ConnectionCallback? = null
6365

6466
/**
6567
* 单例
@@ -93,6 +95,13 @@ internal class WSClientManager private constructor() {
9395
startHeartJob()
9496
}
9597

98+
/**
99+
* 设置WebSocket连接状态回调
100+
*/
101+
fun setSocketCallback(callback: ConnectionCallback) {
102+
socketCallback = callback
103+
}
104+
96105
fun setBrokerUrl(value: String) {
97106
host = value
98107
}
@@ -102,7 +111,10 @@ internal class WSClientManager private constructor() {
102111
*/
103112
fun addDeviceIds(ids: ArrayString) {
104113
for (i in 0 until ids.size()) {
105-
heartMessageList.addValue(ids.getValue(i))
114+
val id = ids.getValue(i)
115+
if (!heartMessageList.contains(id)) {
116+
heartMessageList.addValue(id)
117+
}
106118
}
107119
}
108120

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

259271
override fun connected() {
260272
resend()
261-
if (job != null)
273+
if (job != null) {
262274
activePushCallbacks.forEach {
263275
it.reconnected()
264276
}
277+
}
265278
stopJob()
279+
socketCallback?.connected()
266280
}
267281

268282
override fun disconnected() {
269-
L.d("连接断开")
270283
client?.destroy()
271284
client = null
272285
startJob()
286+
socketCallback?.disconnected()
273287
}
274288
}
275289

0 commit comments

Comments
 (0)