3 files modified
2 files added
| | |
| | | <script setup> |
| | | import {onHide, onLaunch, onShow} from "@dcloudio/uni-app"; |
| | | import {useAppStore, useUserStore} from "@/store"; |
| | | import {genTestUserSig} from '@/utils/voiceCallByTX/GenerateTestUserSig.js'; |
| | | |
| | | |
| | | import {useGlobalWS} from "@/hooks/useGlobalWS.js"; |
| | | |
| | | const appStore = useAppStore(); |
| | | const userStore = useUserStore(); |
| | | const userId = computed(() => userStore?.userInfo?.user_id) |
| | | |
| | | |
| | | |
| | | onLaunch(() => { |
| | | // 初始化系统信息 |
| | | appStore.initSystemInfo(); |
| | | |
| | | if (!userStore.userInfo) { |
| | | //不存在则跳转至登录页 |
| | | uni.reLaunch({ |
| | | url: "/pages/login/index", |
| | | }) |
| | | } |
| | | }); |
| | | |
| | | // #ifdef APP-PLUS |
| | | import TrtcCloud from '@/utils/voiceCallByTX/TrtcCloud/lib/index'; |
| | | import { TRTCAppScene } from '@/utils/voiceCallByTX/TrtcCloud/lib/TrtcDefines'; |
| | | const trtcCloud = TrtcCloud.createInstance(); |
| | | function enterRoomFun() { |
| | | const {userSig, SDKAppID} = genTestUserSig(userId.value); |
| | | const params = {sdkAppId: SDKAppID, userId: userId.value, roomId: 789456, userSig: userSig}; |
| | | trtcCloud.enterRoom(params, TRTCAppScene.TRTCAppSceneVideoCall) |
| | | trtcCloud.startLocalAudio(); |
| | | } |
| | | // #endif |
| | | |
| | | // #ifdef H5 |
| | | import TRTC from 'trtc-sdk-v5'; |
| | | const trtc = TRTC.create(); |
| | | function enterRoomFunByH5() { |
| | | const {userSig, SDKAppID} = genTestUserSig(userId.value); |
| | | trtc.enterRoom({ sdkAppId:SDKAppID, userId:userId.value, userSig, roomId: 789456 }) |
| | | trtc.startLocalAudio() |
| | | } |
| | | // #endif |
| | | |
| | | // 初始化登陆腾讯音频平台 |
| | | watch(userId, () => { |
| | | if (!userId.value) return |
| | | // #ifdef APP-PLUS |
| | | // enterRoomFun() |
| | | // #endif |
| | | // #ifdef H5 |
| | | // enterRoomFunByH5() |
| | | // #endif |
| | | |
| | | }, { |
| | | immediate: true |
| | | }) |
| | | useGlobalWS() |
| | | |
| | | onShow(() => { |
| | | console.log("App Show"); |
| | |
| | | onHide(() => { |
| | | console.log("App Hide"); |
| | | }); |
| | | |
| | | onLaunch(() => { |
| | | // 初始化系统信息 |
| | | appStore.initSystemInfo(); |
| | | if (!userStore.userInfo) { |
| | | //不存在则跳转至登录页 |
| | | uni.reLaunch({ |
| | | url: "/pages/login/index", |
| | | }) |
| | | } |
| | | }); |
| | | </script> |
| | | |
| | | <style lang="scss"> |
| | |
| | | }, |
| | | }); |
| | | }; |
| | | |
| | | // 发送通话信息 |
| | | export const sendVoiceCallApi = (data) => { |
| | | return request({ |
| | | url: `/drone-device-core/dp/call/sendVoiceCall`, |
| | | method: 'post', |
| | | data |
| | | }) |
| | | } |
| | |
| | | VITE_APP_WEBVIEW_URL: 'http://localhost:5173/drone-app-web-view/#/webViewWrapper', |
| | | VITE_API_BASE_URL: 'https://wrj.shuixiongit.com/api', |
| | | // VITE_API_BASE_URL: 'https://aisky.org.cn/api', |
| | | VITE_APP_WS_API_URL:'wss://wrj.shuixiongit.com/drone-wss/api/v1/ws' |
| | | } |
| | | |
| | | const test = { |
| | | VITE_APP_ENV:'test', |
| | | VITE_APP_WEBVIEW_URL: 'https://wrj.shuixiongit.com/drone-app-web-view/#/webViewWrapper', |
| | | VITE_API_BASE_URL: 'https://wrj.shuixiongit.com/api', |
| | | VITE_APP_WS_API_URL:'wss://wrj.shuixiongit.com/drone-wss/api/v1/ws' |
| | | } |
| | | |
| | | const production = { |
| | | VITE_APP_ENV:'production', |
| | | VITE_APP_WEBVIEW_URL: 'https://aisky.org.cn/drone-app-web-view/#/webViewWrapper', |
| | | VITE_API_BASE_URL: 'https://aisky.org.cn/api', |
| | | VITE_APP_WS_API_URL:'wss://wrj.shuixiongit.com/drone-wss/api/v1/ws' |
| | | } |
| | | |
| | | export default { |
| New file |
| | |
| | | import {useUserStore} from "@/store/index.js"; |
| | | import {getEnvObj} from "@/utils/index.js"; |
| | | import {enterRoom} from "@/utils/voiceCallByTX/index.js"; |
| | | |
| | | let socketTask = null |
| | | |
| | | export function useGlobalWS() { |
| | | const userStore = useUserStore(); |
| | | const userId = computed(() => userStore?.userInfo?.user_id) |
| | | const access_token = computed(() => userStore?.userInfo?.access_token) |
| | | const {VITE_APP_WS_API_URL} = getEnvObj() |
| | | |
| | | // 消息处理 |
| | | function messageHandler(payload) { |
| | | switch (payload.biz_code) { |
| | | case 'JOB_ISREFRESH': |
| | | break |
| | | case 'DEVICE_ISREFRESH': |
| | | break |
| | | case 'DOWNLOAD_PROGRESS': |
| | | break |
| | | case 'LOGOUT_USER': |
| | | userStore.setUserInfo(null) |
| | | uni.reLaunch({ |
| | | url: '/pages/login/index' |
| | | }) |
| | | break |
| | | case 'VoiceCall': |
| | | enterRoom(payload, userId.value) |
| | | break |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 关闭ws |
| | | function closeWS() { |
| | | socketTask?.close({ |
| | | success: () => { |
| | | console.log('ws关闭连接'); |
| | | }, |
| | | }) |
| | | } |
| | | |
| | | // 初始化ws |
| | | function initWS() { |
| | | // 关闭,再连接ws |
| | | closeWS() |
| | | if (!access_token.value) return |
| | | const url = VITE_APP_WS_API_URL |
| | | + `?x-auth-token=${encodeURI(access_token?.value)}` |
| | | + `&model_type=3&workspace-id=${userId.value}` |
| | | // 创建连接 |
| | | socketTask = uni.connectSocket({ |
| | | url: url, |
| | | success: () => { |
| | | console.log('ws连接成功'); |
| | | }, |
| | | fail: (err) => { |
| | | console.error('ws连接失败:', err); |
| | | } |
| | | }); |
| | | // 消息监听 |
| | | socketTask.onMessage((result) => { |
| | | messageHandler(JSON.parse(result.data)) |
| | | }) |
| | | } |
| | | |
| | | watch(access_token, initWS, {immediate: true}) |
| | | } |
| New file |
| | |
| | | // #ifdef APP-PLUS |
| | | import TrtcCloud from '@/utils/voiceCallByTX/TrtcCloud/lib/index'; |
| | | import {TRTCAppScene} from '@/utils/voiceCallByTX/TrtcCloud/lib/TrtcDefines'; |
| | | |
| | | const trtcCloud = TrtcCloud.createInstance(); |
| | | // #endif |
| | | |
| | | // #ifdef H5 |
| | | import TRTC from 'trtc-sdk-v5'; |
| | | |
| | | const trtc = TRTC.create(); |
| | | // #endif |
| | | |
| | | import {genTestUserSig} from "@/utils/voiceCallByTX/GenerateTestUserSig.js"; |
| | | import {sendVoiceCallApi} from "@/api/user/index.js"; |
| | | |
| | | export function enterRoom(payload, userId) { |
| | | const data = JSON.parse(payload.data.data) |
| | | const theOtherPartyId = payload.data.caller_id |
| | | const {userSig, SDKAppID: sdkAppId} = genTestUserSig(userId); |
| | | const params = {sdkAppId, userId, roomId: data.roomId, userSig}; |
| | | // #ifdef APP-PLUS |
| | | trtcCloud.enterRoom(params, TRTCAppScene.TRTCAppSceneVideoCall) |
| | | trtcCloud.startLocalAudio(); |
| | | // #endif |
| | | // #ifdef H5 |
| | | trtc.enterRoom(params) |
| | | trtc.startLocalAudio() |
| | | // #endif |
| | | // demo原因,直接接通来进行验证测试 |
| | | sendVoiceCallApi({ |
| | | caller_id: userId, |
| | | receiver_id: theOtherPartyId, |
| | | data: JSON.stringify({state: '接通', roomId: data.roomId}), |
| | | }) |
| | | } |