Sfoglia il codice sorgente

feat: 优化接口

shuisheng 2 anni fa
parent
commit
479d075b7c
5 ha cambiato i file con 10 aggiunte e 31 eliminazioni
  1. 0 13
      script/config/webpack.dev.ts
  2. 2 5
      src/api/srs.ts
  3. 0 5
      src/constant.ts
  4. 4 4
      src/hooks/use-pull.ts
  5. 4 4
      src/hooks/use-push.ts

+ 0 - 13
script/config/webpack.dev.ts

@@ -71,19 +71,6 @@ export default new Promise((resolve) => {
             directory: resolveApp('./public/'),
           },
           proxy: {
-            '/srs/': {
-              target: 'http://localhost:1985',
-              secure: false, // 默认情况下(secure: true),不接受在HTTPS上运行的带有无效证书的后端服务器。设置secure: false后,后端服务器的HTTPS有无效证书也可运行
-              /**
-               * changeOrigin,是否修改请求地址的源
-               * 默认changeOrigin: false,即发请求即使用devServer的localhost:port发起的,如果后端服务器有校验源,就会有问题
-               * 设置changeOrigin: true,就会修改发起请求的源,将原本的localhost:port修改为target,这样就可以通过后端服务器对源的校验
-               */
-              changeOrigin: true,
-              pathRewrite: {
-                '^/srs/': '', // 效果:/srs/link/list ==> http://localhost:3300/link/list
-              },
-            },
             '/api': {
               // target: 'http://localhost:4200',
               target: 'http://localhost:4300',

+ 2 - 5
src/api/srs.ts

@@ -1,4 +1,3 @@
-import { SRS_STREAM_URL } from '@/constant';
 import request from '@/utils/request';
 
 export function fetchRtcV1Publish(data: {
@@ -9,8 +8,7 @@ export function fetchRtcV1Publish(data: {
   tid: string;
 }) {
   return request.instance({
-    baseURL: SRS_STREAM_URL,
-    url: `/rtc/v1/publish/`,
+    url: `/srs/rtcV1Publish`,
     method: 'post',
     data,
   });
@@ -23,8 +21,7 @@ export function fetchRtcV1Play(data: {
   tid: string;
 }) {
   return request.instance({
-    baseURL: SRS_STREAM_URL,
-    url: '/rtc/v1/play/',
+    url: `/srs/rtcV1Play`,
     method: 'post',
     data,
   });

+ 0 - 5
src/constant.ts

@@ -5,11 +5,6 @@ export const QQ_REDIRECT_URI = 'https://live.hsslive.cn/oauth/qq_login';
 export const AUTHOR_GITHUB = 'https://github.com/galaxy-s10';
 export const LIVE_CLIENT_URL = 'https://live.hsslive.cn';
 
-export const SRS_STREAM_URL =
-  process.env.NODE_ENV === 'development'
-    ? 'http://localhost:1985'
-    : 'https://srs-pull.hsslive.cn/srs';
-
 export const WEBSOCKET_URL =
   process.env.NODE_ENV === 'development'
     ? 'ws://localhost:4300'

+ 4 - 4
src/hooks/use-pull.ts

@@ -3,7 +3,7 @@ import { Ref, nextTick, onUnmounted, reactive, ref, watch } from 'vue';
 import { useRoute } from 'vue-router';
 
 import { fetchRtcV1Play } from '@/api/srs';
-import { SRS_STREAM_URL, WEBSOCKET_URL } from '@/constant';
+import { WEBSOCKET_URL } from '@/constant';
 import { useFlvPlay, useHlsPlay } from '@/hooks/use-play';
 import {
   DanmuMsgTypeEnum,
@@ -390,15 +390,15 @@ export function usePull({
         const offer = await rtc.createOffer();
         if (!offer) return;
         await rtc.setLocalDescription(offer);
-        const res: any = await fetchRtcV1Play({
-          api: `${SRS_STREAM_URL}/rtc/v1/play/`,
+        const res = await fetchRtcV1Play({
+          api: `/rtc/v1/play/`,
           clientip: null,
           sdp: offer.sdp!,
           streamurl: streamurl.value,
           tid: getRandomString(10),
         });
         await rtc.setRemoteDescription(
-          new RTCSessionDescription({ type: 'answer', sdp: res.sdp })
+          new RTCSessionDescription({ type: 'answer', sdp: res.data.sdp })
         );
       } catch (error) {
         console.log(error);

+ 4 - 4
src/hooks/use-push.ts

@@ -15,7 +15,7 @@ import {
   fetchCreateUserLiveRoom,
   fetchUserHasLiveRoom,
 } from '@/api/userLiveRoom';
-import { SRS_STREAM_URL, WEBSOCKET_URL } from '@/constant';
+import { WEBSOCKET_URL } from '@/constant';
 import {
   DanmuMsgTypeEnum,
   IAnswer,
@@ -211,8 +211,8 @@ export function usePush({
         const offer = await rtc.createOffer();
         if (!offer) return;
         await rtc.setLocalDescription(offer);
-        const res: any = await fetchRtcV1Publish({
-          api: `${SRS_STREAM_URL}/rtc/v1/publish/`,
+        const res = await fetchRtcV1Publish({
+          api: `/rtc/v1/publish/`,
           clientip: null,
           sdp: offer.sdp!,
           streamurl: userStore.userInfo!.live_rooms![0]!.rtmp_url!.replace(
@@ -222,7 +222,7 @@ export function usePush({
           tid: getRandomString(10),
         });
         await rtc.setRemoteDescription(
-          new RTCSessionDescription({ type: 'answer', sdp: res.sdp })
+          new RTCSessionDescription({ type: 'answer', sdp: res.data.sdp })
         );
       } catch (error) {
         console.log(error);