@cloud-app-dev/vidc 3.0.9 → 3.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +1 -1
- package/.umirc.ts +3 -2
- package/clear-cache.sh +4 -0
- package/es/CustomRenderSelect/index.css +20 -0
- package/es/CustomRenderSelect/index.d.ts +10 -0
- package/es/CustomRenderSelect/index.js +73 -0
- package/es/List/DynamicGridList/index.js +4 -3
- package/es/List/DynamicList/utils.d.ts +1 -1
- package/es/List/DynamicList/utils.js +1 -1
- package/es/List/GridList/Demo.js +1 -1
- package/es/Player/api/index.d.ts +4 -4
- package/es/Player/contraller_bar/contraller_event.js +1 -1
- package/es/Player/demo.js +36 -12
- package/es/Player/event/errorEvent.d.ts +2 -2
- package/es/Player/event/errorEvent.js +2 -2
- package/es/Player/live_heart.d.ts +4 -2
- package/es/Player/live_heart.js +24 -12
- package/es/Player/message.js +4 -4
- package/es/Player/player.d.ts +4 -4
- package/es/Player/segment_player.js +1 -0
- package/es/Player/segment_timeline.d.ts +2 -1
- package/es/Player/segment_timeline.js +7 -12
- package/es/Player/single_player.js +2 -1
- package/es/Player/style/iconfont.css +150 -33
- package/es/Player/style/iconfont.ttf +0 -0
- package/es/Player/style/iconfont.woff +0 -0
- package/es/Player/style/iconfont.woff2 +0 -0
- package/es/Player/util.d.ts +1 -1
- package/es/Player/util.js +17 -22
- package/es/ScreenPlayer/Live.d.ts +1 -1
- package/es/ScreenPlayer/Live.js +67 -14
- package/es/ScreenPlayer/LiveTools.d.ts +3 -1
- package/es/ScreenPlayer/LiveTools.js +69 -33
- package/es/ScreenPlayer/PlayerWithExt.d.ts +2 -2
- package/es/ScreenPlayer/PlayerWithExt.js +5 -4
- package/es/ScreenPlayer/Record.d.ts +1 -1
- package/es/ScreenPlayer/Record.js +64 -32
- package/es/ScreenPlayer/RecordTools.d.ts +2 -1
- package/es/ScreenPlayer/RecordTools.js +46 -36
- package/es/ScreenPlayer/ScreenSelect.js +41 -20
- package/es/ScreenPlayer/SegmentTimeLine.d.ts +2 -2
- package/es/ScreenPlayer/SegmentTimeLine.js +17 -36
- package/es/ScreenPlayer/TimeMode.js +8 -2
- package/es/ScreenPlayer/TimeSlider.d.ts +2 -2
- package/es/ScreenPlayer/TimeSlider.js +15 -15
- package/es/ScreenPlayer/demo.js +4 -4
- package/es/ScreenPlayer/demo2.js +1 -1
- package/es/ScreenPlayer/index.css +29 -10
- package/es/ScreenPlayer/interface.d.ts +24 -4
- package/es/ScreenPlayer/useTimeSlider.d.ts +22 -0
- package/es/ScreenPlayer/useTimeSlider.js +485 -0
- package/es/ScreenPlayer/utils.d.ts +1 -0
- package/es/ScreenPlayer/utils.js +17 -8
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/package.json +2 -2
package/es/ScreenPlayer/demo.js
CHANGED
|
@@ -3,16 +3,16 @@ import _ConfigProvider from "antd/lib/config-provider";
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import LivePlayer from './Live';
|
|
5
5
|
var list = [{
|
|
6
|
-
url: 'https://6a75ef90-
|
|
6
|
+
url: 'https://6a75ef90-3-server.antelopecloud.cn/flv_live?app=live&token=542446023_3356491776_1693558509_61374ba6efe326a4cb8b6bae86917a25',
|
|
7
7
|
type: 'flv'
|
|
8
8
|
}, {
|
|
9
|
-
url: 'https://
|
|
9
|
+
url: 'https://6a75ef89-1-server.antelopecloud.cn/flv_live?app=live&token=542446501_3356491776_1693535295_37062417b87df4be7dd5c02b01d87248',
|
|
10
10
|
type: 'flv'
|
|
11
11
|
}, {
|
|
12
|
-
url: 'https://6a75ef90-
|
|
12
|
+
url: 'https://6a75ef90-1-server.antelopecloud.cn/flv_live?app=live&token=542453821_3356491776_1693535323_3a90f54c141b9a246d5679678ebafe90',
|
|
13
13
|
type: 'flv'
|
|
14
14
|
}, {
|
|
15
|
-
url: 'https://6a75ef90-
|
|
15
|
+
url: 'https://6a75ef90-6-server.antelopecloud.cn/flv_live?app=live&token=542449206_3356491776_1693535342_803846974f04eb02e8115d10432d062f',
|
|
16
16
|
type: 'flv'
|
|
17
17
|
}];
|
|
18
18
|
export default function App() {
|
package/es/ScreenPlayer/demo2.js
CHANGED
|
@@ -28,7 +28,7 @@ import RecordPlayer from './Record';
|
|
|
28
28
|
import moment from 'moment';
|
|
29
29
|
import Service from '../Service';
|
|
30
30
|
import { completionSegments } from './utils';
|
|
31
|
-
var token = "eyJhbGciOiJIUzI1NiJ9.
|
|
31
|
+
var token = "eyJhbGciOiJIUzI1NiJ9.eyJvcmdhbml6YXRpb25JZCI6IjEwMDEwMTAwMDQ0NSIsImV4dCI6MTY2MjI1ODMwNzUxNSwidWlkIjoiMTAxMDAwMDAwNjk5IiwidmFsaWRTdGF0ZSI6MTA0NDA2LCJyb2xlSWQiOlsxMDAwMDAxMTA1MTgsMTAwMDAwMTEwNzI4XSwidmFsaWRUaW1lIjoxNzA0MzgzOTk5MDAwLCJvcHRDZW50ZXJJZCI6IjEwMDEwMDAwMDIzMyIsInVzZXJUeXBlIjoxMDA3MDQsImlhdCI6MTY2MTk5OTEwNzUxNX0.uk_G3vqBCFqxQM2jbV6CSN-z9YNVt_cx5nWXkSuCOIA";
|
|
32
32
|
var cids = ['538509097', '539172446'];
|
|
33
33
|
|
|
34
34
|
var query = function query(_ref) {
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
.split-screen-player-wrapper .player-layout .player-with-ext-layout.player-current-index .lm-player-ext-layout {
|
|
20
20
|
border: 1px solid var(--primary);
|
|
21
21
|
}
|
|
22
|
+
.split-screen-player-wrapper.split-screen-player-live-wrapper .player-layout {
|
|
23
|
+
height: calc(100% - 42px);
|
|
24
|
+
}
|
|
22
25
|
.split-screen-player-wrapper .player-tools-group {
|
|
23
26
|
height: 88px;
|
|
24
27
|
position: relative;
|
|
25
28
|
}
|
|
26
29
|
.split-screen-player-wrapper .player-record-time {
|
|
27
|
-
width: 100%;
|
|
28
|
-
height: 100%;
|
|
29
30
|
text-align: center;
|
|
30
31
|
background-color: var(--gray11);
|
|
31
32
|
line-height: 42px;
|
|
@@ -69,7 +70,8 @@
|
|
|
69
70
|
color: var(--gray1);
|
|
70
71
|
text-align: center;
|
|
71
72
|
cursor: pointer;
|
|
72
|
-
margin-right:
|
|
73
|
+
margin-right: 10px;
|
|
74
|
+
display: inline-block;
|
|
73
75
|
}
|
|
74
76
|
.split-screen-player-wrapper .player-tools .player-tools-item .lm-player-iconfont {
|
|
75
77
|
font-size: 20px;
|
|
@@ -78,6 +80,23 @@
|
|
|
78
80
|
background-color: var(--gray11);
|
|
79
81
|
border-radius: var(--radius1);
|
|
80
82
|
}
|
|
83
|
+
.split-screen-player-wrapper .player-tools .select-current-screen-item {
|
|
84
|
+
font-size: 18px;
|
|
85
|
+
width: 32px;
|
|
86
|
+
height: 32px;
|
|
87
|
+
color: var(--gray1);
|
|
88
|
+
text-align: center;
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
margin-right: 6px;
|
|
91
|
+
display: inline-block;
|
|
92
|
+
}
|
|
93
|
+
.split-screen-player-wrapper .player-tools .select-current-screen-item .lm-player-iconfont {
|
|
94
|
+
font-size: 20px;
|
|
95
|
+
}
|
|
96
|
+
.split-screen-player-wrapper .player-tools .select-current-screen-item:hover {
|
|
97
|
+
background-color: var(--gray11);
|
|
98
|
+
border-radius: var(--radius1);
|
|
99
|
+
}
|
|
81
100
|
.split-screen-player-wrapper.split-screen-player-wrapper-record .record-time-line {
|
|
82
101
|
width: 100%;
|
|
83
102
|
height: 46px;
|
|
@@ -105,20 +124,20 @@
|
|
|
105
124
|
justify-content: space-around;
|
|
106
125
|
align-items: center;
|
|
107
126
|
}
|
|
108
|
-
.time-mode-select {
|
|
127
|
+
.cloudapp-select.time-mode-select {
|
|
109
128
|
font-size: var(--fs-small);
|
|
110
129
|
color: var(--gray1);
|
|
111
130
|
}
|
|
112
|
-
.time-mode-select .cloudapp-select-selector {
|
|
113
|
-
background-color: transparent
|
|
114
|
-
border-radius: var(--radius1)
|
|
131
|
+
.cloudapp-select.time-mode-select .cloudapp-select-selector {
|
|
132
|
+
background-color: transparent;
|
|
133
|
+
border-radius: var(--radius1);
|
|
115
134
|
}
|
|
116
|
-
.time-mode-select .anticon {
|
|
135
|
+
.cloudapp-select.time-mode-select .anticon {
|
|
117
136
|
color: var(--gray1);
|
|
118
137
|
}
|
|
119
|
-
.
|
|
138
|
+
.custom-select-dropdown {
|
|
120
139
|
font-size: var(--fs-small);
|
|
121
140
|
}
|
|
122
|
-
.
|
|
141
|
+
.custom-select-dropdown .cloudapp-select-item {
|
|
123
142
|
font-size: var(--fs-small);
|
|
124
143
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { PlayModeType } from '../PlayerExt';
|
|
2
3
|
import { ISegmentType } from '../Player/player';
|
|
3
4
|
|
|
4
5
|
export type RecordItem = {
|
|
@@ -8,6 +9,7 @@ export type RecordItem = {
|
|
|
8
9
|
segments?: ISegmentType[];
|
|
9
10
|
url?: string;
|
|
10
11
|
recordType?: 1 | 2; //1云录像 2前端录像
|
|
12
|
+
mode?: PlayModeType;
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
export interface IRecordPlayerProps {
|
|
@@ -22,7 +24,7 @@ export interface IRecordPlayerProps {
|
|
|
22
24
|
/**
|
|
23
25
|
* 窗口索引变化,后续基于索引传入播放必要数据
|
|
24
26
|
*/
|
|
25
|
-
onIndexChange
|
|
27
|
+
onIndexChange?: (idx: number) => void;
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* 关闭单个窗口
|
|
@@ -37,6 +39,14 @@ export interface IRecordPlayerProps {
|
|
|
37
39
|
* 录像下载回调
|
|
38
40
|
*/
|
|
39
41
|
download?: () => void;
|
|
42
|
+
|
|
43
|
+
snapshot?: (base64: string) => void;
|
|
44
|
+
|
|
45
|
+
screenChange?: (num: number) => void;
|
|
46
|
+
|
|
47
|
+
defaultScreen?: 1 | 4 | 6 | 9 | 16;
|
|
48
|
+
|
|
49
|
+
defaultSelectIndex?: number;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
export interface IRecordPlayerState {
|
|
@@ -53,7 +63,7 @@ export interface IRecordPlayerState {
|
|
|
53
63
|
/**
|
|
54
64
|
* 插件OR浏览器
|
|
55
65
|
*/
|
|
56
|
-
|
|
66
|
+
modes: PlayModeType[];
|
|
57
67
|
|
|
58
68
|
/**
|
|
59
69
|
* 时间轴开始时间
|
|
@@ -84,6 +94,8 @@ export interface IRecordPlayerState {
|
|
|
84
94
|
export type ScreenItemLivePlayerType = {
|
|
85
95
|
url?: string;
|
|
86
96
|
type?: 'flv' | 'hls' | 'native';
|
|
97
|
+
mode?: PlayModeType;
|
|
98
|
+
cid?: string;
|
|
87
99
|
};
|
|
88
100
|
|
|
89
101
|
export interface ILivePlayerProps {
|
|
@@ -102,13 +114,21 @@ export interface ILivePlayerProps {
|
|
|
102
114
|
/**
|
|
103
115
|
* 窗口索引变化,后续基于索引传入播放必要数据
|
|
104
116
|
*/
|
|
105
|
-
onIndexChange
|
|
117
|
+
onIndexChange?: (idx: number) => void;
|
|
118
|
+
|
|
119
|
+
snapshot?: (base64: string) => void;
|
|
120
|
+
|
|
121
|
+
screenChange?: (num: number) => void;
|
|
122
|
+
|
|
123
|
+
defaultScreen?: 1 | 4 | 6 | 9 | 16;
|
|
124
|
+
|
|
125
|
+
defaultSelectIndex?: number;
|
|
106
126
|
}
|
|
107
127
|
|
|
108
128
|
export interface ILivePlayerState {
|
|
109
129
|
screenNum: number;
|
|
110
130
|
selectIndex: number;
|
|
111
|
-
|
|
131
|
+
modes: PlayModeType[];
|
|
112
132
|
}
|
|
113
133
|
|
|
114
134
|
export const RecordPlayer: React.FC<IRecordPlayerProps>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ISegmentType } from '../Player/player';
|
|
3
|
+
export interface ITimeSliderOptions {
|
|
4
|
+
hoursPer?: number;
|
|
5
|
+
begin?: number;
|
|
6
|
+
segments?: TimeCellItem[];
|
|
7
|
+
currentTime?: number;
|
|
8
|
+
onTimeChange?: (time: number, outTimeline?: boolean) => void;
|
|
9
|
+
onHoursPerChange?: (hour: number) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare type ITimeSliderState = {
|
|
12
|
+
hoursPer: number;
|
|
13
|
+
begin: number;
|
|
14
|
+
currentTime: number;
|
|
15
|
+
hover: {
|
|
16
|
+
x: number;
|
|
17
|
+
time: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare type TimeCellItem = ISegmentType;
|
|
21
|
+
declare function useTimeSlider(canvasRef: React.MutableRefObject<HTMLCanvasElement>, { hoursPer, begin, currentTime, segments, onTimeChange, onHoursPerChange }: ITimeSliderOptions): void;
|
|
22
|
+
export default useTimeSlider;
|
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import _nextTick from "@cloud-app-dev/utils/es/nextTick";
|
|
2
|
+
import _useEventListener from "ahooks/es/useEventListener";
|
|
3
|
+
import _useUpdateEffect from "ahooks/es/useUpdateEffect";
|
|
4
|
+
import _useSize from "ahooks/es/useSize";
|
|
5
|
+
|
|
6
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
7
|
+
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
13
|
+
|
|
14
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
15
|
+
|
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
+
|
|
18
|
+
import moment from 'moment';
|
|
19
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
20
|
+
var hours = [1, 6, 12, 24];
|
|
21
|
+
var currentColor = '#FF000A';
|
|
22
|
+
var normalLineColor = '#ffffff';
|
|
23
|
+
var hoverLineColor = '#319BFF';
|
|
24
|
+
var minPerStep = [1, 2, 5, 10, 15, 20, 30, 60, 120, 180, 240, 360, 720, 1440];
|
|
25
|
+
var minStepSize = 20;
|
|
26
|
+
var distance_between_gtitle = 80;
|
|
27
|
+
/**
|
|
28
|
+
* 下一个刻度
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
function ms_to_next_step(timestamp, step) {
|
|
32
|
+
var remainder = timestamp % step;
|
|
33
|
+
return remainder ? step - remainder : 0;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 返回 2018-01-01 10:00:00 格式时间
|
|
37
|
+
* @param {*} time
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function formartTimestemp(time) {
|
|
42
|
+
return moment(time).format('YYYY-MM-DD HH:mm:ss');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 返回时间轴上刻度的时间
|
|
46
|
+
* @param {*} datetime new Date 格式
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function graduation_title(datetime) {
|
|
51
|
+
var mom = moment(datetime);
|
|
52
|
+
var h = mom.get('hours');
|
|
53
|
+
var m = mom.get('minutes');
|
|
54
|
+
var s = mom.get('seconds');
|
|
55
|
+
|
|
56
|
+
if (h === 0 && m === 0 && s === 0) {
|
|
57
|
+
return mom.format('YYYY.MM.DD');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return mom.format('HH:mm');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 绘制线条
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
function drawLine(ctx, beginX, beginY, endX, endY, color, width) {
|
|
68
|
+
ctx.beginPath();
|
|
69
|
+
ctx.moveTo(beginX, beginY);
|
|
70
|
+
ctx.lineTo(endX, endY);
|
|
71
|
+
ctx.strokeStyle = color;
|
|
72
|
+
ctx.lineWidth = width;
|
|
73
|
+
ctx.stroke();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function drawText(ctx, _ref) {
|
|
77
|
+
var fillStyle = _ref.fillStyle,
|
|
78
|
+
font = _ref.font,
|
|
79
|
+
text = _ref.text,
|
|
80
|
+
x = _ref.x,
|
|
81
|
+
y = _ref.y;
|
|
82
|
+
ctx.fillStyle = fillStyle;
|
|
83
|
+
ctx.font = font;
|
|
84
|
+
ctx.fillText(text, x, y);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function useTimeSlider(canvasRef, _ref2) {
|
|
88
|
+
var hoursPer = _ref2.hoursPer,
|
|
89
|
+
begin = _ref2.begin,
|
|
90
|
+
currentTime = _ref2.currentTime,
|
|
91
|
+
_ref2$segments = _ref2.segments,
|
|
92
|
+
segments = _ref2$segments === void 0 ? [] : _ref2$segments,
|
|
93
|
+
onTimeChange = _ref2.onTimeChange,
|
|
94
|
+
onHoursPerChange = _ref2.onHoursPerChange;
|
|
95
|
+
|
|
96
|
+
var _useState = useState({
|
|
97
|
+
hoursPer: hoursPer,
|
|
98
|
+
begin: begin,
|
|
99
|
+
currentTime: currentTime,
|
|
100
|
+
hover: {
|
|
101
|
+
x: 0,
|
|
102
|
+
time: null
|
|
103
|
+
}
|
|
104
|
+
}),
|
|
105
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
106
|
+
state = _useState2[0],
|
|
107
|
+
setState = _useState2[1];
|
|
108
|
+
|
|
109
|
+
var extRef = useRef({
|
|
110
|
+
mousedownTime: null,
|
|
111
|
+
mousedownX: 0
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
var size = _useSize(canvasRef);
|
|
115
|
+
|
|
116
|
+
var canvas = canvasRef.current;
|
|
117
|
+
|
|
118
|
+
var _useMemo = useMemo(function () {
|
|
119
|
+
return size ? size : {
|
|
120
|
+
width: 0,
|
|
121
|
+
height: 0
|
|
122
|
+
};
|
|
123
|
+
}, [size]),
|
|
124
|
+
width = _useMemo.width,
|
|
125
|
+
height = _useMemo.height;
|
|
126
|
+
|
|
127
|
+
var ctx = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
|
|
128
|
+
|
|
129
|
+
var update = function update() {
|
|
130
|
+
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
131
|
+
return setState(function (old) {
|
|
132
|
+
return Object.assign(Object.assign({}, old), params);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
var clearCanvas = useCallback(function () {
|
|
137
|
+
return ctx.clearRect(0, 0, width, height);
|
|
138
|
+
}, [ctx, width, height]);
|
|
139
|
+
var drawOverlay = useCallback(function () {
|
|
140
|
+
segments.forEach(function (item) {
|
|
141
|
+
var _a;
|
|
142
|
+
|
|
143
|
+
var px_ms = width / (state.hoursPer * 60 * 60 * 1000); // px/ms
|
|
144
|
+
|
|
145
|
+
var beginX = (item.beginTime - state.begin) * px_ms;
|
|
146
|
+
var scale_width = (item.endTime - item.beginTime) * px_ms;
|
|
147
|
+
ctx.fillStyle = item.url ? ((_a = item.style) === null || _a === void 0 ? void 0 : _a.background) || hoverLineColor : '#242C3D';
|
|
148
|
+
ctx.fillRect(beginX, height - 10, scale_width + 1, height);
|
|
149
|
+
});
|
|
150
|
+
}, [ctx, segments, height, width, state.begin, state.hoursPer]);
|
|
151
|
+
/**
|
|
152
|
+
* 绘制刻度相关的
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
var drawScale = useCallback(function () {
|
|
156
|
+
var px_per_min = width / (state.hoursPer * 60); // px/min
|
|
157
|
+
|
|
158
|
+
var px_per_ms = width / (state.hoursPer * 60 * 60 * 1000); // px/ms
|
|
159
|
+
|
|
160
|
+
var px_per_step = minStepSize; // px/格 默认最小值20px
|
|
161
|
+
|
|
162
|
+
var min_per_step = px_per_step / px_per_min; // min/格
|
|
163
|
+
|
|
164
|
+
for (var i = 0; i < minPerStep.length; i++) {
|
|
165
|
+
if (min_per_step <= minPerStep[i]) {
|
|
166
|
+
//让每格时间在minutes_per_step规定的范围内
|
|
167
|
+
min_per_step = minPerStep[i];
|
|
168
|
+
px_per_step = px_per_min * min_per_step;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var medium_step = 30;
|
|
174
|
+
|
|
175
|
+
for (var _i2 = 0; _i2 < minPerStep.length; _i2++) {
|
|
176
|
+
if (distance_between_gtitle / px_per_min <= minPerStep[_i2]) {
|
|
177
|
+
medium_step = minPerStep[_i2];
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
var num_steps = width / px_per_step; //总格数
|
|
183
|
+
|
|
184
|
+
var ms_offset = ms_to_next_step(state.begin, min_per_step * 60 * 1000); //开始的偏移时间 ms
|
|
185
|
+
|
|
186
|
+
var px_offset = ms_offset * px_per_ms; //开始的偏移距离 px
|
|
187
|
+
|
|
188
|
+
var ms_per_step = px_per_step / px_per_ms; // ms/step
|
|
189
|
+
|
|
190
|
+
var graduation_left, graduation_time, lineH;
|
|
191
|
+
|
|
192
|
+
for (var _i3 = 0; _i3 < num_steps; _i3++) {
|
|
193
|
+
graduation_left = px_offset + _i3 * px_per_step; // 距离=开始的偏移距离+格数*px/格
|
|
194
|
+
|
|
195
|
+
graduation_time = state.begin + ms_offset + _i3 * ms_per_step; //时间=左侧开始时间+偏移时间+格数*ms/格
|
|
196
|
+
|
|
197
|
+
var date = moment(graduation_time);
|
|
198
|
+
|
|
199
|
+
if (date.get('hours') === 0 && date.get('minutes') === 0) {
|
|
200
|
+
lineH = 10;
|
|
201
|
+
var big_date = graduation_title(date.valueOf());
|
|
202
|
+
var x = graduation_left - 12;
|
|
203
|
+
drawText(ctx, {
|
|
204
|
+
fillStyle: normalLineColor,
|
|
205
|
+
font: '10px Arial',
|
|
206
|
+
x: x,
|
|
207
|
+
y: 30,
|
|
208
|
+
text: big_date
|
|
209
|
+
});
|
|
210
|
+
} else if (graduation_time / (60 * 1000) % medium_step === 0) {
|
|
211
|
+
lineH = 10;
|
|
212
|
+
var middle_date = graduation_title(date.valueOf());
|
|
213
|
+
|
|
214
|
+
var _x = graduation_left - (middle_date.length > 5 ? 24 : 12);
|
|
215
|
+
|
|
216
|
+
drawText(ctx, {
|
|
217
|
+
fillStyle: normalLineColor,
|
|
218
|
+
font: '10px Arial',
|
|
219
|
+
x: _x,
|
|
220
|
+
y: 30,
|
|
221
|
+
text: middle_date
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
lineH = 5;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
drawLine(ctx, graduation_left, height - lineH, graduation_left, height, normalLineColor, 2);
|
|
228
|
+
}
|
|
229
|
+
}, [ctx, height, width, state.begin, state.hoursPer]);
|
|
230
|
+
/**
|
|
231
|
+
* 绘制当前刻度
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
var drawCurrentLine = useCallback(function () {
|
|
236
|
+
var currentTime = state.currentTime,
|
|
237
|
+
begin = state.begin,
|
|
238
|
+
hoursPer = state.hoursPer;
|
|
239
|
+
var time = currentTime;
|
|
240
|
+
var range = [begin, currentTime + hoursPer * 3600 * 1000];
|
|
241
|
+
|
|
242
|
+
if (time < range[0] || time > range[1]) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
var ms_current = time - begin;
|
|
247
|
+
var px_per_ms = width / (hoursPer * 60 * 60 * 1000); // px/ms
|
|
248
|
+
|
|
249
|
+
var left = px_per_ms * ms_current;
|
|
250
|
+
drawText(ctx, {
|
|
251
|
+
fillStyle: '#ffffff',
|
|
252
|
+
font: '12px Arial',
|
|
253
|
+
x: left - 64,
|
|
254
|
+
y: 14,
|
|
255
|
+
text: formartTimestemp(time)
|
|
256
|
+
});
|
|
257
|
+
drawLine(ctx, left, 20, left, height, currentColor, 2); //中间当前点线
|
|
258
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
259
|
+
}, [ctx, height, width, state.currentTime, state.begin, state.hoursPer]);
|
|
260
|
+
/**
|
|
261
|
+
* 绘制提示时间
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
var drawHoverLine = useCallback(function () {
|
|
265
|
+
drawText(ctx, {
|
|
266
|
+
fillStyle: hoverLineColor,
|
|
267
|
+
font: '12px Arial',
|
|
268
|
+
x: state.hover.x - 50,
|
|
269
|
+
y: 12,
|
|
270
|
+
text: formartTimestemp(state.hover.time)
|
|
271
|
+
});
|
|
272
|
+
drawLine(ctx, state.hover.x, 20, state.hover.x, height, hoverLineColor, 1);
|
|
273
|
+
}, [ctx, height, state.hover.time, state.hover.x]);
|
|
274
|
+
/**
|
|
275
|
+
* 获取鼠标posx
|
|
276
|
+
* @param {*} e
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
var get_cursor_x_position = function get_cursor_x_position(e) {
|
|
280
|
+
var posx = 0;
|
|
281
|
+
|
|
282
|
+
var _canvas$getBoundingCl = canvas.getBoundingClientRect(),
|
|
283
|
+
left = _canvas$getBoundingCl.left;
|
|
284
|
+
|
|
285
|
+
if (!e) {
|
|
286
|
+
e = window.event;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (e.pageX || e.pageY) {
|
|
290
|
+
posx = e.pageX - left;
|
|
291
|
+
} else if (e.clientX || e.clientY) {
|
|
292
|
+
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return posx;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* 更新画布大小
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
_useUpdateEffect(function () {
|
|
303
|
+
if (canvas) {
|
|
304
|
+
canvas.width = width;
|
|
305
|
+
canvas.height = height;
|
|
306
|
+
}
|
|
307
|
+
}, [canvas, height, width]);
|
|
308
|
+
|
|
309
|
+
useEffect(function () {
|
|
310
|
+
if (canvas) {
|
|
311
|
+
clearCanvas();
|
|
312
|
+
drawOverlay();
|
|
313
|
+
drawScale();
|
|
314
|
+
drawCurrentLine();
|
|
315
|
+
state.hover.time && drawHoverLine();
|
|
316
|
+
}
|
|
317
|
+
}, [canvas, state.begin, state.currentTime, state.hoursPer, segments, state.hover, clearCanvas, drawOverlay, drawScale, drawCurrentLine, drawHoverLine]);
|
|
318
|
+
|
|
319
|
+
_useUpdateEffect(function () {
|
|
320
|
+
return update({
|
|
321
|
+
begin: begin
|
|
322
|
+
});
|
|
323
|
+
}, [begin]);
|
|
324
|
+
|
|
325
|
+
_useUpdateEffect(function () {
|
|
326
|
+
return update({
|
|
327
|
+
hoursPer: hoursPer
|
|
328
|
+
});
|
|
329
|
+
}, [hoursPer]);
|
|
330
|
+
|
|
331
|
+
_useUpdateEffect(function () {
|
|
332
|
+
return update({
|
|
333
|
+
currentTime: currentTime
|
|
334
|
+
});
|
|
335
|
+
}, [currentTime]);
|
|
336
|
+
|
|
337
|
+
_useEventListener('mousewheel', function (event) {
|
|
338
|
+
event.preventDefault();
|
|
339
|
+
var delta = Math.max(-1, Math.min(1, event.wheelDelta || -event.detail));
|
|
340
|
+
var middle_time = state.begin + state.hoursPer * 3600 * 1000 / 2; //ms 记住当前中间的时间
|
|
341
|
+
|
|
342
|
+
var new_hoursPer = state.hoursPer;
|
|
343
|
+
var index = hours.indexOf(new_hoursPer);
|
|
344
|
+
|
|
345
|
+
if (delta < 0) {
|
|
346
|
+
// 缩小
|
|
347
|
+
if (index === hours.length - 1) {
|
|
348
|
+
new_hoursPer = hours[index];
|
|
349
|
+
} else {
|
|
350
|
+
new_hoursPer = hours[index + 1];
|
|
351
|
+
}
|
|
352
|
+
} else if (delta > 0) {
|
|
353
|
+
// 放大
|
|
354
|
+
if (index === 0) {
|
|
355
|
+
new_hoursPer = hours[0];
|
|
356
|
+
} else {
|
|
357
|
+
new_hoursPer = hours[index - 1];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
var new_begin = middle_time - state.hoursPer * 3600 * 1000 / 2; //start_timestamp = 当前中间的时间 - zoom/2
|
|
362
|
+
|
|
363
|
+
setState(function (old) {
|
|
364
|
+
return Object.assign(Object.assign({}, old), {
|
|
365
|
+
begin: new_begin,
|
|
366
|
+
hoursPer: new_hoursPer
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
_nextTick(function () {
|
|
371
|
+
return onHoursPerChange && onHoursPerChange(new_hoursPer);
|
|
372
|
+
});
|
|
373
|
+
}, {
|
|
374
|
+
target: canvasRef
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
_useEventListener('mouseout', function () {
|
|
378
|
+
return setState(function (old) {
|
|
379
|
+
return Object.assign(Object.assign({}, old), {
|
|
380
|
+
hover: {
|
|
381
|
+
x: 0,
|
|
382
|
+
time: null
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
}, {
|
|
387
|
+
target: canvasRef
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
_useEventListener('mousemove', function (e) {
|
|
391
|
+
if (extRef.current.mousedownTime) {
|
|
392
|
+
setState(function (old) {
|
|
393
|
+
return Object.assign(Object.assign({}, old), {
|
|
394
|
+
hover: old.hover.time ? {
|
|
395
|
+
x: 0,
|
|
396
|
+
time: null
|
|
397
|
+
} : old.hover
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
} else {
|
|
401
|
+
// 触发绘制hover tips
|
|
402
|
+
var pos_x = get_cursor_x_position(e);
|
|
403
|
+
var ms_per_px = state.hoursPer * 3600 * 1000 / width; // ms/px
|
|
404
|
+
|
|
405
|
+
var current_timestamp = state.begin + pos_x * ms_per_px;
|
|
406
|
+
setState(function (old) {
|
|
407
|
+
return Object.assign(Object.assign({}, old), {
|
|
408
|
+
hover: {
|
|
409
|
+
x: pos_x,
|
|
410
|
+
time: current_timestamp
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}, {
|
|
416
|
+
target: canvasRef
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
_useEventListener('mousedown', function (e) {
|
|
420
|
+
extRef.current.mousedownTime = Date.now();
|
|
421
|
+
extRef.current.mousedownX = get_cursor_x_position(e); //记住mousedown的位置
|
|
422
|
+
}, {
|
|
423
|
+
target: canvasRef
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
_useEventListener('mouseup', function (e) {
|
|
427
|
+
if (!extRef.current.mousedownTime) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
var clickDelay = Date.now() - extRef.current.mousedownTime;
|
|
432
|
+
|
|
433
|
+
if (clickDelay < 300 && e.target === canvas) {
|
|
434
|
+
// click 事件
|
|
435
|
+
var pos_x = get_cursor_x_position(e); //鼠标距离 px
|
|
436
|
+
|
|
437
|
+
var ms_per_px = state.hoursPer * 3600 * 1000 / width; // ms/px
|
|
438
|
+
|
|
439
|
+
var new_current = state.begin + pos_x * ms_per_px;
|
|
440
|
+
var segmentItem = segments.find(function (v) {
|
|
441
|
+
return new_current >= v.beginTime && new_current < v.endTime;
|
|
442
|
+
}); // 当前片段没有录像的时候
|
|
443
|
+
|
|
444
|
+
var outTimeline = segmentItem && !segmentItem.url;
|
|
445
|
+
var new_begin = new_current - state.hoursPer * 60 * 60 * 1000 / 2;
|
|
446
|
+
setState(function (old) {
|
|
447
|
+
return Object.assign(Object.assign({}, old), {
|
|
448
|
+
begin: new_begin,
|
|
449
|
+
current: new_current
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
_nextTick(function () {
|
|
454
|
+
return onTimeChange && onTimeChange(new_current, outTimeline);
|
|
455
|
+
});
|
|
456
|
+
} // 清楚拖拽关联信息
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
extRef.current.mousedownTime = null;
|
|
460
|
+
extRef.current.mousedownX = 0;
|
|
461
|
+
}, {
|
|
462
|
+
target: document
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
_useEventListener('mousemove', function (e) {
|
|
466
|
+
if (!extRef.current.mousedownTime) {
|
|
467
|
+
return;
|
|
468
|
+
} // 触发拖动
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
var pos_x = get_cursor_x_position(e);
|
|
472
|
+
var px_per_ms = width / (state.hoursPer * 60 * 60 * 1000); // px/ms
|
|
473
|
+
|
|
474
|
+
var diff_x = pos_x - extRef.current.mousedownX;
|
|
475
|
+
var new_begin = state.begin - Math.round(diff_x / px_per_ms);
|
|
476
|
+
extRef.current.mousedownX = pos_x;
|
|
477
|
+
update({
|
|
478
|
+
begin: new_begin
|
|
479
|
+
});
|
|
480
|
+
}, {
|
|
481
|
+
target: document
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export default useTimeSlider;
|