浏览代码

接入getSign接口

gemercheung 2 年之前
父节点
当前提交
6da20b1c69
共有 2 个文件被更改,包括 23 次插入4 次删除
  1. 17 1
      src/hooks/useRoom.ts
  2. 6 3
      src/hooks/useTRTC.ts

+ 17 - 1
src/hooks/useRoom.ts

@@ -1,5 +1,5 @@
 import browser from '/@/utils/browser';
-import axios from 'axios';
+import axios, { AxiosResponse } from 'axios';
 import { ref, computed, unref } from 'vue';
 import { useRtcStore } from '../store/modules/rtc';
 
@@ -42,6 +42,12 @@ interface roomParamsType {
   avatar: string;
 }
 
+interface getSignType {
+  expire: number;
+  sdkAppId: number;
+  sign: string;
+}
+
 function createNewURL(params: roomParamsType): string {
   let tempUrl = window.location.href;
   // ['mode', 'name', 'role', 'vruserId']
@@ -66,6 +72,7 @@ export function useRoom() {
     leaveRoom,
     createNewURLEntry,
     createNewURL,
+    getSign,
   };
 }
 
@@ -125,3 +132,12 @@ export const leaveRoom = async () => {
 if (roomId) {
   shopAxios.get('/takelook/roomAddView', { params: { roomId } });
 }
+
+export const getSign = async (userId: string): Promise<getSignType> => {
+  const res = await shopAxios.get<AxiosResponse>('/takelook/tencentYun/getSign', {
+    params: {
+      userId,
+    },
+  });
+  return res.data.data;
+};

+ 6 - 3
src/hooks/useTRTC.ts

@@ -6,6 +6,7 @@ import { useRtcStore } from '/@/store/modules/rtc';
 // import Dialog from '/@/components/basic/dialog';
 import { useI18n } from './useI18n';
 import { useMiniApp } from './useMiniApp';
+import { useRoom } from './useRoom';
 
 let localClient: Client;
 let localStream: LocalStream;
@@ -122,12 +123,14 @@ async function createRTCSocket(): Promise<void> {
 async function handleJoin() {
   const rtcStore = useRtcStore();
   try {
-    // let res = await apis.getSign({ userId: store.getters["rtc/userId"] });
+    const { getSign } = useRoom();
+    const res = await getSign(rtcStore.userId);
+    console.warn('sign', res);
     localClient = TRTC.createClient({
       mode: 'rtc',
-      sdkAppId: parseInt(rtcStore.sdkAppId, 10),
+      sdkAppId: res.sdkAppId || parseInt(rtcStore.sdkAppId, 10),
       userId: rtcStore.userId,
-      userSig: rtcStore.genUserSig,
+      userSig: res.sign || rtcStore.genUserSig,
       useStringRoomId: true,
       enableAutoPlayDialog: false,
     });