DialogPreviewVideo.vue
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<template>
  <div>
    <BasicModal
      v-bind="$attrs"
      width="55rem"
      destroyOnClose
      :height="heightNum"
      @register="register"
      title="视频预览"
      :showOkBtn="false"
      @cancel="handleCancel"
    >
      <div
        class="flex items-center justify-center bg-dark-900 w-full h-full min-h-96 video-container"
      >
        <BasicVideoPlay
          v-if="showVideo"
          :options="(options as any)"
          :withToken="withToken"
          @on-unmounted="handleCloseFlvPlayUrl"
        />
      </div>
    </BasicModal>
  </div>
</template>
<script setup lang="ts">
  import { ref, reactive, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import type { StreamingManageRecord, CameraModel } from '/@/api/camera/model/cameraModel';
  import { BasicVideoPlay, getVideoTypeByUrl } from '/@/components/Video';
  import { AccessMode } from './config.data';
  import { closeFlvPlay, getFlvPlayUrl, getStreamingPlayUrl } from '/@/api/camera/cameraManager';
  import { isRtspProtocol } from '/@/components/Video/src/utils';
  import { VideoJsPlayerOptions } from 'video.js';
  import { useFingerprint } from '/@/utils/useFingerprint';
  import { GetResult } from '@fingerprintjs/fingerprintjs';
  const heightNum = ref(800);
  const showVideo = ref(false);
  const playUrl = ref('');
  const withToken = ref(false);
  const fingerprintResult = ref<Nullable<GetResult>>(null);
  const options = reactive<VideoJsPlayerOptions>({
    width: '100%' as unknown as number,
    height: 384 as unknown as number,
    autoplay: true,
  });
  const setSources = (url: string, fingerprintResult: GetResult) => {
    const flag = isRtspProtocol(url);
    options.sources = [
      {
        src: flag ? getFlvPlayUrl(url, fingerprintResult.visitorId) : url,
        type: getVideoTypeByUrl(url),
      },
    ];
  };
  const { getResult } = useFingerprint();
  const [register] = useModalInner(
    async (data: { record: CameraModel | StreamingManageRecord }) => {
      const { record } = data;
      const result = await getResult();
      fingerprintResult.value = result;
      if (record.accessMode === AccessMode.ManuallyEnter) {
        if ((record as CameraModel).videoUrl) {
          if (isRtspProtocol((record as CameraModel).videoUrl)) {
            playUrl.value = (record as CameraModel).videoUrl;
            closeFlvPlay(unref(playUrl), result.visitorId);
            withToken.value = true;
          }
          setSources((record as CameraModel).videoUrl, result);
        }
      } else {
        try {
          const { data: { url } = { url: '' } } = await getStreamingPlayUrl(record.id!);
          setSources(url, result);
        } catch (error) {}
      }
      showVideo.value = true;
    }
  );
  const handleCloseFlvPlayUrl = () => {
    if (isRtspProtocol(unref(playUrl))) {
      closeFlvPlay(unref(playUrl)!, unref(fingerprintResult)!.visitorId!);
    }
  };
  const handleCancel = () => {
    showVideo.value = false;
    withToken.value = false;
  };
</script>
<style lang="less" scoped>
  .video-container:deep(.vben-basic-video-play) {
    min-height: 13rem;
  }
  .video-container:deep(.video-js) {
    min-height: 13rem;
  }
</style>