|
@@ -1,97 +0,0 @@
|
|
|
-<template>
|
|
|
- <div class="avatar-video" ref="refVideo"> </div>
|
|
|
-</template>
|
|
|
-<script lang="ts" setup>
|
|
|
- import { onMounted, onUnmounted, ref, unref, watch } from 'vue';
|
|
|
- import { computed } from 'vue';
|
|
|
- import { useRtcSdk } from '/@/hooks/useTRTC';
|
|
|
- import { useRtcStore } from '/@/store/modules/rtc';
|
|
|
-
|
|
|
- const rtcStore = useRtcStore();
|
|
|
- // const destination = computed(() => (rtcStore.isLeader ? '.local' : '.remote'));
|
|
|
- const isPublished = computed(() => rtcStore.isPublished);
|
|
|
- const remoteStreams = computed(() => rtcStore.remoteStreams);
|
|
|
- const refVideo = ref(null);
|
|
|
- const initHostCam = ref(false);
|
|
|
- const initCustomCam = ref(false);
|
|
|
-
|
|
|
- const handleCapVideoElement = (event) => {
|
|
|
- const { localStream } = useRtcSdk();
|
|
|
- const steamId = localStream.getId();
|
|
|
- initHostCam.value = true;
|
|
|
- if (event.type === 'video' && event.state === 'PLAYING') {
|
|
|
- const localVideo = document.getElementById(`video_${steamId}`);
|
|
|
- const avatarVideo = document.querySelector('.avatar-video');
|
|
|
- avatarVideo && localVideo && avatarVideo.append(localVideo);
|
|
|
- console.log('localVideo', `video_${steamId}`, localVideo);
|
|
|
- }
|
|
|
- };
|
|
|
- const handleCapVideoRemoteElement = () => {
|
|
|
- const remoteStream = unref(remoteStreams)[0];
|
|
|
- const steamId = remoteStream.getId();
|
|
|
- initCustomCam.value = true;
|
|
|
- const remoteVideo = document.getElementById(`video_${steamId}`);
|
|
|
- const avatarVideo = document.querySelector('.avatar-video');
|
|
|
- const preVideo = document.querySelector('.avatar-video video');
|
|
|
- preVideo && avatarVideo?.removeChild(preVideo);
|
|
|
- avatarVideo && remoteVideo && avatarVideo.append(remoteVideo);
|
|
|
- console.log('remoteVideo', `video_${steamId}`, remoteVideo);
|
|
|
- };
|
|
|
- onUnmounted(() => {
|
|
|
- const { localStream } = useRtcSdk();
|
|
|
- localStream && localStream.off('player-state-changed', handleCapVideoElement);
|
|
|
- });
|
|
|
-
|
|
|
- onMounted(() => {
|
|
|
- watch(
|
|
|
- () => isPublished,
|
|
|
- (val) => {
|
|
|
- if (unref(val) && !unref(initHostCam)) {
|
|
|
- if (rtcStore.isLeader) {
|
|
|
- const { localStream } = useRtcSdk();
|
|
|
- const hasVideo = localStream.hasVideo();
|
|
|
- if (hasVideo) {
|
|
|
- localStream.on('player-state-changed', handleCapVideoElement);
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.log('gemer', remoteStreams);
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- deep: true,
|
|
|
- },
|
|
|
- );
|
|
|
- watch(
|
|
|
- () => remoteStreams,
|
|
|
- (val) => {
|
|
|
- if (unref(val)?.length) {
|
|
|
- if (!rtcStore.isLeader) {
|
|
|
- const remoteStreams = unref(val)[0];
|
|
|
- const hasVideo = remoteStreams.hasVideo();
|
|
|
- if (hasVideo) {
|
|
|
- setTimeout(() => {
|
|
|
- handleCapVideoRemoteElement();
|
|
|
- }, 2000);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- deep: true,
|
|
|
- },
|
|
|
- );
|
|
|
- });
|
|
|
-</script>
|
|
|
-<style scoped lang="scss">
|
|
|
- .avatar-video {
|
|
|
- width: 1.94rem;
|
|
|
- height: 1.94rem;
|
|
|
- position: fixed;
|
|
|
- top: 0.69rem;
|
|
|
- left: 0.53rem;
|
|
|
- overflow: hidden;
|
|
|
- z-index: 10000;
|
|
|
- border-radius: 50%;
|
|
|
- }
|
|
|
-</style>
|