接入语音SDK

This commit is contained in:
tdg930622 2025-01-14 17:59:20 +08:00
parent aa221ee87d
commit cbe6643d58
3 changed files with 86 additions and 6 deletions

View File

@ -5,10 +5,86 @@
</template>
<script>
import {mapState} from 'vuex'
import fetchApi from "@/services/fetchApi";
export default {
name: "App",
methods: {},
mounted() {},
computed: {
...mapState({
token: state => state.token
}),
},
data(){
return {
}
},
mounted() {
let token = sessionStorage.getItem('token')
if (token){this.initVoiceCall();}
},
methods: {
scriptWithDataSetExists(dataId) {
const scriptElement = document.querySelector(`script[data-telephone="${dataId}"]`);
return scriptElement !== null;
},
injectTCCC ({ token, sdkAppId, userId, sdkUrl }) {
const scriptDom = document.createElement('script')
scriptDom.setAttribute('crossorigin', 'anonymous')
scriptDom.dataset.token = token
scriptDom.dataset.sdkAppId = sdkAppId
scriptDom.dataset.userid = userId
scriptDom.src = sdkUrl
scriptDom.dataset.telephone = 'telephone'
// UI Dom
// script.dataset.renderDomId = "renderDom";
document.body.appendChild(scriptDom)
scriptDom.addEventListener('load', () => {
// UI
window.tccc.UI.hide();
// readytcccready
window.tccc.on('ready', () => {
// Demo
console.log('---初始化成功')
})
//
window.tccc.on('tokenExpired', ({message}) => {
console.error('---初始化失败', message)
})
//
window.tccc.on('callIn', (callback) => {
// acceptID = callback.id;
console.log(callback, '---呼入')
})
})
},
initVoiceCall(){
//
if (this.scriptWithDataSetExists('telephone')){return}
fetchApi.webCalling().then(res => {
const {agent, token, sdkAppId, agentId, sdkURL} = res;
// console.log(res, '---res')
if (agent){
let userId = agentId;
let sdkUrl = sdkURL;
this.injectTCCC({token, sdkAppId, userId, sdkUrl})
}
}).catch(err => {
console.log(err, '---err')
})
},
},
watch: {
token: {
deep: true,
handler: function (val) {
if (val){
// console.log(val, '---token1')
this.initVoiceCall();
}
}
}
}
};
</script>

View File

@ -4,8 +4,8 @@
<div class="layout-bottom-wrap">
<!-- <SideMenu /> -->
<div class="layout-bottom-right-content" :class="(currentName == '/workbench' || currentName == '/workbenchcm') ? '':' p-16'">
<el-scrollbar :style="'height:'+`${contentHeight}`+'px'">
<router-view></router-view>
<el-scrollbar :style="'height:'+`${contentHeight}`+'px'">
<router-view></router-view>
</el-scrollbar>
</div>
</div>
@ -22,14 +22,14 @@ export default {
contentHeight(){
let oh = document.documentElement.clientHeight;
return oh-85
} ,
currentPath() {
return this.$route.path; //
},
currentName() {
return this.$route.name; //
}
}
},
}
</script>

View File

@ -47,5 +47,9 @@ const fetchApi = {
viewFullFile: data => {
return service.service.post(`${apiAdmin}upload/full`, data,{hideLoading:true})
},
// ========================start:: 语音通话SDK======================================
webCalling: data => {
return service.service.get(`${apiAdmin}/api/trace/calling/init-web`, data)
},
}
export default fetchApi;