Explorar o código

直播状态中刷新页面继续直播

wolyshaw %!s(int64=3) %!d(string=hai) anos
pai
achega
405c370aee

+ 1 - 3
package-lock.json

@@ -3614,12 +3614,11 @@
         }
       }
     },
-<<<<<<< HEAD
     "loaders.css": {
       "version": "0.1.2",
       "resolved": "https://registry.npmjs.org/loaders.css/-/loaders.css-0.1.2.tgz",
       "integrity": "sha1-Op+0NybHMzSjgUKvnQYpAZtlh0M="
-=======
+    },
     "locate-path": {
       "version": "5.0.0",
       "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@@ -3627,7 +3626,6 @@
       "requires": {
         "p-locate": "^4.1.0"
       }
->>>>>>> 8d813a91342ab66bfc7d529943b3c3611d527f7c
     },
     "lodash": {
       "version": "4.17.21",

+ 3 - 0
src/components/live-broadcast/index.tsx

@@ -83,6 +83,9 @@ export default defineComponent({
             console.log('onUserLeave', userIds)
           },
         })
+        if (sessionStorage.getItem(RuntimeUtils.START_LIVE_STATUS) === 'liveing') {
+          await RuntimeUtils.startLive()
+        }
         if (join.room && join.code === RTC.RCRTCCode.SUCCESS) {
           runtime.joinedRoom = join.room
         }

+ 13 - 6
src/components/live-broadcast/runtime.ts

@@ -23,6 +23,8 @@ type DeviceStatus = {
 
 export const START_LIVE_TIME = 'start-live-time'
 
+export const START_LIVE_STATUS = 'start-live-status'
+
 const runtime = reactive({
   /** 房间id */
   roomUid: 'LIVE-2112263-12345',
@@ -334,6 +336,14 @@ export const removeTrack = async (tracks: RTC.RCLocalTrack[], trackType: TrackTy
   }
 }
 
+export const joinIMRoom = async (roomId: string, type: RTC.RCLivingType, listenEvents: RTC.IRoomEventListener | null) => {
+  await RongIMLib.joinChatRoom(roomId, {count: -1})
+  const join = await runtime.rtcClient?.joinLivingRoom(roomId, type)
+  if (join?.code != RTC.RCRTCCode.SUCCESS) throw Error('加入房间失败')
+  join.room?.registerRoomEventListener(listenEvents)
+  return join
+}
+
 export const joinRoom = async (roomId: string, type: RTC.RCLivingType, listenEvents: RTC.IRoomEventListener | null) => {
   try {
     await request.get('/api-web/imLiveBroadcastRoom/joinRoom', {
@@ -343,11 +353,7 @@ export const joinRoom = async (roomId: string, type: RTC.RCLivingType, listenEve
       }
     })
   } catch (error) {}
-  await RongIMLib.joinChatRoom(roomId, {count: -1})
-  const join = await runtime.rtcClient?.joinLivingRoom(roomId, type)
-  if (join?.code != RTC.RCRTCCode.SUCCESS) throw Error('加入房间失败')
-  join.room?.registerRoomEventListener(listenEvents)
-  return join
+  return await joinIMRoom(roomId, type, listenEvents)
 }
 
 /**
@@ -359,7 +365,6 @@ export const startLive = async () => {
   const room = runtime.joinedRoom
   if (room) {
     const microphoneAudioTrack = await getTrack('microphone')
-    console.log(microphoneAudioTrack)
     const cameraVideoTrack = await getTrack('camera')
     await setTrack([cameraVideoTrack], 'camera')
     await setTrack([microphoneAudioTrack], 'microphone')
@@ -371,6 +376,7 @@ export const startLive = async () => {
     runtime.videoStatus = 'liveing'
   }
   sessionStorage.setItem(START_LIVE_TIME, dayjs().valueOf().toString())
+  sessionStorage.setItem(START_LIVE_STATUS, 'liveing')
 }
 
 /**
@@ -386,6 +392,7 @@ export const closeLive = async () => {
   //   }
   // })
   sessionStorage.removeItem(START_LIVE_TIME)
+  sessionStorage.removeItem(START_LIVE_STATUS)
   runtime.videoStatus = 'stream'
   for (const key in runtime.activeTracks) {
     if (Object.prototype.hasOwnProperty.call(runtime.activeTracks, key)) {