shuisheng 2 anni fa
parent
commit
b665c50d79
2 ha cambiato i file con 17 aggiunte e 18 eliminazioni
  1. 4 4
      src/hooks/use-play.ts
  2. 13 14
      src/views/account/index.vue

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

@@ -65,6 +65,10 @@ export function useFlvPlay() {
           });
           videoEl.addEventListener('playing', () => {
             console.log('flv-playing');
+            retry.value = 0;
+            setMuted(appStore.muted);
+            flvVideoEl.value = videoEl;
+            resolve('');
           });
           videoEl.addEventListener('loadedmetadata', () => {
             console.log('flv-loadedmetadata');
@@ -89,10 +93,6 @@ export function useFlvPlay() {
           });
           flvPlayer.value.on(mpegts.Events.MEDIA_INFO, () => {
             console.log('mpegts消息:mpegts.Events.MEDIA_INFO');
-            retry.value = 0;
-            setMuted(appStore.muted);
-            flvVideoEl.value = videoEl;
-            resolve('');
           });
           try {
             console.log(`开始播放flv,muted:${appStore.muted}`);

+ 13 - 14
src/views/account/index.vue

@@ -41,7 +41,11 @@
         >
           <span>
             推流地址:{{
-              newRtmpUrl || handleUrl(userInfo?.live_rooms?.[0].rtmp_url!)
+              newRtmpUrl ||
+              handleUrl({
+                url: userInfo?.live_rooms?.[0].rtmp_url!,
+                token: userInfo?.live_rooms?.[0].key!,
+              })
             }},
           </span>
           <span
@@ -89,7 +93,11 @@ async function handleUserInfo() {
 
 function handleCopy() {
   copyToClipBoard(
-    newRtmpUrl.value || handleUrl(userInfo.value?.live_rooms?.[0].rtmp_url!)
+    newRtmpUrl.value ||
+      handleUrl({
+        url: userInfo.value?.live_rooms?.[0].rtmp_url!,
+        token: userInfo.value?.live_rooms?.[0].key!,
+      })
   );
   window.$message.success('复制成功!');
 }
@@ -105,17 +113,8 @@ function openLiveRoom() {
   openToTarget(url.href);
 }
 
-function handleUrl(rtmpUrl: string) {
-  let resUrl = '';
-  if (rtmpUrl.indexOf('type=') === -1) {
-    resUrl += `${rtmpUrl}&type=${LiveRoomTypeEnum.user_obs}`;
-  } else {
-    resUrl = rtmpUrl.replace(
-      /type=([0-9]+)/,
-      `type=${LiveRoomTypeEnum.user_obs}`
-    );
-  }
-  return resUrl;
+function handleUrl(data: { url: string; token: string }) {
+  return `${data.url}?token=${data.token}&type=${LiveRoomTypeEnum.user_obs}`;
 }
 
 async function handleUpdateKey() {
@@ -123,7 +122,7 @@ async function handleUpdateKey() {
     keyLoading.value = true;
     const res = await fetchUpdateLiveRoomKey();
     if (res.code === 200) {
-      const resUrl = handleUrl(res.data.rtmp_url as string);
+      const resUrl = handleUrl({ url: res.data.rtmp_url, token: res.data.key });
       newRtmpUrl.value = resUrl;
     }
   } catch (error) {