|
@@ -5,6 +5,7 @@ import { useRoute } from 'vue-router';
|
|
|
import { commentAuthTip, loginTip } from '@/hooks/use-login';
|
|
import { commentAuthTip, loginTip } from '@/hooks/use-login';
|
|
|
import { useFlvPlay, useHlsPlay } from '@/hooks/use-play';
|
|
import { useFlvPlay, useHlsPlay } from '@/hooks/use-play';
|
|
|
import { useWebsocket } from '@/hooks/use-websocket';
|
|
import { useWebsocket } from '@/hooks/use-websocket';
|
|
|
|
|
+import { useWebRtcRtmpToRtc } from '@/hooks/webrtc/rtmpToRtc';
|
|
|
import {
|
|
import {
|
|
|
DanmuMsgTypeEnum,
|
|
DanmuMsgTypeEnum,
|
|
|
LiveLineEnum,
|
|
LiveLineEnum,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
LiveRoomUseCDNEnum,
|
|
LiveRoomUseCDNEnum,
|
|
|
} from '@/types/ILiveRoom';
|
|
} from '@/types/ILiveRoom';
|
|
|
import { WsMessageType, WsMsgTypeEnum } from '@/types/websocket';
|
|
import { WsMessageType, WsMsgTypeEnum } from '@/types/websocket';
|
|
|
-import { videoFullBox, videoToCanvas } from '@/utils';
|
|
|
|
|
|
|
+import { createVideo, videoFullBox, videoToCanvas } from '@/utils';
|
|
|
|
|
|
|
|
export function usePull() {
|
|
export function usePull() {
|
|
|
const route = useRoute();
|
|
const route = useRoute();
|
|
@@ -44,28 +45,30 @@ export function usePull() {
|
|
|
const isRemoteDesk = ref(false);
|
|
const isRemoteDesk = ref(false);
|
|
|
const videoElArr = ref<HTMLVideoElement[]>([]);
|
|
const videoElArr = ref<HTMLVideoElement[]>([]);
|
|
|
const remoteVideo = ref<HTMLElement[]>([]);
|
|
const remoteVideo = ref<HTMLElement[]>([]);
|
|
|
|
|
+ const remoteStream = ref<MediaStream[]>([]);
|
|
|
const { mySocketId, initWs, roomLiving, anchorInfo, liveUserList, damuList } =
|
|
const { mySocketId, initWs, roomLiving, anchorInfo, liveUserList, damuList } =
|
|
|
useWebsocket();
|
|
useWebsocket();
|
|
|
|
|
+ const { updateWebRtcRtmpToRtcConfig, webRtcRtmpToRtc } = useWebRtcRtmpToRtc();
|
|
|
|
|
+
|
|
|
const { flvVideoEl, flvIsPlaying, startFlvPlay, destroyFlv } = useFlvPlay();
|
|
const { flvVideoEl, flvIsPlaying, startFlvPlay, destroyFlv } = useFlvPlay();
|
|
|
const { hlsVideoEl, hlsIsPlaying, startHlsPlay, destroyHls } = useHlsPlay();
|
|
const { hlsVideoEl, hlsIsPlaying, startHlsPlay, destroyHls } = useHlsPlay();
|
|
|
const stopDrawingArr = ref<any[]>([]);
|
|
const stopDrawingArr = ref<any[]>([]);
|
|
|
|
|
+ const rtmpToRtcVido = ref<HTMLVideoElement>();
|
|
|
|
|
+
|
|
|
let changeWrapSizeFn;
|
|
let changeWrapSizeFn;
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
|
handleStopDrawing();
|
|
handleStopDrawing();
|
|
|
|
|
+ destroyFlv();
|
|
|
|
|
+ destroyHls();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
function handleStopDrawing() {
|
|
function handleStopDrawing() {
|
|
|
- destroyFlv();
|
|
|
|
|
- destroyHls();
|
|
|
|
|
changeWrapSizeFn = undefined;
|
|
changeWrapSizeFn = undefined;
|
|
|
stopDrawingArr.value.forEach((cb) => cb());
|
|
stopDrawingArr.value.forEach((cb) => cb());
|
|
|
stopDrawingArr.value = [];
|
|
stopDrawingArr.value = [];
|
|
|
remoteVideo.value.forEach((el) => el.remove());
|
|
remoteVideo.value.forEach((el) => el.remove());
|
|
|
remoteVideo.value = [];
|
|
remoteVideo.value = [];
|
|
|
- if (isRemoteDesk.value && videoWrapRef.value) {
|
|
|
|
|
- videoWrapRef.value.removeAttribute('style');
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function handleVideoWrapResize() {
|
|
function handleVideoWrapResize() {
|
|
@@ -78,8 +81,8 @@ export function usePull() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function videoPlay(videoEl: HTMLVideoElement) {
|
|
function videoPlay(videoEl: HTMLVideoElement) {
|
|
|
- stopDrawingArr.value = [];
|
|
|
|
|
stopDrawingArr.value.forEach((cb) => cb());
|
|
stopDrawingArr.value.forEach((cb) => cb());
|
|
|
|
|
+ stopDrawingArr.value = [];
|
|
|
if (appStore.videoControls.renderMode === LiveRenderEnum.canvas) {
|
|
if (appStore.videoControls.renderMode === LiveRenderEnum.canvas) {
|
|
|
if (videoEl && videoWrapRef.value) {
|
|
if (videoEl && videoWrapRef.value) {
|
|
|
const rect = videoWrapRef.value.getBoundingClientRect();
|
|
const rect = videoWrapRef.value.getBoundingClientRect();
|
|
@@ -120,17 +123,25 @@ export function usePull() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- watch(hlsVideoEl, (newval) => {
|
|
|
|
|
- if (newval) {
|
|
|
|
|
- videoPlay(newval);
|
|
|
|
|
|
|
+ watch(
|
|
|
|
|
+ () => hlsVideoEl.value,
|
|
|
|
|
+ (newval) => {
|
|
|
|
|
+ if (newval) {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ remoteStream.value.push(newval.captureStream());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- watch(flvVideoEl, (newval) => {
|
|
|
|
|
- if (newval) {
|
|
|
|
|
- videoPlay(newval);
|
|
|
|
|
|
|
+ watch(
|
|
|
|
|
+ () => flvVideoEl.value,
|
|
|
|
|
+ (newval) => {
|
|
|
|
|
+ if (newval) {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ remoteStream.value.push(newval.captureStream());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
watch(
|
|
watch(
|
|
|
() => appStore.videoControlsValue.pageFullMode,
|
|
() => appStore.videoControlsValue.pageFullMode,
|
|
@@ -140,64 +151,17 @@ export function usePull() {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
watch(
|
|
watch(
|
|
|
- () => appStore.videoControls.renderMode,
|
|
|
|
|
|
|
+ [() => appStore.videoControls.renderMode, () => remoteStream.value],
|
|
|
() => {
|
|
() => {
|
|
|
- if (appStore.liveRoomInfo) {
|
|
|
|
|
- handlePlay(appStore.liveRoomInfo);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- watch(
|
|
|
|
|
- () => networkStore.rtcMap,
|
|
|
|
|
- (newVal) => {
|
|
|
|
|
- if (newVal.size) {
|
|
|
|
|
- roomLiving.value = true;
|
|
|
|
|
- videoLoading.value = false;
|
|
|
|
|
- appStore.playing = true;
|
|
|
|
|
- // cacheStore.muted = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (
|
|
|
|
|
- isRemoteDesk.value ||
|
|
|
|
|
- appStore.liveRoomInfo?.type === LiveRoomTypeEnum.wertc_meeting_one ||
|
|
|
|
|
- appStore.liveRoomInfo?.type === LiveRoomTypeEnum.wertc_live ||
|
|
|
|
|
- appStore.liveRoomInfo?.type === LiveRoomTypeEnum.pk ||
|
|
|
|
|
- appStore.liveRoomInfo?.type === LiveRoomTypeEnum.tencent_css_pk
|
|
|
|
|
- ) {
|
|
|
|
|
- newVal.forEach((item) => {
|
|
|
|
|
- if (appStore.allTrack.find((v) => v.mediaName === item.receiver)) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- const rect = videoWrapRef.value?.getBoundingClientRect();
|
|
|
|
|
- if (rect) {
|
|
|
|
|
- videoFullBox({
|
|
|
|
|
- wrapSize: {
|
|
|
|
|
- width: rect.width,
|
|
|
|
|
- height: rect.height,
|
|
|
|
|
- },
|
|
|
|
|
- videoEl: item.videoEl,
|
|
|
|
|
- videoResize: ({ w, h }) => {
|
|
|
|
|
- videoResolution.value = `${w}x${h}`;
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- remoteVideo.value.push(item.videoEl);
|
|
|
|
|
- videoElArr.value.push(item.videoEl);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- nextTick(() => {
|
|
|
|
|
- if (isRemoteDesk.value && videoWrapRef.value) {
|
|
|
|
|
- if (newVal.size) {
|
|
|
|
|
- videoWrapRef.value.style.display = 'inline-block';
|
|
|
|
|
- } else {
|
|
|
|
|
- videoWrapRef.value.style.removeProperty('display');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ handleStopDrawing();
|
|
|
|
|
+ remoteStream.value.forEach((v) => {
|
|
|
|
|
+ const el = createVideo({});
|
|
|
|
|
+ el.srcObject = v;
|
|
|
|
|
+ videoPlay(el);
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
deep: true,
|
|
deep: true,
|
|
|
- immediate: true,
|
|
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -214,11 +178,34 @@ export function usePull() {
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ function handleRtmpToRtcPlay() {
|
|
|
|
|
+ console.log('handleRtmpToRtcPlay');
|
|
|
|
|
+ handleStopDrawing();
|
|
|
|
|
+ videoLoading.value = true;
|
|
|
|
|
+ appStore.liveLine = LiveLineEnum['rtmp-rtc'];
|
|
|
|
|
+ updateWebRtcRtmpToRtcConfig({
|
|
|
|
|
+ isPk: false,
|
|
|
|
|
+ roomId: roomId.value,
|
|
|
|
|
+ });
|
|
|
|
|
+ webRtcRtmpToRtc.newWebRtc({
|
|
|
|
|
+ sender: mySocketId.value,
|
|
|
|
|
+ receiver: 'rtmpToRtc',
|
|
|
|
|
+ videoEl: createVideo({}),
|
|
|
|
|
+ sucessCb: (stream) => {
|
|
|
|
|
+ remoteStream.value.push(stream);
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ webRtcRtmpToRtc.sendOffer({
|
|
|
|
|
+ sender: mySocketId.value,
|
|
|
|
|
+ receiver: 'rtmpToRtc',
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function handleHlsPlay() {
|
|
function handleHlsPlay() {
|
|
|
console.log('handleHlsPlay', hlsurl.value);
|
|
console.log('handleHlsPlay', hlsurl.value);
|
|
|
handleStopDrawing();
|
|
handleStopDrawing();
|
|
|
videoLoading.value = true;
|
|
videoLoading.value = true;
|
|
|
- appStore.setLiveLine(LiveLineEnum.hls);
|
|
|
|
|
|
|
+ appStore.liveLine = LiveLineEnum.hls;
|
|
|
startHlsPlay({
|
|
startHlsPlay({
|
|
|
hlsurl: hlsurl.value,
|
|
hlsurl: hlsurl.value,
|
|
|
});
|
|
});
|
|
@@ -228,7 +215,7 @@ export function usePull() {
|
|
|
console.log('handleFlvPlay', flvurl.value);
|
|
console.log('handleFlvPlay', flvurl.value);
|
|
|
handleStopDrawing();
|
|
handleStopDrawing();
|
|
|
videoLoading.value = true;
|
|
videoLoading.value = true;
|
|
|
- appStore.setLiveLine(LiveLineEnum.flv);
|
|
|
|
|
|
|
+ appStore.liveLine = LiveLineEnum.flv;
|
|
|
startFlvPlay({
|
|
startFlvPlay({
|
|
|
flvurl: flvurl.value,
|
|
flvurl: flvurl.value,
|
|
|
});
|
|
});
|
|
@@ -281,7 +268,7 @@ export function usePull() {
|
|
|
LiveRoomTypeEnum.wertc_meeting_two,
|
|
LiveRoomTypeEnum.wertc_meeting_two,
|
|
|
].includes(data.type!)
|
|
].includes(data.type!)
|
|
|
) {
|
|
) {
|
|
|
- appStore.setLiveLine(LiveLineEnum.rtc);
|
|
|
|
|
|
|
+ appStore.liveLine = LiveLineEnum.rtc;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -325,6 +312,11 @@ export function usePull() {
|
|
|
() => appStore.liveLine,
|
|
() => appStore.liveLine,
|
|
|
(newVal) => {
|
|
(newVal) => {
|
|
|
console.log('liveLine变了', newVal);
|
|
console.log('liveLine变了', newVal);
|
|
|
|
|
+ handleStopDrawing();
|
|
|
|
|
+ destroyFlv();
|
|
|
|
|
+ destroyHls();
|
|
|
|
|
+ remoteStream.value = [];
|
|
|
|
|
+
|
|
|
if (!roomLiving.value) {
|
|
if (!roomLiving.value) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -337,6 +329,9 @@ export function usePull() {
|
|
|
break;
|
|
break;
|
|
|
case LiveLineEnum.rtc:
|
|
case LiveLineEnum.rtc:
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case LiveLineEnum['rtmp-rtc']:
|
|
|
|
|
+ handleRtmpToRtcPlay();
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
@@ -396,15 +391,6 @@ export function usePull() {
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- watch(
|
|
|
|
|
- () => appStore.remoteDesk.isClose,
|
|
|
|
|
- (newval) => {
|
|
|
|
|
- if (newval) {
|
|
|
|
|
- handleStopDrawing();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
function initRoomId(id: string) {
|
|
function initRoomId(id: string) {
|
|
|
roomId.value = id;
|
|
roomId.value = id;
|
|
|
}
|
|
}
|
|
@@ -554,5 +540,6 @@ export function usePull() {
|
|
|
liveRoomInfo,
|
|
liveRoomInfo,
|
|
|
anchorInfo,
|
|
anchorInfo,
|
|
|
initRoomId,
|
|
initRoomId,
|
|
|
|
|
+ rtmpToRtcVido,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|