|
@@ -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)) {
|