当前位置:网站首页>Implementation idea and solution of calling global monitoring for applet
Implementation idea and solution of calling global monitoring for applet
2022-06-23 02:46:00 【A good man】
explain
Ben demo Is based on Tencent cloud calling Applet The related logic is modified to realize global listening , After receiving the invitation signal, jump to the specified page ( This page has registered TUICalling Components ) Perform component initialization , It is recommended to know the official website before using demo Related documents of , I won't explain more here , If you think this article is helpful to you, please give me a compliment !
Global monitoring effect display
be based on calling Modification description of components
The implementation idea of global monitoring is based on the original calling Based on the component, the signaling is put into app.js file , And in appLaunch Realize the listening of invitation signaling , Process the invitation event after listening to the invitation event , And set the required parameters to globalData When it is convenient to get , Then jump to the page initialization component to handle the invitation event , Besides, I didn't leave because of the invitation TRTCDelegate, Therefore, hang up events are handled separately by signaling , Due to the hurry of time , So this demo Only ideas and references are provided
Mind mapping
project demo GitHub Address gate
Modify the code of the point part
- app.js Import signaling related files
import TSignaling from './components/TUICalling/TRTCCalling/node\_module/tsignaling-wx'
import TSignalingClient from './components/TUICalling/TRTCCalling/TSignalingClient'
import TIM from './components/TUICalling/TRTCCalling/node\_module/tim-wx-sdk'
import { CALL\_STATUS } from './components/TUICalling/TRTCCalling/common/constants'- Set the required global parameters
userInfo: null,
headerHeight: 0,
statusBarHeight: 0,
sdkAppID: Signature.sdkAppID,
userID: '',
userSig: '',
token: '',
expiresIn: '',
phone: '',
sessionID: '',
callStatus: CALL\_STATUS.IDLE, // Current call status of the user
callType: 1,
callEvent: null,
inviteId: '',
inviteID: '',
inviter: '',
roomID: '',
isSponsor: false,
\_connectUserIDList: [],
\_isGroupCall: false,
\_groupID: '',
\_unHandledInviteeList: [],
inviteData: null,
inviteeList: []- Signaling initialization and listening
wx.$TIM = TIM.create({SDKAppID: Signature.sdkAppID})
wx.$TSignaling = new TSignaling({SDKAppID: Signature.sdkAppID, tim: wx.$TIM})
wx.TSignalingClient = new TSignalingClient({ TSignaling: wx.$TSignaling })
// New invitation callback event
wx.$TSignaling.on(TSignaling.EVENT.NEW\_INVITATION\_RECEIVED, this.handleNewInvitationReceived, this);
// SDK Ready Callback
wx.$TSignaling.on(TSignaling.EVENT.SDK\_READY, this.handleSDKReady, this);
// Kicked offline
wx.$TSignaling.on(TSignaling.EVENT.KICKED\_OUT, this.handleKickedOut, this);- Invitation event handling
handleNewInvitationReceived(event) {
console.log(TAG\_NAME, 'onNewInvitationReceived', event);
const { data: { inviter, inviteeList, data, inviteID, groupID } } = event
const inviteData = JSON.parse(data)
wx.$globalData.inviteData = inviteData
wx.$globalData.inviteeList = inviteeList
// Judge here inviteeList.length Greater than 2, It is used to judge multi person calls in non group situations
// userIDs For synchronization native No... In use groupID Judgment basis for group chat
const isGroupCall = groupID || inviteeList.length >= 2 || inviteData.data && inviteData.data.userIDs && inviteData.data.userIDs.length >= 2 ? true : false
let callEnd = false
// The logic here is used for invite Signaling
// When the group call has ended ,room\_id Nonexistence or call\_end by 0
if (isGroupCall && (!inviteData.room\_id || (inviteData.call\_end && inviteData.call\_end === 0))) {
callEnd = true
}
// 1v1 When hanging up , Notify the end and duration of the call at the opposite end
if (!isGroupCall && inviteData.call\_end >= 0) {
callEnd = true
}
if(callEnd) {
return
}
if(wx.$globalData.callStatus === CALL\_STATUS.CALLING || wx.$globalData.callStatus === CALL\_STATUS.CONNECTED) {
wx.$TSignaling.reject({ inviteID, type: data.call\_type, lineBusy: 'line\_busy' })
return
}
const callInfo = {
\_isGroupCall: !!isGroupCall,
\_groupID: groupID || '',
\_unHandledInviteeList: [...inviteeList, inviter],
}
if (isGroupCall && !groupID) {
callInfo.\_unHandledInviteeList = [...inviteData.data.userIDs]
}
wx.$globalData.callStatus = CALL\_STATUS.CALLING
wx.$globalData.callType = inviteData.call\_type
wx.$globalData.inviteID = inviteID
wx.$globalData.inviter= inviter
wx.$globalData.roomID = inviteData.room\_id
wx.$globalData.isSponsor = false
wx.$globalData.\_connectUserIDList = [inviter]
wx.$globalData.\_isGroupCall = callInfo.\_isGroupCall
wx.$globalData.\_groupID = callInfo.\_groupID
wx.$globalData.\_unHandledInviteeList = callInfo.\_unHandledInviteeList
wx.$globalData.callEvent = event
wx.navigateTo({
url: '/pages/calling/calling', // Page to jump to
})
}- Jump page introduction TUICalling Components
<TUICalling
id="TUICalling-component"
config="{{config}}"
></TUICalling>- Specify page onLoad Method to initialize and process components
const config = {
sdkAppID: wx.$globalData.sdkAppID,
userID: wx.$globalData.userID,
userSig: wx.$globalData.userSig
}
this.setData({
config: { ...this.data.config, ...config },
}, () => {
this.TUICalling = this.selectComponent('#TUICalling-component')
this.TUICalling.init()
wx.$globalData.callStatus === CALL\_STATUS.CALLING && this.TUICalling.handleNewInvitationReceived(wx.$globalData.callEvent)
}) - TUICalling.js Invitation event handling
// New invitation callback event
handleNewInvitationReceived(event) {
console.log(`${TAG\_NAME}, handleNewInvitationReceived`, event)
this.data.config.type = wx.$globalData.callType
this.getUserProfile([event.data.inviter || event.data.sponsor])
this.setData({
config: this.data.config,
callStatus: 'calling',
isSponsor: false,
})
}- Hang up as the inviting party
/\*\*
\* When you receive a callback as the invitee , You can call this function to reject an incoming call
\*/
async reject() {
console.log(`${TAG\_NAME}, reject`)
const inviteID = wx.$globalData.inviteID
const data = wx.$globalData.callEvent.data
wx.$TSignaling.reject({
inviteID,
data: JSON.stringify(data)
}).then(res => {
this.triggerEvent('sendMessage', {
message: res.data.message,
})
})边栏推荐
- Goframe framework (RK boot): fast implementation of server-side JWT verification
- SetTimeout and setinterval execution time
- Delta oscillation in EEG
- The difference between script in head and body
- Hypervisor Necromancy; Recover kernel protector (1)
- Learning notes of recommendation system (1) - Collaborative Filtering - Theory
- How to make traditional Chinese medicine labels with pictures
- Ping your domain name to 127.0.0.1. The solution to DNS hijacking
- Biological psychiatry: defining individualized functional neuroanatomy for precision psychiatry
- How PHP uses redis
猜你喜欢

5. concept of ruler method

Xgboost Guide

Deep learning environment configuration (I) installation of CUDA and cudnn

2021-11-11

Xgboost principle

8. greed

Microservice Optimization: internal communication of microservices using grpc

Stop automatically after MySQL starts (unable to start)

Analog Electronic Technology

You must know the type and method of urllib
随机推荐
Aikuai multi dialing + load balancing overlay bandwidth
Applet control version update best practices
Soft exam information system project manager_ Information system comprehensive testing and management - Senior Information System Project Manager of soft test 027
Canvas draw the clock
2021-11-11
EDI project cases of customers in medical device industry
Log a log4j2 vulnerability handling
Performance test -- 14 detailed explanation of performance test report and precautions
Reinforcement learning series (III) -gym introduction and examples
How to prohibit copying and copying files to the local server remote desktop
Windows system poisoning, SQL Server database file recovery rescue and OA program file recovery
My good brother gave me a difficult problem: retry mechanism
Analysis of resolv Conf common parameters
5g access network and base station evolution
WebService details
Vs code remote SSH configuration
Soft exam information system project manager_ Contract Law_ Copyright_ Implementation Regulations - Senior Information System Project Manager of soft exam 030
February 2, 2022: the closest binary search tree value II. Given a non empty two
Understand GB, gbdt and xgboost step by step
Chapter 3 tensorflow linear regression