const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit')
const TUICallingEvent = uni.requireNativePlugin('globalEvent')
const sdkAppId = 1400737560
const userId = 'xxx'
const userSig = 'eJyrVgrxCdYrSy1S...'
created() {
const options = {
SDKAppID: sdkAppId,
userID: userId,
userSig: userSig,
}
TUICallKit.login(options, (res) => {
if (res.code === 0) {
console.log('已登录')
} else {
console.log(`login failed, error message = ${res.msg}`)
}
})
TUICallingEvent.addEventListener('onError', (res) => {
console.log('onError', JSON.stringify(res))
})
TUICallingEvent.addEventListener('onCallReceived', (res) => {
console.log('onCallReceived', JSON.stringify(res))
})
TUICallingEvent.addEventListener('onCallCancelled', (res) => {
console.log('onCallCancelled', res)
})
TUICallingEvent.addEventListener('onCallBegin', (res) => {
console.log('onCallBegin', JSON.stringify(res))
})
TUICallingEvent.addEventListener('onCallEnd', (res) => {
console.log('onCallEnd', JSON.stringify(res))
})
}
测试使用script引入 也可以使用npm(https://cloud.tencent.com/document/product/647/78731)
<script src="./trtc-js-sdk/trtc.js"></script>
<script src="./tim-js-sdk/tim-js.js"></script>
<script src="./tsignaling/tsignaling-js.js"></script>
<script src="./tuicall- engine-webrtc/tuicall-engine-webrtc.js"></script>
引入客户端生成userSig
相关文件
<script src="./js/clipboard.min.js"></script>
<script src="./js/lib-generate-test-usersig.min.js"></script>
<script src="./js/generateTestUserSig.js"></script>
传入参数 登录,之后就可以呼叫 监听事件等等(https://cloud.tencent.com/document/product/647/78756)
const {
TUICallEngine,
TUICallEvent
} = window['tuicall-engine-webrtc']
let options = {
SDKAppID: sdkAppId, // 接入时需要将 0 替换为您的云通信应用的 SDKAppID
tim: null // tim 参数适用于业务中已存在 TIM 实例,为保证 TIM 实例唯一性
}
console.log()
let tuiCallEngine = TUICallEngine.createInstance(options);
tuiCallEngine.login({
userID: userId,
userSig: userSig,
}).then(res => {
// success
}).catch(error => {
console.warn('login error:', error)
})
Web端没看到有通话组件的(呼叫界面、接听界面)