@cloud-app-dev/vidc 3.0.17 → 3.0.18
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/.umirc.ts +1 -1
- package/es/Map/hook/useMapEvent.js +9 -8
- package/es/Player/api/index.d.ts +3 -1
- package/es/Player/api/index.js +27 -24
- package/es/Player/context.d.ts +21 -0
- package/es/Player/context.js +16 -0
- package/es/Player/contraller_bar/contraller_event.d.ts +1 -4
- package/es/Player/contraller_bar/contraller_event.js +37 -28
- package/es/Player/contraller_bar/index.d.ts +2 -7
- package/es/Player/contraller_bar/index.js +4 -12
- package/es/Player/contraller_bar/left_bar.d.ts +2 -7
- package/es/Player/contraller_bar/left_bar.js +26 -23
- package/es/Player/contraller_bar/right_bar.d.ts +1 -6
- package/es/Player/contraller_bar/right_bar.js +6 -3
- package/es/Player/contraller_bar/useBarStatus.js +17 -24
- package/es/Player/demo.js +5 -1
- package/es/Player/event/errorEvent.js +34 -43
- package/es/Player/event/eventName.d.ts +17 -2
- package/es/Player/event/eventName.js +5 -1
- package/es/Player/event/index.d.ts +2 -0
- package/es/Player/event/index.js +55 -3
- package/es/Player/fps_play.d.ts +10 -0
- package/es/Player/fps_play.js +80 -0
- package/es/Player/frontend_player.js +0 -2
- package/es/Player/frontend_timeline.d.ts +1 -5
- package/es/Player/frontend_timeline.js +8 -4
- package/es/Player/live_heart.js +1 -1
- package/es/Player/message.js +69 -84
- package/es/Player/player.d.ts +10 -15
- package/es/Player/segment_player.js +13 -29
- package/es/Player/segment_timeline.d.ts +1 -6
- package/es/Player/segment_timeline.js +11 -7
- package/es/Player/single_player.js +76 -35
- package/es/Player/style/bar.css +1 -0
- package/es/Player/style/index.css +8 -0
- package/es/Player/timeline.d.ts +1 -1
- package/es/Player/timeline.js +26 -37
- package/es/Player/util.d.ts +1 -1
- package/es/Player/util.js +2 -5
- package/es/ScreenPlayer/Live.js +0 -1
- package/es/ScreenPlayer/PlayerWithExt.d.ts +1 -1
- package/es/ScreenPlayer/PlayerWithExt.js +2 -4
- package/es/ScreenPlayer/Record.js +0 -1
- package/es/ScreenPlayer/demo2.js +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/useRafInterval/index.d.ts +5 -0
- package/es/useRafInterval/index.js +94 -0
- package/package.json +1 -1
- package/es/Player/event/browserTabEvent.d.ts +0 -9
- package/es/Player/event/browserTabEvent.js +0 -57
|
@@ -22,6 +22,7 @@ import { useState, useEffect, useRef } from 'react';
|
|
|
22
22
|
import EventName from './eventName';
|
|
23
23
|
import Flvjs from '@cloud-app-dev/flv.js';
|
|
24
24
|
import Hls from 'hls.js';
|
|
25
|
+
import { useRegisterPlayerEvent, useVideoEvent } from '.';
|
|
25
26
|
|
|
26
27
|
function useErrorEvent(_ref) {
|
|
27
28
|
var event = _ref.event,
|
|
@@ -40,64 +41,54 @@ function useErrorEvent(_ref) {
|
|
|
40
41
|
|
|
41
42
|
var errorInfo = useRef(null);
|
|
42
43
|
var reloadTimer = useRef(null);
|
|
43
|
-
useEffect(function () {
|
|
44
|
-
var errorHandle = function errorHandle() {
|
|
45
|
-
var _console;
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
45
|
+
var errorHandle = function errorHandle() {
|
|
46
|
+
var _console;
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
49
|
+
args[_key] = arguments[_key];
|
|
50
|
+
}
|
|
54
51
|
|
|
55
|
-
|
|
52
|
+
if (args[2] && args[2].msg && args[2].msg.includes('Unsupported audio')) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
(_console = console).error.apply(_console, args);
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
setErrorTime(errorTimer + 1);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
58
|
+
errorInfo.current = args;
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
clearErrorTimer();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
60
|
+
if (!(errorHandleAdapter === null || errorHandleAdapter === void 0 ? void 0 : errorHandleAdapter(args))) {
|
|
61
|
+
setErrorTime(errorTimer + 1);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
71
64
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
var clearErrorTimer = function clearErrorTimer() {
|
|
66
|
+
return setErrorTime(0);
|
|
67
|
+
};
|
|
75
68
|
|
|
69
|
+
var reloadSuccess = function reloadSuccess() {
|
|
70
|
+
if (errorTimer > 0) {
|
|
71
|
+
console.warn('视频重连成功!');
|
|
72
|
+
event.emit(EventName.RELOAD_SUCCESS);
|
|
73
|
+
clearErrorTimer();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
useVideoEvent('error', errorHandle);
|
|
78
|
+
useVideoEvent('canplay', reloadSuccess);
|
|
79
|
+
useRegisterPlayerEvent(EventName.ERROR, errorHandle);
|
|
80
|
+
useRegisterPlayerEvent(EventName.CLEAR_ERROR_TIMER, clearErrorTimer);
|
|
81
|
+
useEffect(function () {
|
|
76
82
|
if (flv) {
|
|
77
83
|
flv.on(Flvjs.Events.ERROR, errorHandle);
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
if (hls) {
|
|
81
87
|
hls.on(Hls.Events.ERROR, errorHandle);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (event) {
|
|
85
|
-
event.on(EventName.ERROR, errorHandle);
|
|
86
|
-
event.on(EventName.CLEAR_ERROR_TIMER, clearErrorTimer);
|
|
87
|
-
event.addEventListener('error', errorHandle); //获取video状态清除错误状态
|
|
88
|
-
|
|
89
|
-
event.addEventListener('canplay', reloadSuccess);
|
|
90
|
-
}
|
|
88
|
+
} //事件销毁由flv、hls销毁时控制
|
|
89
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
// flv, hls事件不用主动销毁,库内部自己处理
|
|
94
|
-
if (event) {
|
|
95
|
-
event.off(EventName.ERROR, errorHandle);
|
|
96
|
-
event.removeEventListener('error', errorHandle);
|
|
97
|
-
event.removeEventListener('canplay', reloadSuccess);
|
|
98
|
-
}
|
|
99
|
-
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
-
}, [event, flv, hls, errorTimer]);
|
|
91
|
+
}, [flv, hls]);
|
|
101
92
|
useEffect(function () {
|
|
102
93
|
if (errorTimer === 0) {
|
|
103
94
|
return undefined;
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const Events: {
|
|
2
|
+
RELOAD: string;
|
|
3
|
+
RELOAD_FAIL: string;
|
|
4
|
+
RELOAD_SUCCESS: string;
|
|
5
|
+
ERROR: string;
|
|
6
|
+
ERROR_RELOAD: string;
|
|
7
|
+
HISTORY_PLAY_END: string;
|
|
8
|
+
PLAY_ENDED: string;
|
|
9
|
+
SEEK: string;
|
|
10
|
+
TRANSFORM: string;
|
|
11
|
+
CHANGE_PLAY_INDEX: string;
|
|
12
|
+
HIDE_CONTRALLER: string;
|
|
13
|
+
SHOW_CONTRALLER: string;
|
|
14
|
+
CLEAR_ERROR_TIMER: string;
|
|
15
|
+
CANVAS_PAUSE: string;
|
|
16
|
+
CANVAS_PLAY: string;
|
|
17
|
+
};
|
|
3
18
|
export default Events;
|
|
@@ -5,11 +5,15 @@ var Events = {
|
|
|
5
5
|
ERROR: 'error',
|
|
6
6
|
ERROR_RELOAD: 'errorRload',
|
|
7
7
|
HISTORY_PLAY_END: 'historyPlayEnd',
|
|
8
|
+
PLAY_ENDED: 'play_ended',
|
|
8
9
|
SEEK: 'seek',
|
|
9
10
|
TRANSFORM: 'transform',
|
|
10
11
|
CHANGE_PLAY_INDEX: 'changePlayIndex',
|
|
11
12
|
HIDE_CONTRALLER: 'hideContraller',
|
|
12
13
|
SHOW_CONTRALLER: 'showContraller',
|
|
13
|
-
CLEAR_ERROR_TIMER: 'clearErrorTimer'
|
|
14
|
+
CLEAR_ERROR_TIMER: 'clearErrorTimer',
|
|
15
|
+
CANVAS_PAUSE: 'canvasPause',
|
|
16
|
+
CANVAS_PLAY: 'canvasPlay' //逐帧播放
|
|
17
|
+
|
|
14
18
|
};
|
|
15
19
|
export default Events;
|
|
@@ -17,6 +17,8 @@ declare class VideoEventInstance {
|
|
|
17
17
|
}
|
|
18
18
|
declare type PlayEvent = VideoEventInstance;
|
|
19
19
|
export declare function usePlayerEvent(video: HTMLVideoElement): PlayEvent;
|
|
20
|
+
export declare function useVideoEvent(eventName: string, handle: (event: any) => void, context?: VideoEventInstance): void;
|
|
21
|
+
export declare function useRegisterPlayerEvent(eventName: string, handle: (event: any) => void, context?: VideoEventInstance): void;
|
|
20
22
|
export declare function useVideoEvents(event: VideoEventInstance, events: CustomEvent[]): void;
|
|
21
23
|
export declare function useRegisterPlayerEvents(event: VideoEventInstance, events: CustomEvent[]): void;
|
|
22
24
|
export default VideoEventInstance;
|
package/es/Player/event/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _useLatest from "ahooks/es/useLatest";
|
|
1
2
|
import _nextTick from "@cloud-app-dev/utils/es/nextTick";
|
|
2
3
|
|
|
3
4
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
@@ -18,7 +19,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
18
19
|
|
|
19
20
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
20
21
|
|
|
21
|
-
import { useEffect, useState } from 'react';
|
|
22
|
+
import { useContext, useEffect, useMemo, useState } from 'react';
|
|
23
|
+
import { Context } from '../context';
|
|
22
24
|
|
|
23
25
|
var VideoEventInstance = /*#__PURE__*/function () {
|
|
24
26
|
function VideoEventInstance(video) {
|
|
@@ -128,6 +130,56 @@ export function usePlayerEvent(video) {
|
|
|
128
130
|
}, [video]);
|
|
129
131
|
return event;
|
|
130
132
|
}
|
|
133
|
+
export function useVideoEvent(eventName, handle, context) {
|
|
134
|
+
var ctx = useContext(Context);
|
|
135
|
+
var event = useMemo(function () {
|
|
136
|
+
var _a;
|
|
137
|
+
|
|
138
|
+
return (_a = ctx === null || ctx === void 0 ? void 0 : ctx.event) !== null && _a !== void 0 ? _a : context;
|
|
139
|
+
}, [context, ctx === null || ctx === void 0 ? void 0 : ctx.event]);
|
|
140
|
+
|
|
141
|
+
var handlerRef = _useLatest(handle);
|
|
142
|
+
|
|
143
|
+
useEffect(function () {
|
|
144
|
+
if (!event) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
var eventListener = function eventListener(event) {
|
|
149
|
+
return handlerRef.current(event);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
event.addEventListener(eventName, eventListener);
|
|
153
|
+
return function () {
|
|
154
|
+
event.removeEventListener(eventName, eventListener);
|
|
155
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
156
|
+
}, [event, eventName]);
|
|
157
|
+
}
|
|
158
|
+
export function useRegisterPlayerEvent(eventName, handle, context) {
|
|
159
|
+
var ctx = useContext(Context);
|
|
160
|
+
var event = useMemo(function () {
|
|
161
|
+
var _a;
|
|
162
|
+
|
|
163
|
+
return (_a = ctx === null || ctx === void 0 ? void 0 : ctx.event) !== null && _a !== void 0 ? _a : context;
|
|
164
|
+
}, [context, ctx === null || ctx === void 0 ? void 0 : ctx.event]);
|
|
165
|
+
|
|
166
|
+
var handlerRef = _useLatest(handle);
|
|
167
|
+
|
|
168
|
+
useEffect(function () {
|
|
169
|
+
if (!event) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var eventListener = function eventListener(event) {
|
|
174
|
+
return handlerRef.current(event);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
event.on(eventName, eventListener);
|
|
178
|
+
return function () {
|
|
179
|
+
event.off(eventName, eventListener);
|
|
180
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
181
|
+
}, [event, eventName]);
|
|
182
|
+
}
|
|
131
183
|
export function useVideoEvents(event, events) {
|
|
132
184
|
useEffect(function () {
|
|
133
185
|
if (!event || !events) {
|
|
@@ -149,7 +201,7 @@ export function useVideoEvents(event, events) {
|
|
|
149
201
|
|
|
150
202
|
event.removeEventListener(eventName, handle);
|
|
151
203
|
});
|
|
152
|
-
};
|
|
204
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
153
205
|
}, [event]);
|
|
154
206
|
}
|
|
155
207
|
export function useRegisterPlayerEvents(event, events) {
|
|
@@ -173,7 +225,7 @@ export function useRegisterPlayerEvents(event, events) {
|
|
|
173
225
|
|
|
174
226
|
event.off(eventName, handle);
|
|
175
227
|
});
|
|
176
|
-
};
|
|
228
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
229
|
}, [event]);
|
|
178
230
|
}
|
|
179
231
|
export default VideoEventInstance;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type Api from './api';
|
|
3
|
+
import type VideoEventInstance from './event';
|
|
4
|
+
interface IFPSPlay {
|
|
5
|
+
api: Api;
|
|
6
|
+
event: VideoEventInstance;
|
|
7
|
+
fpsDelay?: number;
|
|
8
|
+
}
|
|
9
|
+
declare function FPSPlay({ api, event, fpsDelay }: IFPSPlay): JSX.Element;
|
|
10
|
+
export default FPSPlay;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
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."); }
|
|
4
|
+
|
|
5
|
+
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); }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
14
|
+
import Events from './event/eventName';
|
|
15
|
+
import useRafInterval from '../useRafInterval';
|
|
16
|
+
import { useRegisterPlayerEvent } from './event';
|
|
17
|
+
var oneFps = 1 / 30;
|
|
18
|
+
|
|
19
|
+
function FPSPlay(_ref) {
|
|
20
|
+
var api = _ref.api,
|
|
21
|
+
event = _ref.event,
|
|
22
|
+
fpsDelay = _ref.fpsDelay;
|
|
23
|
+
|
|
24
|
+
var _useState = useState(Date.now()),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
forceKey = _useState2[0],
|
|
27
|
+
update = _useState2[1];
|
|
28
|
+
|
|
29
|
+
var ref = useRef(null);
|
|
30
|
+
var timerRef = useRef(null);
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
var fpsCapture = function fpsCapture() {
|
|
33
|
+
if (!ref.current || !event.video) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var video = event.video;
|
|
38
|
+
var fpsTime = api.getCurrentTime() + oneFps;
|
|
39
|
+
video.currentTime = fpsTime;
|
|
40
|
+
|
|
41
|
+
if (video.currentTime >= api.getDuration()) {
|
|
42
|
+
clearInterval(timerRef.current);
|
|
43
|
+
video.currentTime = 0;
|
|
44
|
+
event.emit(Events.PLAY_ENDED);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var canvas = ref.current;
|
|
48
|
+
var ctx = canvas.getContext('2d');
|
|
49
|
+
|
|
50
|
+
var _video$getBoundingCli = video.getBoundingClientRect(),
|
|
51
|
+
width = _video$getBoundingCli.width,
|
|
52
|
+
height = _video$getBoundingCli.height;
|
|
53
|
+
|
|
54
|
+
canvas.width = width;
|
|
55
|
+
canvas.height = height;
|
|
56
|
+
ctx.drawImage(video, 0, 0, width, height);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
fpsCapture();
|
|
60
|
+
timerRef.current = setInterval(fpsCapture, fpsDelay);
|
|
61
|
+
return function () {
|
|
62
|
+
clearInterval(timerRef.current);
|
|
63
|
+
};
|
|
64
|
+
}, [api, event, fpsDelay, forceKey]);
|
|
65
|
+
useRegisterPlayerEvent(Events.CANVAS_PAUSE, function () {
|
|
66
|
+
clearInterval(timerRef.current);
|
|
67
|
+
});
|
|
68
|
+
useRegisterPlayerEvent(Events.CANVAS_PLAY, function () {
|
|
69
|
+
update(Date.now());
|
|
70
|
+
});
|
|
71
|
+
useRafInterval(function () {
|
|
72
|
+
return !api.paused ? api.pause() : null;
|
|
73
|
+
}, 10);
|
|
74
|
+
return /*#__PURE__*/React.createElement("canvas", {
|
|
75
|
+
className: "fps-play-canvas",
|
|
76
|
+
ref: ref
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default FPSPlay;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type Api from './api';
|
|
3
|
-
import type VideoEventInstance from './event';
|
|
4
2
|
import './style/timeline.less';
|
|
5
3
|
interface ITimeLineProps {
|
|
6
|
-
api: Api;
|
|
7
|
-
event: VideoEventInstance;
|
|
8
4
|
duration: number;
|
|
9
5
|
begin: number;
|
|
10
6
|
end: number;
|
|
11
7
|
onSeek?: (time: number) => void;
|
|
12
8
|
url?: string;
|
|
13
9
|
}
|
|
14
|
-
declare function FrontendTimeLine({
|
|
10
|
+
declare function FrontendTimeLine({ duration, begin, end, onSeek, url }: ITimeLineProps): JSX.Element;
|
|
15
11
|
export default FrontendTimeLine;
|
|
@@ -12,21 +12,25 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
12
12
|
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
14
|
|
|
15
|
-
import React, { useCallback, useEffect, useMemo, useState, startTransition, useRef } from 'react';
|
|
15
|
+
import React, { useCallback, useEffect, useMemo, useState, startTransition, useRef, useContext } from 'react';
|
|
16
16
|
import useBarStatus from './contraller_bar/useBarStatus';
|
|
17
17
|
import { useTimes } from './timeline';
|
|
18
18
|
import { FMT } from './util';
|
|
19
19
|
import moment from 'moment';
|
|
20
|
+
import { Context } from './context';
|
|
20
21
|
import "./style/timeline.css";
|
|
21
22
|
|
|
22
23
|
function FrontendTimeLine(_ref) {
|
|
23
|
-
var
|
|
24
|
-
event = _ref.event,
|
|
25
|
-
duration = _ref.duration,
|
|
24
|
+
var duration = _ref.duration,
|
|
26
25
|
begin = _ref.begin,
|
|
27
26
|
end = _ref.end,
|
|
28
27
|
onSeek = _ref.onSeek,
|
|
29
28
|
url = _ref.url;
|
|
29
|
+
|
|
30
|
+
var _useContext = useContext(Context),
|
|
31
|
+
api = _useContext.api,
|
|
32
|
+
event = _useContext.event;
|
|
33
|
+
|
|
30
34
|
var lastSeekCTimeRef = useRef(0); // time 是记录seek时跳了多少
|
|
31
35
|
|
|
32
36
|
var _useState = useState({
|
package/es/Player/live_heart.js
CHANGED
package/es/Player/message.js
CHANGED
|
@@ -10,8 +10,9 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
10
10
|
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
12
|
|
|
13
|
-
import React, {
|
|
13
|
+
import React, { useState, useMemo, useRef } from 'react';
|
|
14
14
|
import IconFont from './iconfont';
|
|
15
|
+
import { useRegisterPlayerEvent, useVideoEvent } from './event';
|
|
15
16
|
import EventName from './event/eventName';
|
|
16
17
|
import "./style/message.css";
|
|
17
18
|
|
|
@@ -42,99 +43,83 @@ function VideoMessage(_ref) {
|
|
|
42
43
|
|
|
43
44
|
return '';
|
|
44
45
|
}, [state.errorTimer, state.status]);
|
|
45
|
-
useEffect(function () {
|
|
46
|
-
var openLoading = function openLoading() {
|
|
47
|
-
clearTimeout(timeRef.current);
|
|
48
|
-
timeRef.current = setTimeout(function () {
|
|
49
|
-
return setState(function (old) {
|
|
50
|
-
return Object.assign(Object.assign({}, old), {
|
|
51
|
-
loading: true
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}, 200);
|
|
55
|
-
};
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
var openLoading = function openLoading() {
|
|
48
|
+
clearTimeout(timeRef.current);
|
|
49
|
+
timeRef.current = setTimeout(function () {
|
|
50
|
+
return setState(function (old) {
|
|
60
51
|
return Object.assign(Object.assign({}, old), {
|
|
61
|
-
loading:
|
|
52
|
+
loading: true
|
|
62
53
|
});
|
|
63
54
|
});
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
loading: true
|
|
73
|
-
};
|
|
55
|
+
}, 200);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var closeLoading = function closeLoading() {
|
|
59
|
+
clearTimeout(timeRef.current);
|
|
60
|
+
setState(function (old) {
|
|
61
|
+
return Object.assign(Object.assign({}, old), {
|
|
62
|
+
loading: false
|
|
74
63
|
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
var errorReload = function errorReload(timer) {
|
|
68
|
+
clearTimeout(timeRef.current);
|
|
69
|
+
setState(function () {
|
|
70
|
+
return {
|
|
71
|
+
status: 'reload',
|
|
72
|
+
errorTimer: timer,
|
|
73
|
+
loading: true
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var reloadFail = function reloadFail() {
|
|
79
|
+
return setState(function (old) {
|
|
80
|
+
return Object.assign(Object.assign({}, old), {
|
|
81
|
+
status: 'fail'
|
|
82
82
|
});
|
|
83
|
-
};
|
|
83
|
+
});
|
|
84
|
+
};
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
86
|
+
var reloadSuccess = function reloadSuccess() {
|
|
87
|
+
return setState(function (old) {
|
|
88
|
+
return Object.assign(Object.assign({}, old), {
|
|
89
|
+
status: null
|
|
90
90
|
});
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
var reload = function reload() {
|
|
95
|
+
return setState(function (old) {
|
|
96
|
+
return Object.assign(Object.assign({}, old), {
|
|
97
|
+
status: 'reload',
|
|
98
|
+
loading: true
|
|
99
99
|
});
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
var playEnd = function playEnd() {
|
|
104
|
+
clearTimeout(timeRef.current);
|
|
105
|
+
setState(function (old) {
|
|
106
|
+
return Object.assign(Object.assign({}, old), {
|
|
107
|
+
status: null,
|
|
108
|
+
loading: false
|
|
109
109
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
event.on(EventName.CLEAR_ERROR_TIMER, reloadSuccess);
|
|
124
|
-
return function () {
|
|
125
|
-
event.removeEventListener('loadstart', openLoading); // event.removeEventListener('waiting', openLoading);
|
|
126
|
-
// event.removeEventListener('seeking', openLoading)
|
|
127
|
-
|
|
128
|
-
event.removeEventListener('loadeddata', closeLoading);
|
|
129
|
-
event.removeEventListener('canplay', closeLoading);
|
|
130
|
-
event.off(EventName.ERROR_RELOAD, errorReload);
|
|
131
|
-
event.off(EventName.RELOAD_FAIL, reloadFail);
|
|
132
|
-
event.off(EventName.RELOAD_SUCCESS, reloadSuccess);
|
|
133
|
-
event.off(EventName.RELOAD, reload);
|
|
134
|
-
event.off(EventName.HISTORY_PLAY_END, playEnd);
|
|
135
|
-
event.off(EventName.CLEAR_ERROR_TIMER, reloadSuccess);
|
|
136
|
-
};
|
|
137
|
-
}, [api, event]);
|
|
110
|
+
});
|
|
111
|
+
api.pause();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
useVideoEvent('loadstart', openLoading);
|
|
115
|
+
useVideoEvent('loadeddata', closeLoading);
|
|
116
|
+
useVideoEvent('canplay', closeLoading);
|
|
117
|
+
useRegisterPlayerEvent(EventName.ERROR_RELOAD, errorReload);
|
|
118
|
+
useRegisterPlayerEvent(EventName.RELOAD_FAIL, reloadFail);
|
|
119
|
+
useRegisterPlayerEvent(EventName.RELOAD_SUCCESS, reloadSuccess);
|
|
120
|
+
useRegisterPlayerEvent(EventName.RELOAD, reload);
|
|
121
|
+
useRegisterPlayerEvent(EventName.HISTORY_PLAY_END, playEnd);
|
|
122
|
+
useRegisterPlayerEvent(EventName.CLEAR_ERROR_TIMER, reloadSuccess);
|
|
138
123
|
var loading = state.loading,
|
|
139
124
|
status = state.status;
|
|
140
125
|
return /*#__PURE__*/React.createElement("div", {
|
package/es/Player/player.d.ts
CHANGED
|
@@ -132,6 +132,16 @@ export interface ISinglePlayerProps {
|
|
|
132
132
|
* 自定义播放器的事件
|
|
133
133
|
*/
|
|
134
134
|
playerEvents?: CustomEvent[];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 开启单帧播放
|
|
138
|
+
*/
|
|
139
|
+
oneFpsPlay?: boolean;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 获取视频针的频次 (ms)
|
|
143
|
+
*/
|
|
144
|
+
fpsDelay?: number;
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
export interface IFrontendPlayerProps extends Omit<ISinglePlayerProps, 'isLive' | 'reload'> {
|
|
@@ -173,21 +183,6 @@ export const SinglePlayer: React.FunctionComponent<ISinglePlayerProps>;
|
|
|
173
183
|
export const FrontendPlayer: React.FunctionComponent<IFrontendPlayerProps>;
|
|
174
184
|
export const SegmentPlayer: React.FunctionComponent<ISegmentPlayerProps>;
|
|
175
185
|
|
|
176
|
-
export interface EventName {
|
|
177
|
-
RELOAD: 'reload'; //手动视频重载
|
|
178
|
-
RELOAD_FAIL: 'reloadFail'; // 视频出错,重连失败
|
|
179
|
-
RELOAD_SUCCESS: 'reloadSuccess'; //视频出错,重连成功
|
|
180
|
-
ERROR: 'error'; //视频出错
|
|
181
|
-
ERROR_RELOAD: 'errorRload'; //视频出错,自动重连
|
|
182
|
-
HISTORY_PLAY_END: 'historyPlayEnd'; //历史视频列表播放结束
|
|
183
|
-
SEEK: 'seek'; //跳跃播放时间
|
|
184
|
-
TRANSFORM: 'transform'; //视频容器缩放
|
|
185
|
-
CHANGE_PLAY_INDEX: 'changePlayIndex'; //历史视频列表播放索引改变
|
|
186
|
-
HIDE_CONTRALLER: 'hideContraller';
|
|
187
|
-
SHOW_CONTRALLER: 'showContraller';
|
|
188
|
-
CLEAR_ERROR_TIMER: 'clearErrorTimer';
|
|
189
|
-
}
|
|
190
|
-
|
|
191
186
|
export type EventInfo = {
|
|
192
187
|
type: string;
|
|
193
188
|
listener: ((...args: any) => void)[];
|