@@ -17,10 +17,7 @@ import com.tencent.iot.explorer.link.core.auth.util.Weak
1717import com.tencent.iot.explorer.link.demo.common.log.L
1818import com.tencent.iot.explorer.link.core.link.entity.TRTCParamsEntity
1919import com.tencent.iot.explorer.link.demo.rtc.TRTCSdkDemoSessionManager
20- import com.tencent.iot.explorer.link.rtc.model.RoomKey
21- import com.tencent.iot.explorer.link.rtc.model.TRTCCallStatus
22- import com.tencent.iot.explorer.link.rtc.model.TRTCCalling
23- import com.tencent.iot.explorer.link.rtc.model.TRTCUIManager
20+ import com.tencent.iot.explorer.link.rtc.model.*
2421import com.tencent.iot.explorer.link.rtc.ui.audiocall.TRTCAudioCallActivity
2522import com.tencent.iot.explorer.link.rtc.ui.videocall.TRTCVideoCallActivity
2623
@@ -130,92 +127,49 @@ class App : Application(), PayloadMessageCallback {
130127 }
131128
132129 override fun payloadMessage (payload : Payload ) {
133-
134- var jsonObject = org.json.JSONObject (payload.json)
135- val action = jsonObject.getString(MessageConst .MODULE_ACTION );
136- if (action == MessageConst .DEVICE_CHANGE ) { // 收到了设备属性改变的wss消息
137- var paramsObject = jsonObject.getJSONObject(MessageConst .PARAM ) as org.json.JSONObject
138- val subType = paramsObject.getString(MessageConst .SUB_TYPE )
139- if (subType == MessageConst .REPORT ) { // 收到了设备端上报的属性状态改变的wss消息
140-
141- var payloadParamsObject = org.json.JSONObject (payload.payload)
142- val payloadParamsJson = payloadParamsObject.getJSONObject(MessageConst .PARAM )
143- var videoCallStatus = - 1
144- if (payloadParamsJson.has(MessageConst .TRTC_VIDEO_CALL_STATUS )) {
145- videoCallStatus = payloadParamsJson.getInt(MessageConst .TRTC_VIDEO_CALL_STATUS )
146- }
147- var audioCallStatus = - 1
148- if (payloadParamsJson.has(MessageConst .TRTC_AUDIO_CALL_STATUS )) {
149- audioCallStatus = payloadParamsJson.getInt(MessageConst .TRTC_AUDIO_CALL_STATUS )
130+ val userId = data.userInfo.UserID
131+ val trtcPayload = TRTCPayload (payload.json, payload.payload, payload.deviceId)
132+ TRTCUIManager .getInstance().payloadMessage(trtcPayload, userId, object :
133+ TRTCCallback {
134+ override fun busy () {
135+ TRTCUIManager .getInstance().userBusy()
136+ TRTCUIManager .getInstance().exitRoom()
137+ activity?.runOnUiThread {
138+ Toast .makeText(activity, " 对方正忙..." , Toast .LENGTH_LONG ).show()
150139 }
140+ }
151141
152- var deviceId = " "
153- if (payloadParamsJson.has(MessageConst .USERID )) {
154- deviceId = payloadParamsJson.getString(MessageConst .USERID )
155- }
142+ override fun updateCallStatus (key : String? , value : String? , deviceId : String? ) {
143+ controlDevice(key!! , value!! , deviceId!! )
144+ }
156145
157- // 判断主动呼叫的回调中收到的_sys_userid不为自己的userid则被其他用户抢先呼叫设备了,提示用户 对方正忙...
158- val userId = data.userInfo.UserID
159- if (data.callingDeviceId != " " && deviceId != userId) {
160- if (TRTCUIManager .getInstance().isCalling) { // 当前正显示音视频通话页面,finish掉
161- TRTCUIManager .getInstance().userBusy()
162- TRTCUIManager .getInstance().exitRoom()
163- activity?.runOnUiThread {
164- Toast .makeText(activity, " 对方正忙..." , Toast .LENGTH_LONG ).show()
165- }
166- return
167- }
168- }
146+ override fun startCall (type : Int , deviceId : String? ) {
147+ startBeingCall(type, deviceId!! )
148+ }
169149
170- // 判断被动呼叫时,已经被一台设备呼叫,又接到其他设备的呼叫请求,则调用AppControldeviceData拒绝其他设备的请求
171- if (data.callingDeviceId == " " && TRTCUIManager .getInstance().isCalling) {
172- if (videoCallStatus == TRTCCallStatus .TYPE_CALLING .value) {
173- controlDevice(MessageConst .TRTC_VIDEO_CALL_STATUS , " 0" , payload.deviceId)
174- } else if (audioCallStatus == TRTCCallStatus .TYPE_CALLING .value) {
175- controlDevice(MessageConst .TRTC_AUDIO_CALL_STATUS , " 0" , payload.deviceId)
176- }
150+ override fun otherUserAnswered () {
151+ activity?.runOnUiThread {
152+ Toast .makeText(activity, " 其他用户已接听..." , Toast .LENGTH_LONG ).show()
177153 }
154+ TRTCUIManager .getInstance().otherUserAccept()
155+ TRTCUIManager .getInstance().exitRoom()
156+ }
178157
179- // 判断payload中是否包含设备的video_call_status, audio_call_status字段以及是否等于1,若等于1,就调用CallDevice接口, 主动拨打
180- if (videoCallStatus == 1 ) {
181- if (data.callingDeviceId == " " && deviceId != " " && ! deviceId.contains(userId)) { // App被动呼叫 _sys_userid有值 且不包含当前用户的userid
182- } else {
183- startBeingCall(TRTCCalling .TYPE_VIDEO_CALL , payload.deviceId)
184- }
185- } else if (audioCallStatus == 1 ) {
186- if (data.callingDeviceId == " " && deviceId != " " && ! deviceId.contains(userId)) { // App被动呼叫 _sys_userid有值 且不包含当前用户的userid
187- } else {
188- startBeingCall(TRTCCalling .TYPE_AUDIO_CALL , payload.deviceId)
189- }
190- } else if (videoCallStatus == 0 || audioCallStatus == 0 ) { // 空闲或拒绝了,当前正显示音视频通话页面的话,finish掉
191- if (TRTCUIManager .getInstance().deviceId == payload.deviceId) {
192- if (TRTCUIManager .getInstance().callStatus == TRTCCallStatus .TYPE_CALLING .value) {
193- if (data.callingDeviceId == " " ) { // 被动呼叫
194- activity?.runOnUiThread {
195- Toast .makeText(activity, " 对方正忙..." , Toast .LENGTH_LONG ).show()
196- }
197- } else { // 主动呼叫
198- activity?.runOnUiThread {
199- Toast .makeText(activity, " 对方正忙..." , Toast .LENGTH_LONG ).show()
200- }
201- }
158+ override fun hungUp () {
159+ if (TRTCUIManager .getInstance().callStatus == TRTCCallStatus .TYPE_CALLING .value) {
160+ if (TRTCUIManager .getInstance().callingDeviceId == " " ) { // 被动呼叫
161+ activity?.runOnUiThread {
162+ Toast .makeText(activity, " 对方正忙..." , Toast .LENGTH_LONG ).show()
202163 }
203- TRTCUIManager .getInstance().exitRoom()
204- }
205- } else if (videoCallStatus == 2 || audioCallStatus == 2 ) {
206- if (TRTCUIManager .getInstance().callStatus == TRTCCallStatus .TYPE_CALLING .value && data.callingDeviceId == " " ) {
164+ } else { // 主动呼叫
207165 activity?.runOnUiThread {
208- Toast .makeText(activity, " 其他用户已接听 ..." , Toast .LENGTH_LONG ).show()
166+ Toast .makeText(activity, " 对方正忙 ..." , Toast .LENGTH_LONG ).show()
209167 }
210- TRTCUIManager .getInstance().exitRoom()
211168 }
212169 }
213-
214- if (audioCallStatus == 0 || videoCallStatus == 0 ) {
215- data.callingDeviceId = " "
216- }
170+ TRTCUIManager .getInstance().exitRoom()
217171 }
218- }
172+ })
219173 }
220174
221175 /* *
0 commit comments