Procházet zdrojové kódy

fix: 修复已知问题

shuisheng před 1 rokem
rodič
revize
c514cb04b9

+ 4 - 2
.vscode/settings.json

@@ -11,9 +11,11 @@
 
   // 保存时进行一些操作
   "editor.codeActionsOnSave": {
+    "source.fixAll.eslint": "explicit",
+    "source.organizeImports": "explicit"
     // 在保存时运行eslint
-    "source.fixAll.eslint": true,
-    "source.organizeImports": true // 保存时整理 import ,去掉没用的导包,会删掉declare global {import utils from 'billd-utils';},因此先不用
+    //  "source.fixAll.eslint": true,
+    //  "source.organizeImports": true // 保存时整理 import ,去掉没用的导包,会删掉declare global {import utils from 'billd-utils';},因此先不用
   },
 
   // "eslint.autoFixOnSave": true, // 废弃,使用editor.codeActionsOnSave替代

+ 4 - 4
public/worker.js

@@ -4,12 +4,12 @@ self.addEventListener('message', function (e) {
       const timer = setInterval(function () {
         self.postMessage({
           type: 'response-msr-looping',
-          data: { timer },
+          timer,
         });
       }, e.data.delay);
       self.postMessage({
         type: 'response-start-msr-loop',
-        data: { timer },
+        timer,
       });
     }
   } else if (e.data.type === 'request-start-loop') {
@@ -17,12 +17,12 @@ self.addEventListener('message', function (e) {
       const timer = setInterval(function () {
         self.postMessage({
           type: 'response-looping',
-          data: { timer },
+          timer,
         });
       }, e.data.delay);
       self.postMessage({
         type: 'response-start-loop',
-        data: { timer },
+        timer,
       });
     }
   } else if (e.data.type === 'request-clear-loop') {

+ 2 - 0
src/hooks/use-pull.ts

@@ -48,6 +48,7 @@ export function usePull(roomId: string) {
     anchorInfo,
     liveUserList,
     damuList,
+    handleSendGetLiveUser,
   } = useWebsocket();
   isPull.value = true;
   const { flvVideoEl, flvIsPlaying, startFlvPlay, destroyFlv } = useFlvPlay();
@@ -465,6 +466,7 @@ export function usePull(roomId: string) {
     keydownDanmu,
     sendDanmu,
     addVideo,
+    handleSendGetLiveUser,
     danmuMsgType,
     isPlaying,
     msgIsFile,

+ 3 - 0
src/hooks/use-push.ts

@@ -39,6 +39,7 @@ export function usePush() {
     isPull,
     initSrsWs,
     handleStartLive,
+    handleSendGetLiveUser,
     mySocketId,
     canvasVideoStream,
     lastCoverImg,
@@ -350,6 +351,8 @@ export function usePush() {
     sendDanmu,
     keydownDanmu,
     sendBlob,
+    handleSendGetLiveUser,
+    roomId,
     msgIsFile,
     mySocketId,
     lastCoverImg,

+ 18 - 0
src/hooks/use-websocket.ts

@@ -53,6 +53,7 @@ export const useWebsocket = () => {
   const { maxBitrate, maxFramerate, resolutionRatio } = useRTCParams();
 
   const loopHeartbeatTimer = ref();
+  const loopGetLiveUserTimer = ref();
   const liveUserList = ref<ILiveUser[]>([]);
   const roomId = ref('');
   const isPull = ref(false);
@@ -71,6 +72,7 @@ export const useWebsocket = () => {
 
   onUnmounted(() => {
     clearInterval(loopHeartbeatTimer.value);
+    clearInterval(loopGetLiveUserTimer.value);
   });
 
   watch(
@@ -99,6 +101,21 @@ export const useWebsocket = () => {
         msgType: WsMsgTypeEnum.heartbeat,
         data: {
           socket_id: socketId,
+          live_room_id: Number(roomId.value),
+        },
+      });
+    }, 1000 * 5);
+  }
+
+  function handleSendGetLiveUser(liveRoomId: number) {
+    loopGetLiveUserTimer.value = setInterval(() => {
+      const ws = networkStore.wsMap.get(roomId.value);
+      if (!ws) return;
+      ws.send<WsGetLiveUserType['data']>({
+        requestId: getRandomString(8),
+        msgType: WsMsgTypeEnum.getLiveUser,
+        data: {
+          live_room_id: liveRoomId,
         },
       });
     }, 1000 * 5);
@@ -841,6 +858,7 @@ export const useWebsocket = () => {
     isPull,
     initSrsWs,
     handleStartLive,
+    handleSendGetLiveUser,
     mySocketId,
     canvasVideoStream,
     lastCoverImg,

+ 1 - 0
src/types/websocket.ts

@@ -200,6 +200,7 @@ export type WsLeavedType = IWsFormat<{
 /** 心跳检测 */
 export type WsHeartbeatType = IWsFormat<{
   socket_id: string;
+  live_room_id: number;
 }>;
 
 /** msr直播发送blob */

+ 0 - 1
src/utils/index.ts

@@ -3,7 +3,6 @@ import { computeBox, getRangeRandom } from 'billd-utils';
 import sparkMD5 from 'spark-md5';
 
 export function formatMoney(money?: number) {
-  console.log('formatMoneyformatMoney', money);
   if (!money) {
     return '0.00';
   }

+ 5 - 3
src/views/h5/room/index.vue

@@ -245,7 +245,7 @@ const containerHeight = ref(0);
 const videoWrapHeight = ref(0);
 const frontendWechatQrcode = ref('');
 const remoteVideoRef = ref<HTMLDivElement>();
-
+const roomId = ref(route.params.roomId as string);
 const {
   videoWrapRef,
   handlePlay,
@@ -254,6 +254,7 @@ const {
   sendDanmu,
   closeRtc,
   closeWs,
+  handleSendGetLiveUser,
   isPlaying,
   autoplayVal,
   videoLoading,
@@ -263,7 +264,7 @@ const {
   anchorInfo,
   remoteVideo,
   videoHeight,
-} = usePull(route.params.roomId as string);
+} = usePull(roomId.value);
 
 onUnmounted(() => {
   closeWs();
@@ -288,6 +289,7 @@ onMounted(() => {
     }
   });
   getLiveRoomInfo();
+  handleSendGetLiveUser(Number(roomId.value));
 });
 
 function handlePushStr(str) {
@@ -340,7 +342,7 @@ function handleRefresh() {
 async function getLiveRoomInfo() {
   try {
     videoLoading.value = true;
-    const res = await fetchFindLiveRoom(route.params.roomId as string);
+    const res = await fetchFindLiveRoom(roomId.value);
     if (res.code === 200) {
       appStore.setLiveRoomInfo(res.data);
       if (res.data.type === LiveRoomTypeEnum.user_wertc) {

+ 2 - 0
src/views/pull/index.vue

@@ -467,6 +467,7 @@ const {
   keydownDanmu,
   sendDanmu,
   handlePlay,
+  handleSendGetLiveUser,
   danmuMsgType,
   msgIsFile,
   mySocketId,
@@ -499,6 +500,7 @@ onMounted(() => {
   initPull();
   getGiftRecord();
   getGiftGroupList();
+  handleSendGetLiveUser(Number(roomId.value));
 });
 
 onUnmounted(() => {

+ 11 - 0
src/views/push/index.vue

@@ -433,6 +433,8 @@ const {
   sendDanmu,
   keydownDanmu,
   sendBlob,
+  handleSendGetLiveUser,
+  roomId,
   msgIsFile,
   mySocketId,
   lastCoverImg,
@@ -686,6 +688,15 @@ function handleMsr(stream: MediaStream) {
   });
 }
 
+watch(
+  () => roomId.value,
+  (newval) => {
+    if (newval) {
+      handleSendGetLiveUser(Number(newval));
+    }
+  }
+);
+
 onMounted(() => {
   worker.value = new Worker('worker.js');
   setTimeout(() => {