config.ts
3.33 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { PublicConfigClass } from '@/packages/public'
import { CreateComponentType } from '@/packages/index.d'
import { SingleCameraConfig } from './index'
import cloneDeep from 'lodash/cloneDeep'
import { StreamType } from "@/components/Video/src/types";
import { useFingerprint } from "@/utils/external/useFingerprint";
import { getOpenFlvPlayUrl, getVideoControlStart } from "@/api/external/flvPlay";
import { getVideoUrl } from "@/api/external/common";
import { CameraRecord } from "@/api/external/common/model";
import { useGlobSetting } from '@/hooks/external/setting';
export enum sourceTypeEnum {
CUSTOM = 'custom',
PLATFORM = 'platform'
}
export enum sourceTypeNameEnum {
CUSTOM = '自定义',
PLATFORM = '平台获取'
}
export enum FluoriteMideaProtocolEnum {
HLS = 2,
FLV = 4,
}
export enum VideoPlayerTypeEnum {
m3u8 = 'application/x-mpegURL',
mp4 = 'video/mp4',
webm = 'video/webm',
flv = 'video/x-flv'
}
export interface videoListInterface {
name: string
accessMode: number
id: string
videoUrl: string
label: string
value: string
sn: string
channelId: string
deviceId: string
customUrl: string
params: GBT28181Params
playProtocol?: number
}
export interface GBT28181Params {
channelNo: string
deviceId: string
deviceName: string
}
export enum AccessMode {
ManuallyEnter = 0, //手动输入
Streaming = 1, //流媒体
GBT28181 = 2 //GBT28181
}
export interface Dataset {
accessMode: AccessMode
channelId?: string
customUrl?: string
deviceId?: string
id?: string
value?: string
playProtocol?: number
}
export const option = {
dataset: {} as Dataset,
customVideoUrl: '', //用于手动输入视频流地址
autoplay: true,
poster: '',
sourceType: sourceTypeEnum.CUSTOM,
organization: '',
videoId: null
}
export default class Config extends PublicConfigClass implements CreateComponentType {
public key = SingleCameraConfig.key
public chartConfig = cloneDeep(SingleCameraConfig)
public option = cloneDeep(option)
}
export const isRtspProtocol = (url: string) => {
const reg = /^rtsp:\/\//g;
return reg.test(url);
};
export async function getPlayUrl(
params: CameraRecord
): Promise<{ url: string; type: StreamType } | undefined> {
const { accessMode } = params;
if (accessMode === AccessMode.ManuallyEnter) {
const { videoUrl } = params;
if (params.videoUrl) {
const isRTSPPlay = isRtspProtocol(videoUrl);
if (isRTSPPlay) {
const { getResult } = useFingerprint();
const fingerprint = await getResult();
return { url: getOpenFlvPlayUrl(videoUrl, fingerprint.visitorId), type: 'flv' };
} else {
return { url: videoUrl, type: 'auto' };
}
}
} else if (accessMode === AccessMode.GBT28181) {
const { securityPolicy } = useGlobSetting()
const { deviceId, channelNo } = params?.params || {};
const result = await getVideoControlStart({ channelId: channelNo!, deviceId: deviceId! });
return { url: securityPolicy ? result.data.https_flv : result.data.flv, type: 'flv' };
} else {
const { id, playProtocol } = params;
const result = await getVideoUrl(id);
const type: StreamType =
playProtocol === FluoriteMideaProtocolEnum.FLV
? 'flv'
: playProtocol === FluoriteMideaProtocolEnum.HLS
? 'hls'
: 'auto';
return { url: result.data.url, type };
}
}