|
@@ -1,3 +1,4 @@
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
import { reactive, ref, Ref } from 'vue'
|
|
|
import * as RongIMLib from '@rongcloud/imlib-next'
|
|
|
import * as RTC from '@rongcloud/plugin-rtc'
|
|
@@ -33,7 +34,7 @@ export const AUDIO_DEVICE_VOLUME = 'audio-device-volume'
|
|
|
|
|
|
const runtime = reactive({
|
|
|
/** 房间id */
|
|
|
- roomUid: 'LIVE-2112263-12345',
|
|
|
+ roomUid: sessionStorage.getItem('roomUid') || '',
|
|
|
/** IM连接状态 */
|
|
|
imConnectStatus: 'connecting' as imConnectStatus,
|
|
|
// 屏幕分享状态
|
|
@@ -380,18 +381,23 @@ export const joinRoom = async (roomId: string, type: RTC.RCLivingType, listenEve
|
|
|
*/
|
|
|
|
|
|
export const startLive = async (resetTime = true) => {
|
|
|
- if (runtime.videoStatus !== 'stream') throw Error('当前无视频流')
|
|
|
+ if (runtime.videoStatus !== 'stream') {
|
|
|
+ const errorMessage = '请确定摄像头已经开启'
|
|
|
+ ElMessage.error(errorMessage)
|
|
|
+ throw Error(errorMessage)
|
|
|
+ }
|
|
|
const room = runtime.joinedRoom
|
|
|
if (room) {
|
|
|
// const microphoneAudioTrack = await getTrack('microphone')
|
|
|
// const cameraVideoTrack = await getTrack('camera')
|
|
|
- // await setTrack([cameraVideoTrack], 'camera')
|
|
|
- // await setTrack([microphoneAudioTrack], 'microphone')
|
|
|
+ await setTrack([runtime.activeTracks.camera as RTC.RCLocalVideoTrack], 'camera')
|
|
|
+ await setTrack([runtime.activeTracks.microphone as RTC.RCLocalAudioTrack], 'microphone')
|
|
|
// const builder = await runtime.joinedRoom?.getMCUConfigBuilder()
|
|
|
// // @ts-ignore
|
|
|
// await builder.setOutputVideoRenderMode?.(RTC.MixVideoRenderMode.WHOLE)
|
|
|
// // @ts-ignore
|
|
|
// await builder.flush()
|
|
|
+ // console.log(runtime.activeTracks)
|
|
|
await request.get('/api-web/imLiveBroadcastRoom/opsLiveVideo', {
|
|
|
params: {
|
|
|
type: '1',
|
|
@@ -410,7 +416,7 @@ export const startLive = async (resetTime = true) => {
|
|
|
/**
|
|
|
* 关闭直播
|
|
|
*/
|
|
|
-export const closeLive = async () => {
|
|
|
+export const closeLive = async (remove = false) => {
|
|
|
// removeMedia(runtime.mediaStreams, runtime.mediaStreamTrack)
|
|
|
await request.get('/api-web/imLiveBroadcastRoom/opsLiveVideo', {
|
|
|
params: {
|
|
@@ -421,15 +427,19 @@ 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)) {
|
|
|
const track = runtime.activeTracks[key as TrackType] as RTC.RCLocalTrack
|
|
|
if (track) {
|
|
|
- removeTrack([track], key as TrackType)
|
|
|
+ await runtime.joinedRoom?.unpublish([track])
|
|
|
+ if (remove) {
|
|
|
+ await removeTrack([track], key as TrackType)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ runtime.videoStatus = 'stream'
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -537,7 +547,7 @@ export const toggleDevice = async (trackType: TrackType) => {
|
|
|
}
|
|
|
|
|
|
export const leaveIMRoom = async () => {
|
|
|
- await closeLive()
|
|
|
+ await closeLive(true)
|
|
|
if (runtime.joinedRoom) {
|
|
|
// @ts-ignore
|
|
|
await runtime.rtcClient?.leaveRoom(runtime.joinedRoom)
|