@cloud-app-dev/vidc 3.1.22 → 3.2.1

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 CHANGED
@@ -35,9 +35,6 @@ export default defineConfig({
35
35
  '/api': {
36
36
  target: 'https://jxsr-eye.antelopecloud.cn/',
37
37
  changeOrigin: true,
38
- onProxyReq(proxyReq: any) {
39
- proxyReq.setHeader('authorization', token);
40
- },
41
38
  },
42
39
  },
43
40
  mfsu:
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { ISegmentType } from 'src/Player/player';
2
3
  import './index.less';
3
4
  export declare type PlayModeType = 1 | 2;
4
5
  export interface IPluginProps {
@@ -18,6 +19,7 @@ export interface IPluginProps {
18
19
  * @default ''
19
20
  */
20
21
  pluginParams?: string;
22
+ segments?: ISegmentType[];
21
23
  /**
22
24
  * 正在获取视频数据
23
25
  */
@@ -42,5 +44,5 @@ export declare function getLocalPlayPath(url: string, params?: string): string;
42
44
  export declare function usePlugin(mode: PlayModeType, key: any): {
43
45
  needInstall: boolean;
44
46
  };
45
- export declare function ExtModel({ url, children, mode, pluginDownloadUrl, pluginParams, loading }: IPluginProps): JSX.Element;
47
+ export declare function ExtModel({ url, children, mode, pluginDownloadUrl, pluginParams, loading, segments }: IPluginProps): JSX.Element;
46
48
  export { ExtModel as default };
@@ -122,7 +122,8 @@ export function ExtModel(_ref2) {
122
122
  mode = _ref2.mode,
123
123
  pluginDownloadUrl = _ref2.pluginDownloadUrl,
124
124
  pluginParams = _ref2.pluginParams,
125
- loading = _ref2.loading;
125
+ loading = _ref2.loading,
126
+ segments = _ref2.segments;
126
127
  var _useState3 = useState({
127
128
  forceKey: Date.now()
128
129
  }),
@@ -130,14 +131,24 @@ export function ExtModel(_ref2) {
130
131
  state = _useState4[0],
131
132
  setState = _useState4[1];
132
133
  var hasUrl = useMemo(function () {
133
- return !!url;
134
- }, [url]);
134
+ return !!url || Array.isArray(segments) && segments.findIndex(function (v) {
135
+ return v.url;
136
+ }) > -1;
137
+ }, [segments, url]);
135
138
  var _usePlugin = usePlugin(mode, state.forceKey),
136
139
  needInstall = _usePlugin.needInstall;
137
140
  // eslint-disable-next-line react-hooks/exhaustive-deps
138
141
  var playUrl = useMemo(function () {
139
142
  return mode === 2 && url ? getLocalPlayPath(url, pluginParams) : url;
140
143
  }, [url, mode]);
144
+ // eslint-disable-next-line react-hooks/exhaustive-deps
145
+ var playSegments = useMemo(function () {
146
+ return mode === 2 && url ? segments.map(function (v) {
147
+ return Object.assign(Object.assign({}, v), {
148
+ url: getLocalPlayPath(v.url, pluginParams)
149
+ });
150
+ }) : url;
151
+ }, [segments, mode]);
141
152
  if (needInstall) {
142
153
  return /*#__PURE__*/React.createElement(NeedInstallPlugin, {
143
154
  pluginDownloadUrl: pluginDownloadUrl,
@@ -158,8 +169,9 @@ export function ExtModel(_ref2) {
158
169
  }
159
170
  return /*#__PURE__*/React.createElement("div", {
160
171
  className: "lm-player-ext-layout"
161
- }, /*#__PURE__*/React.cloneElement(children, {
162
- url: playUrl
163
- }));
172
+ }, /*#__PURE__*/React.cloneElement(children, mode === 2 ? {
173
+ url: playUrl,
174
+ segments: playSegments
175
+ } : {}));
164
176
  }
165
177
  export { ExtModel as default };
@@ -82,7 +82,8 @@ export function SegmentPlayerWithExt(_a) {
82
82
  onDoubleClick: toggleFullscreen
83
83
  }, /*#__PURE__*/React.createElement(ExtModel, {
84
84
  mode: 1,
85
- loading: httpLoading
85
+ loading: httpLoading,
86
+ segments: segments
86
87
  }, /*#__PURE__*/React.createElement(SegmentPlayer, Object.assign({}, props, {
87
88
  segments: segments,
88
89
  type: "hls",
@@ -16,6 +16,12 @@ function RatePick(_ref) {
16
16
  onChange: onChange,
17
17
  placement: "topLeft"
18
18
  }, /*#__PURE__*/React.createElement(_Select.Option, {
19
+ value: 8
20
+ }, "x8"), /*#__PURE__*/React.createElement(_Select.Option, {
21
+ value: 6
22
+ }, "x6"), /*#__PURE__*/React.createElement(_Select.Option, {
23
+ value: 4
24
+ }, "x4"), /*#__PURE__*/React.createElement(_Select.Option, {
19
25
  value: 2
20
26
  }, "x2"), /*#__PURE__*/React.createElement(_Select.Option, {
21
27
  value: 1.5
@@ -6,5 +6,5 @@ import './index.less';
6
6
  * @param param0
7
7
  * @returns
8
8
  */
9
- declare function RecordPlayer({ list, children, queryRecord, onIndexChange, onClose, onCloseAll, download, snapshot, defaultScreen, screenChange, defaultSelectIndex, oneWinExtTools, allWinExtTools, fpsDelay, fps, queryRecordErrorHandle, getLocalRecordUrl, pluginDownloadUrl, ...options }: IRecordPlayerProps): JSX.Element;
9
+ declare function RecordPlayer({ list, children, queryRecord, onIndexChange, onClose, onCloseAll, download, snapshot, defaultScreen, screenChange, defaultSelectIndex, oneWinExtTools, allWinExtTools, fpsDelay, fps, queryRecordErrorHandle, getLocalRecordUrl, pluginDownloadUrl, onTimeLineChange, seekLoading, ...options }: IRecordPlayerProps): JSX.Element;
10
10
  export default RecordPlayer;
@@ -1,14 +1,7 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
  import _useUpdateEffect from "ahooks/es/useUpdateEffect";
3
- import "antd/lib/message/style";
4
- import _message from "antd/lib/message";
5
- import _usePrevious from "ahooks/es/usePrevious";
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
4
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
7
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
12
5
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
6
  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."); }
14
7
  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); }
@@ -17,11 +10,10 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
17
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
11
  import { __awaiter, __rest } from "tslib";
19
12
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
20
- import { ScreenType, mergeFill, differenceWithIndexs, FILTER_KEY } from './utils';
13
+ import { ScreenType, mergeFill, sleep } from './utils';
21
14
  import { SegmentPlayerWithExt, FrontendPlayerWithExt } from './PlayerWithExt';
22
15
  import RecordTools from './RecordTools';
23
16
  import SegmentTimeLine from './SegmentTimeLine';
24
- import useRecordList from './useRecordList';
25
17
  import useVideoFit from './useVideoFit';
26
18
  import DisableMark from '../DisableMark';
27
19
  import { cloneDeep } from 'lodash-es';
@@ -31,11 +23,8 @@ var defaultState = {
31
23
  selectIndex: 0,
32
24
  modes: {},
33
25
  currentTimes: {},
34
- loading: false,
35
- seekTo: 0,
36
- mergeSegments: [],
37
- timeMode: 24,
38
- winLoadingStatus: {}
26
+ seekTo: {},
27
+ timeMode: 24
39
28
  };
40
29
  /**
41
30
  * @desc 录像设计的时间全部需要到毫秒
@@ -62,7 +51,9 @@ function RecordPlayer(_a) {
62
51
  queryRecordErrorHandle = _a.queryRecordErrorHandle,
63
52
  getLocalRecordUrl = _a.getLocalRecordUrl,
64
53
  pluginDownloadUrl = _a.pluginDownloadUrl,
65
- options = __rest(_a, ["list", "children", "queryRecord", "onIndexChange", "onClose", "onCloseAll", "download", "snapshot", "defaultScreen", "screenChange", "defaultSelectIndex", "oneWinExtTools", "allWinExtTools", "fpsDelay", "fps", "queryRecordErrorHandle", "getLocalRecordUrl", "pluginDownloadUrl"]);
54
+ onTimeLineChange = _a.onTimeLineChange,
55
+ seekLoading = _a.seekLoading,
56
+ options = __rest(_a, ["list", "children", "queryRecord", "onIndexChange", "onClose", "onCloseAll", "download", "snapshot", "defaultScreen", "screenChange", "defaultSelectIndex", "oneWinExtTools", "allWinExtTools", "fpsDelay", "fps", "queryRecordErrorHandle", "getLocalRecordUrl", "pluginDownloadUrl", "onTimeLineChange", "seekLoading"]);
66
57
  var _useState = useState(Object.assign(Object.assign({}, cloneDeep(defaultState)), {
67
58
  screenNum: defaultScreen !== null && defaultScreen !== void 0 ? defaultScreen : defaultState.screenNum
68
59
  })),
@@ -89,122 +80,99 @@ function RecordPlayer(_a) {
89
80
  var _useVideoFit = useVideoFit(domRef, []),
90
81
  fit = _useVideoFit.fit,
91
82
  toggleFit = _useVideoFit.toggleFit;
92
- // key变化
93
- var listKey = useMemo(function () {
94
- return screenList.map(function (v) {
95
- var _a, _b;
96
- return v ? "".concat((_a = v.date) !== null && _a !== void 0 ? _a : 0, "|").concat((_b = v.cid) !== null && _b !== void 0 ? _b : 1) : FILTER_KEY;
97
- }).join('-');
98
- }, [screenList]);
99
- var prevListKey = _usePrevious(listKey);
100
- // 所有窗口播放信息
101
- var recordList = useRecordList(state.mergeSegments, queryRecord, {
102
- errorCallback: queryRecordErrorHandle !== null && queryRecordErrorHandle !== void 0 ? queryRecordErrorHandle : function () {},
103
- loaddingCallback: function loaddingCallback(idx, loadding) {
104
- return setState(function (old) {
105
- var item = old.mergeSegments[idx];
106
- var status = Object.assign({}, old.winLoadingStatus);
107
- status["".concat(item.cid, "-").concat(item.date)] = loadding;
108
- return Object.assign(Object.assign({}, old), {
109
- winLoadingStatus: status
110
- });
111
- });
112
- }
113
- });
114
83
  // 缓存所有player对象
115
84
  var playerRef = useRef({});
116
85
  // 获取选中player对象
117
86
  var getPlayerItem = function getPlayerItem() {
118
87
  var _a, _b;
119
- var item = list[state.selectIndex];
120
- return (_b = (_a = playerRef.current) === null || _a === void 0 ? void 0 : _a[item === null || item === void 0 ? void 0 : item.cid]) === null || _b === void 0 ? void 0 : _b.current;
88
+ var item = screenList[state.selectIndex];
89
+ return item ? (_b = (_a = playerRef.current) === null || _a === void 0 ? void 0 : _a["".concat(item.cid, "-").concat(item.date)]) === null || _b === void 0 ? void 0 : _b.current : null;
121
90
  };
122
91
  // 当前窗口信息
123
92
  var segmentItem = useMemo(function () {
124
- return recordList[state.selectIndex] || {};
125
- }, [state.selectIndex, recordList]);
93
+ return screenList[state.selectIndex] || {};
94
+ }, [state.selectIndex, screenList]);
126
95
  var timeBegin = useMemo(function () {
127
96
  return segmentItem.date;
128
97
  }, [segmentItem.date]);
129
98
  var currentTime = useMemo(function () {
130
- var item = state.mergeSegments[state.selectIndex];
99
+ var item = screenList[state.selectIndex];
131
100
  if (!item) {
132
101
  return undefined;
133
102
  }
134
103
  return state.currentTimes["".concat(item.cid, "-").concat(item.date)];
135
- }, [state.currentTimes, state.mergeSegments, state.selectIndex]);
136
- /**
137
- * @desc 用户缓存接收list的变化。
138
- */
139
- useEffect(function () {
140
- if (!prevListKey || !listKey) {
141
- return;
142
- }
143
- var diffIndexs = differenceWithIndexs(listKey.split('-'), prevListKey.split('-'));
144
- if (diffIndexs.length === 0) {
145
- return;
146
- }
147
- setState(function (old) {
148
- var mergeList = old.mergeSegments;
149
- var times = old.currentTimes;
150
- // 批量更新调整
151
- var _iterator = _createForOfIteratorHelper(diffIndexs),
152
- _step;
153
- try {
154
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
155
- var dif = _step.value;
156
- var i = dif.idx;
157
- var item = list[i];
158
- if (!item) {
159
- // 可能是外部的关闭动作关闭
160
- mergeList[i] = undefined;
161
- } else {
162
- if (!mergeList[i]) {
163
- mergeList[i] = cloneDeep(item);
164
- }
165
- mergeList[i].date = item.date;
166
- mergeList[i].segments = mergeList[i].cid !== item.cid ? [] : mergeList[i].segments;
167
- mergeList[i].cid = item.cid;
168
- mergeList[i].recordType = item.recordType;
169
- // 更新变化的currentTime
170
- times["".concat(item.cid, "-").concat(item.date)] = list[i].date;
171
- }
172
- }
173
- } catch (err) {
174
- _iterator.e(err);
175
- } finally {
176
- _iterator.f();
177
- }
178
- return Object.assign(Object.assign({}, old), {
179
- mergeSegments: _toConsumableArray(mergeList),
180
- currentTimes: Object.assign({}, times)
181
- });
182
- });
183
- }, [list, listKey, prevListKey]);
104
+ }, [state.currentTimes, screenList, state.selectIndex]);
184
105
  /**
185
106
  * @desc seek hook
186
107
  * 处理seek相关的包括索引和video current time
187
108
  */
188
109
  useEffect(function () {
189
- if (state.seekTo === 0) {
110
+ var _a, _b;
111
+ // 寻找需要seek的item
112
+ var key = Object.keys(state.seekTo).find(function (k) {
113
+ return state.seekTo[k] !== 0;
114
+ });
115
+ if (!key) {
190
116
  return;
191
117
  }
192
- var item = recordList[state.selectIndex];
193
- var index = item.segments.findIndex(function (v) {
194
- return state.seekTo >= v.beginTime && state.seekTo < v.endTime;
118
+ var seekTime = state.seekTo[key];
119
+ var item = list.find(function (v) {
120
+ return !!v && "".concat(v.cid, "-").concat(v.date) === key;
195
121
  });
122
+ var index = (_b = (_a = item === null || item === void 0 ? void 0 : item.segments) === null || _a === void 0 ? void 0 : _a.findIndex(function (v) {
123
+ return seekTime >= v.beginTime && seekTime < v.endTime;
124
+ })) !== null && _b !== void 0 ? _b : -1;
196
125
  if (index === -1) {
197
126
  return;
198
127
  }
199
- setState(function (old) {
200
- return Object.assign(Object.assign({}, old), {
201
- seekTo: 0
128
+ // list变化导致ref被销毁,这里设计了一个处理机制,1s内重试5次,尝试获取新的ref,正常情况下都会获取到播放器初始化很快,还未获取到那么丢弃
129
+ var timer = 0;
130
+ function getPlay(mapkey) {
131
+ var _a;
132
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
133
+ var playRef;
134
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
135
+ while (1) {
136
+ switch (_context.prev = _context.next) {
137
+ case 0:
138
+ playRef = (_a = playerRef.current) === null || _a === void 0 ? void 0 : _a[mapkey];
139
+ if (!(playRef && playRef.current && playRef.current.api)) {
140
+ _context.next = 5;
141
+ break;
142
+ }
143
+ return _context.abrupt("return", playRef.current);
144
+ case 5:
145
+ if (!(timer < 5)) {
146
+ _context.next = 10;
147
+ break;
148
+ }
149
+ timer++;
150
+ _context.next = 9;
151
+ return sleep(200);
152
+ case 9:
153
+ return _context.abrupt("return", sleep(200).then(function () {
154
+ return getPlay(mapkey);
155
+ }));
156
+ case 10:
157
+ return _context.abrupt("return", undefined);
158
+ case 11:
159
+ case "end":
160
+ return _context.stop();
161
+ }
162
+ }
163
+ }, _callee);
164
+ }));
165
+ }
166
+ getPlay(key).then(function (play) {
167
+ play && play.api.seekTo(seekTime);
168
+ setState(function (old) {
169
+ return Object.assign(Object.assign({}, old), {
170
+ seekTo: Object.assign(Object.assign({}, old.seekTo), _defineProperty({}, key, 0))
171
+ });
202
172
  });
203
173
  });
204
- var play = getPlayerItem();
205
- play.api.seekTo(state.seekTo);
206
174
  // eslint-disable-next-line react-hooks/exhaustive-deps
207
- }, [state.seekTo, state.selectIndex, recordList, segmentItem.recordType]);
175
+ }, [state.seekTo, list]);
208
176
  // 更新状态
209
177
  var updateState = function updateState(newState) {
210
178
  var obj = {};
@@ -221,7 +189,7 @@ function RecordPlayer(_a) {
221
189
  }
222
190
  }
223
191
  if (newState.hasOwnProperty('mode')) {
224
- var item = state.mergeSegments[state.selectIndex];
192
+ var item = screenList[state.selectIndex];
225
193
  var newModes = Object.assign({}, state.modes);
226
194
  newModes["".concat(item.cid, "-").concat(item.date)] = newState.mode;
227
195
  obj.modes = newModes;
@@ -239,83 +207,62 @@ function RecordPlayer(_a) {
239
207
  * 2:不在片断内,查询新的片段,更新mergeSegments和seekTo后交给seek hook处理
240
208
  */
241
209
  var onTimeChange = useCallback(function (time, outTimeline) {
242
- return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
243
- var index, segments;
244
- return _regeneratorRuntime().wrap(function _callee$(_context) {
210
+ return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
211
+ var index;
212
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
245
213
  while (1) {
246
- switch (_context.prev = _context.next) {
214
+ switch (_context2.prev = _context2.next) {
247
215
  case 0:
248
- if (!(!Array.isArray(segmentItem.segments) || state.loading)) {
249
- _context.next = 2;
216
+ if (!(!Array.isArray(segmentItem.segments) || seekLoading)) {
217
+ _context2.next = 2;
250
218
  break;
251
219
  }
252
- return _context.abrupt("return");
220
+ return _context2.abrupt("return");
253
221
  case 2:
254
222
  if (!(outTimeline && segmentItem.recordType === 1)) {
255
- _context.next = 5;
223
+ _context2.next = 5;
256
224
  break;
257
225
  }
258
226
  // 云录像 若点击了缺失的片段,直接忽略
259
- _message.warning('当前录像片段缺失!');
260
- return _context.abrupt("return");
227
+ console.warn('当前录像片段缺失!');
228
+ return _context2.abrupt("return");
261
229
  case 5:
262
230
  if (!(time > Date.now())) {
263
- _context.next = 8;
231
+ _context2.next = 8;
264
232
  break;
265
233
  }
266
234
  console.warn('查询时间超出正常范围!');
267
- return _context.abrupt("return");
235
+ return _context2.abrupt("return");
268
236
  case 8:
269
237
  index = segmentItem.segments.findIndex(function (v) {
270
238
  return time >= v.beginTime && time < v.endTime;
271
239
  });
272
- if (!(index === -1)) {
273
- _context.next = 14;
274
- break;
240
+ if (index === -1) {
241
+ // 触发回调
242
+ onTimeLineChange === null || onTimeLineChange === void 0 ? void 0 : onTimeLineChange(time);
275
243
  }
276
- _context.next = 12;
277
- return queryRecord({
278
- cid: segmentItem.cid,
279
- date: time,
280
- recordType: segmentItem.recordType
281
- });
282
- case 12:
283
- segments = _context.sent;
284
- setState(function (old) {
285
- return Object.assign(Object.assign({}, old), {
286
- loading: true
287
- });
288
- });
289
- case 14:
290
244
  //更新time
291
245
  setState(function (old) {
292
- var mergeSegments = old.mergeSegments;
293
- if (segments) {
294
- mergeSegments[old.selectIndex].segments = segments;
295
- mergeSegments = _toConsumableArray(mergeSegments);
296
- }
297
246
  var currentTimes = Object.assign({}, old.currentTimes);
298
- var item = mergeSegments[old.selectIndex];
247
+ var item = screenList[old.selectIndex];
299
248
  currentTimes["".concat(item.cid, "-").concat(item.date)] = time;
300
249
  return Object.assign(Object.assign({}, old), {
301
250
  currentTimes: currentTimes,
302
- mergeSegments: mergeSegments,
303
- loading: false,
304
- seekTo: time
251
+ seekTo: Object.assign(Object.assign({}, old.seekTo), _defineProperty({}, "".concat(item.cid, "-").concat(item.date), time))
305
252
  });
306
253
  });
307
- case 15:
254
+ case 11:
308
255
  case "end":
309
- return _context.stop();
256
+ return _context2.stop();
310
257
  }
311
258
  }
312
- }, _callee);
259
+ }, _callee2);
313
260
  }));
314
261
  },
315
262
  // eslint-disable-next-line react-hooks/exhaustive-deps
316
- [segmentItem.cid, segmentItem.recordType, segmentItem.segments, state.loading]);
263
+ [segmentItem.cid, segmentItem.recordType, segmentItem.segments, seekLoading]);
317
264
  var _updatePlayer = function updatePlayer(player, index) {
318
- var item = state.mergeSegments[index];
265
+ var item = screenList[index];
319
266
  playerRef.current["".concat(item.cid, "-").concat(item.date)] = player;
320
267
  setState(function (old) {
321
268
  return Object.assign({}, old);
@@ -354,9 +301,9 @@ function RecordPlayer(_a) {
354
301
  className: "player-layout",
355
302
  ref: domRef
356
303
  }, screenList.map(function (item, index) {
357
- var _a, _b, _c, _d;
304
+ var _a, _b;
358
305
  return item.recordType === 1 ? /*#__PURE__*/React.createElement(SegmentPlayerWithExt, Object.assign({}, item, {
359
- segments: ((_a = recordList[index]) === null || _a === void 0 ? void 0 : _a.segments) || [],
306
+ segments: (item === null || item === void 0 ? void 0 : item.segments) || [],
360
307
  key: item.date && item.cid ? "".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid) : "".concat(index),
361
308
  className: state.selectIndex === index ? 'player-current-index' : '',
362
309
  updatePlayer: function updatePlayer(player) {
@@ -373,13 +320,13 @@ function RecordPlayer(_a) {
373
320
  width: screenType.width,
374
321
  height: screenType.height
375
322
  },
376
- mode: (_b = state.modes["".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid)]) !== null && _b !== void 0 ? _b : item.mode,
323
+ mode: (_a = state.modes["".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid)]) !== null && _a !== void 0 ? _a : item.mode,
377
324
  fps: fps,
378
325
  fpsDelay: fpsDelay,
379
- httpLoading: state.winLoadingStatus["".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid)]
326
+ httpLoading: item.loading
380
327
  })) : /*#__PURE__*/React.createElement(FrontendPlayerWithExt, Object.assign({}, item, {
381
328
  className: state.selectIndex === index ? 'player-current-index' : '',
382
- segments: ((_c = recordList[index]) === null || _c === void 0 ? void 0 : _c.segments) || [],
329
+ segments: (item === null || item === void 0 ? void 0 : item.segments) || [],
383
330
  updatePlayer: function updatePlayer(player) {
384
331
  return _updatePlayer(player, index);
385
332
  },
@@ -390,13 +337,13 @@ function RecordPlayer(_a) {
390
337
  });
391
338
  });
392
339
  },
393
- mode: (_d = state.modes["".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid)]) !== null && _d !== void 0 ? _d : item.mode,
340
+ mode: (_b = state.modes["".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid)]) !== null && _b !== void 0 ? _b : item.mode,
394
341
  key: item.date && item.cid ? "".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid) : "".concat(index),
395
342
  style: {
396
343
  width: screenType.width,
397
344
  height: screenType.height
398
345
  },
399
- httpLoading: state.winLoadingStatus["".concat(item === null || item === void 0 ? void 0 : item.date, "-").concat(item.cid)],
346
+ httpLoading: item.loading,
400
347
  getLocalRecordUrl: getLocalRecordUrl,
401
348
  pluginDownloadUrl: pluginDownloadUrl
402
349
  }));
@@ -34,7 +34,7 @@ function RecordTools(_ref) {
34
34
  snapshot = _ref.snapshot,
35
35
  oneWinExtTools = _ref.oneWinExtTools,
36
36
  allWinExtTools = _ref.allWinExtTools;
37
- var _a;
37
+ var _a, _b, _c;
38
38
  var _useFullscreen = useFullscreen(containerRef),
39
39
  _useFullscreen2 = _slicedToArray(_useFullscreen, 2),
40
40
  isFullscreen = _useFullscreen2[0],
@@ -128,7 +128,7 @@ function RecordTools(_ref) {
128
128
  title: "\u9010\u5E27\u64AD\u653E"
129
129
  })), /*#__PURE__*/React.createElement(RatePick, {
130
130
  onChange: ratechange,
131
- value: (_a = player === null || player === void 0 ? void 0 : player.video.playbackRate) !== null && _a !== void 0 ? _a : 1
131
+ value: (_b = (_a = player === null || player === void 0 ? void 0 : player.video) === null || _a === void 0 ? void 0 : _a.playbackRate) !== null && _b !== void 0 ? _b : 1
132
132
  }), oneWinExtTools), /*#__PURE__*/React.createElement("div", {
133
133
  className: "player-tools-mid"
134
134
  }, /*#__PURE__*/React.createElement("div", {
@@ -146,7 +146,7 @@ function RecordTools(_ref) {
146
146
  }), /*#__PURE__*/React.createElement("div", {
147
147
  className: "player-tools-item",
148
148
  onClick: playToggle
149
- }, player && !player.video.paused ? /*#__PURE__*/React.createElement(IconFont, {
149
+ }, player && !((_c = player.video) === null || _c === void 0 ? void 0 : _c.paused) ? /*#__PURE__*/React.createElement(IconFont, {
150
150
  type: "lm-player-Pause_Main",
151
151
  title: "\u6682\u505C",
152
152
  style: {
@@ -1,7 +1,9 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  import "antd/lib/date-picker/style";
2
3
  import _DatePicker from "antd/lib/date-picker";
3
4
  import "antd/lib/config-provider/style";
4
5
  import _ConfigProvider from "antd/lib/config-provider";
6
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
5
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
8
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
9
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -12,31 +14,50 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
12
14
  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
15
  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; }
14
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
- import { __rest } from "tslib";
17
+ import { __awaiter, __rest } from "tslib";
16
18
  import React, { useMemo, useState } from 'react';
17
19
  import RecordPlayer from './Record';
18
20
  import moment from 'moment';
19
21
  import { completionSegments } from './utils';
20
- var cids = ['538509097', '539172446'];
22
+ import Service from '../Service';
23
+ var token = "eyJhbGciOiJIUzI1NiJ9.eyJvcmdhbml6YXRpb25JZCI6IjEwMDEwMTAwMDQ0NSIsImV4dCI6MTY2ODI1OTg2NjQyNywidWlkIjoiMTAxMDAwMDAwNjk5IiwidmFsaWRTdGF0ZSI6MTA0NDA2LCJyb2xlSWQiOlsxMDAwMDAxMTA1MTgsMTAwMDAwMTEwNzI4XSwidmFsaWRUaW1lIjoxNzA0MzgzOTk5MDAwLCJvcHRDZW50ZXJJZCI6IjEwMDEwMDAwMDIzMyIsInVzZXJUeXBlIjoxMDA3MDQsImlhdCI6MTY2ODAwMDY2NjQyN30.LukoTVo52uE6X5nqlXhDuXLX02mAbpRA5pR1ROObmKA";
24
+ var cids = ['560077633', '560073578'];
21
25
  var query = function query(_a) {
22
26
  var cid = _a.cid,
23
27
  date = _a.date,
24
28
  recordType = _a.recordType,
25
29
  props = __rest(_a, ["cid", "date", "recordType"]);
26
- var json = {
27
- code: 0,
28
- codeRemark: '操作成功',
29
- data: [{
30
- begin: 1666627615,
31
- end: 1666697789,
32
- play_url: 'http://192.168.2.63:18092/flv/vod/2834d2b1be2ca7056_1/1bd7e2db944e0c87f.flv?origin_url=sdk%3A%2F%2Fadmin%3Alingyang123%40192.168.2.200%3A8000%2Fcam%2Fplayback%3Ffactory%3Dhikvision%26channel%3D1%26subType%3D0%26startTime%3D1666627615%26endTime%3D1666697789'
33
- }, {
34
- begin: 1666697792,
35
- end: 1666713420,
36
- play_url: 'http://192.168.2.63:18092/flv/vod/2834d2b1be2ca7056_1/1a151c645418ceec0.flv?origin_url=sdk%3A%2F%2Fadmin%3Alingyang123%40192.168.2.200%3A8000%2Fcam%2Fplayback%3Ffactory%3Dhikvision%26channel%3D1%26subType%3D0%26startTime%3D1666697792%26endTime%3D1666713420'
37
- }]
38
- };
39
- console.log(cid, date, recordType, props);
30
+ // const json = {
31
+ // code: 0,
32
+ // message: '成功',
33
+ // data: [
34
+ // {
35
+ // beginTime: '1667995200',
36
+ // endTime: '1667996100',
37
+ // url: 'https://jxsr-oss1.antelopecloud.cn/oss/v1/560077633/record/m3u8/1667995200_1667996100.m3u8?client_token=560077633_0_1668087138_21ad227ea16c7b29c11ea741f12bba36&head=1',
38
+ // },
39
+ // {
40
+ // beginTime: '1667996100',
41
+ // endTime: '1667997000',
42
+ // url: 'https://jxsr-oss1.antelopecloud.cn/oss/v1/560077633/record/m3u8/1667996100_1667997000.m3u8?client_token=560077633_0_1668087138_21ad227ea16c7b29c11ea741f12bba36',
43
+ // },
44
+ // {
45
+ // beginTime: '1667997000',
46
+ // endTime: '1667997900',
47
+ // url: 'https://jxsr-oss1.antelopecloud.cn/oss/v1/560077633/record/m3u8/1667997000_1667997900.m3u8?client_token=560077633_0_1668087138_21ad227ea16c7b29c11ea741f12bba36',
48
+ // },
49
+ // {
50
+ // beginTime: '1667997900',
51
+ // endTime: '1667998800',
52
+ // url: 'https://jxsr-oss1.antelopecloud.cn/oss/v1/560077633/record/m3u8/1667997900_1667998800.m3u8?client_token=560077633_0_1668087138_21ad227ea16c7b29c11ea741f12bba36',
53
+ // },
54
+ // {
55
+ // beginTime: '1667998800',
56
+ // endTime: '1667999136',
57
+ // url: 'https://jxsr-oss1.antelopecloud.cn/oss/v1/560077633/record/m3u8/1667998800_1667999136.m3u8?client_token=560077633_0_1668087138_21ad227ea16c7b29c11ea741f12bba36',
58
+ // },
59
+ // ],
60
+ // };
40
61
  var m = moment(date);
41
62
  var beginTime = m.set({
42
63
  hours: 0,
@@ -48,15 +69,19 @@ var query = function query(_a) {
48
69
  minutes: 59,
49
70
  seconds: 59
50
71
  }).unix();
51
- var promise = Promise.resolve(json.data.map(function (v) {
52
- return {
53
- url: v.play_url,
54
- beginTime: v.begin,
55
- endTime: v.end
56
- };
57
- }));
72
+ var promise = Service.http({
73
+ method: 'post',
74
+ url: "https://jxsr-eye.antelopecloud.cn/api/staticResource/v2/video/queryHistoryAddress?Authorization=".concat(token),
75
+ data: {
76
+ cid: cid,
77
+ mediaType: 'hls',
78
+ beginTime: beginTime,
79
+ endTime: endTime
80
+ }
81
+ });
82
+ // const promise = Promise.resolve(json.data.map((v: any) => ({ url: v.play_url, beginTime: v.begin, endTime: v.end })));
58
83
  return promise.then(function (res) {
59
- return completionSegments(beginTime, endTime, res).map(function (v) {
84
+ return completionSegments(beginTime, endTime, res.data).map(function (v) {
60
85
  return Object.assign(Object.assign({}, v), {
61
86
  beginTime: v.beginTime * 1000,
62
87
  endTime: v.endTime * 1000
@@ -69,6 +94,7 @@ var query = function query(_a) {
69
94
  });
70
95
  };
71
96
  export default function App() {
97
+ var _this = this;
72
98
  var _useState = useState({
73
99
  list: [],
74
100
  idx: 0
@@ -83,7 +109,6 @@ export default function App() {
83
109
  second: 0
84
110
  }) : undefined;
85
111
  }, [state.list, state.idx]);
86
- console.log(state.list);
87
112
  return /*#__PURE__*/React.createElement(_ConfigProvider, {
88
113
  prefixCls: "cloudapp"
89
114
  }, /*#__PURE__*/React.createElement("div", {
@@ -93,24 +118,52 @@ export default function App() {
93
118
  }, /*#__PURE__*/React.createElement(_DatePicker, {
94
119
  value: value,
95
120
  onChange: function onChange(v) {
96
- var flag = state.idx % 2 === 0;
97
- setState(function (old) {
98
- var list = old.list;
99
- list[old.idx] = {
100
- date: v.set({
101
- hours: 0,
102
- seconds: 0,
103
- minutes: 0
104
- }).valueOf(),
105
- cid: flag ? cids[0] : cids[1],
106
- type: flag ? 'hls' : 'flv',
107
- recordType: flag ? 1 : 2,
108
- aaa: 111
109
- };
110
- return Object.assign(Object.assign({}, old), {
111
- list: _toConsumableArray(list)
112
- });
113
- });
121
+ return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
122
+ var list, flag, cid, date, item, segments;
123
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
124
+ while (1) {
125
+ switch (_context.prev = _context.next) {
126
+ case 0:
127
+ list = _toConsumableArray(state.list);
128
+ flag = state.idx % 2 === 0;
129
+ cid = flag ? cids[0] : cids[1];
130
+ date = v.set({
131
+ hours: 0,
132
+ minutes: 0,
133
+ seconds: 0
134
+ }).valueOf();
135
+ item = {
136
+ date: date,
137
+ cid: cid,
138
+ type: 'hls',
139
+ recordType: 1,
140
+ loading: true
141
+ };
142
+ list[state.idx] = item;
143
+ setState(function (old) {
144
+ return Object.assign(Object.assign({}, old), {
145
+ list: list
146
+ });
147
+ });
148
+ _context.next = 9;
149
+ return query(item);
150
+ case 9:
151
+ segments = _context.sent;
152
+ item.loading = false;
153
+ item.segments = segments;
154
+ list[state.idx] = item;
155
+ setState(function (old) {
156
+ return Object.assign(Object.assign({}, old), {
157
+ list: _toConsumableArray(list)
158
+ });
159
+ });
160
+ case 14:
161
+ case "end":
162
+ return _context.stop();
163
+ }
164
+ }
165
+ }, _callee);
166
+ }));
114
167
  }
115
168
  }), /*#__PURE__*/React.createElement("div", {
116
169
  style: {
@@ -128,14 +181,42 @@ export default function App() {
128
181
  });
129
182
  });
130
183
  },
131
- queryRecordErrorHandle: function queryRecordErrorHandle(idx) {
132
- var list = state.list;
133
- list[idx] = undefined;
134
- setState(function (old) {
135
- return Object.assign(Object.assign({}, old), {
136
- list: _toConsumableArray(list)
137
- });
138
- });
184
+ onTimeLineChange: function onTimeLineChange(date) {
185
+ return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
186
+ var item, segments;
187
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
188
+ while (1) {
189
+ switch (_context2.prev = _context2.next) {
190
+ case 0:
191
+ item = state.list[state.idx];
192
+ state.list[state.idx].loading = true;
193
+ setState(function (old) {
194
+ return Object.assign(Object.assign({}, old), {
195
+ list: _toConsumableArray(state.list)
196
+ });
197
+ });
198
+ _context2.next = 5;
199
+ return query({
200
+ cid: item.cid,
201
+ date: date,
202
+ recordType: 1
203
+ });
204
+ case 5:
205
+ segments = _context2.sent;
206
+ state.list[state.idx].loading = false;
207
+ state.list[state.idx].segments = [].concat(_toConsumableArray(segments), _toConsumableArray(state.list[state.idx].segments));
208
+ setState(function (old) {
209
+ return Object.assign(Object.assign({}, old), {
210
+ list: _toConsumableArray(state.list)
211
+ });
212
+ });
213
+ case 9:
214
+ case "end":
215
+ return _context2.stop();
216
+ }
217
+ }
218
+ }, _callee2);
219
+ }));
139
220
  },
140
221
  onClose: function onClose() {
141
222
  var list = state.list;
@@ -1,6 +1,6 @@
1
1
  import type React from 'react';
2
2
  import type { PlayModeType } from '../PlayerExt';
3
- import type { ISegmentType,ExportPlayerType } from '../Player/player';
3
+ import type { ISegmentType, ExportPlayerType } from '../Player/player';
4
4
 
5
5
  export type RecordItem = {
6
6
  type?: 'flv' | 'hls' | 'native';
@@ -10,13 +10,14 @@ export type RecordItem = {
10
10
  url?: string;
11
11
  recordType?: 1 | 2; //1云录像 2前端录像
12
12
  mode?: PlayModeType;
13
+ loading?: boolean; // 录像获取状态
13
14
  };
14
15
 
15
16
  export interface IRecordPlayerProps {
16
17
  /**
17
18
  * 播放对象
18
19
  */
19
- list?: Omit<RecordItem, 'segments' | 'url'>[];
20
+ list?: RecordItem[];
20
21
  children?: JSX.Element;
21
22
 
22
23
  /**
@@ -88,7 +89,20 @@ export interface IRecordPlayerProps {
88
89
  */
89
90
  getLocalRecordUrl?: (options: { url: URL; begin: number; end: number }) => Promise<string>;
90
91
 
92
+ /**
93
+ * 插件下载地址
94
+ */
91
95
  pluginDownloadUrl?: string;
96
+
97
+ /**
98
+ * 轴发生变化
99
+ */
100
+ onTimeLineChange?: (time: number) => void;
101
+
102
+ /**
103
+ * 用户控制seek频率
104
+ */
105
+ seekLoading?: boolean;
92
106
  }
93
107
 
94
108
  export interface IRecordPlayerState {
@@ -105,37 +119,22 @@ export interface IRecordPlayerState {
105
119
  /**
106
120
  * 插件OR浏览器
107
121
  */
108
- modes: {[key:string]:PlayModeType};
122
+ modes: { [key: string]: PlayModeType };
109
123
 
110
124
  /**
111
125
  * 时间轴开始时间
112
126
  */
113
- currentTimes: {[key:string]:number};
127
+ currentTimes: { [key: string]: number };
114
128
 
115
129
  /**
116
130
  * 需要seek的时间针对当前窗口,为0时忽略
117
131
  */
118
- seekTo?: number;
119
-
120
- /**
121
- * 接收外部list变化,同时存储滑动时间轴后新日期的片段
122
- */
123
- mergeSegments?: RecordItem[];
124
-
125
- /**
126
- * 加载中,用于拦截多次时间轴变化需要加载片段的情况
127
- */
128
- loading?: boolean;
132
+ seekTo?: { [key: string]: number };
129
133
 
130
134
  /**
131
135
  * 录像时间轴单页绘制时长单位(hour)
132
136
  */
133
137
  timeMode: number;
134
-
135
- /**
136
- * 窗口播放状态
137
- */
138
- winLoadingStatus: {[key:string]:boolean};
139
138
  }
140
139
 
141
140
  export type ScreenItemLivePlayerType = {
@@ -205,9 +204,9 @@ export interface ILivePlayerProps {
205
204
  export interface ILivePlayerState {
206
205
  screenNum: number;
207
206
  selectIndex: number;
208
- modes: {[key:string]:PlayModeType};
207
+ modes: { [key: string]: PlayModeType };
209
208
  }
210
209
 
211
210
  export const RecordPlayer: React.FC<IRecordPlayerProps>;
212
211
 
213
- export type PlayItemMapType = { [key: string]: React.MutableRefObject<ExportPlayerType> };
212
+ export type PlayItemMapType = { [key: string]: React.MutableRefObject<ExportPlayerType> };
@@ -9,17 +9,6 @@ export declare const TimeModeLibs: {
9
9
  name: number;
10
10
  }[];
11
11
  export declare function mergeFill<T, S>(len: number, mergeArr: T[], fillItem: S): (T | S)[];
12
- export declare const FILTER_KEY = "00|11|00";
13
- /**
14
- * 找出两个数组不等的索引
15
- * @param arr1
16
- * @param arr2
17
- * @returns
18
- */
19
- export declare function differenceWithIndexs(arr1: any[], arr2: any[]): {
20
- idx: number;
21
- value: string;
22
- }[];
23
12
  /**
24
13
  * unix时间戳
25
14
  * @param start
@@ -27,3 +16,4 @@ export declare function differenceWithIndexs(arr1: any[], arr2: any[]): {
27
16
  * @param segments
28
17
  */
29
18
  export declare const completionSegments: (start: number, end: number, segments: ISegmentType[]) => ISegmentType[];
19
+ export declare function sleep(time: number): Promise<unknown>;
@@ -38,25 +38,6 @@ export function mergeFill(len, mergeArr, fillItem) {
38
38
  return mergeArr[i] ? mergeArr[i] : v;
39
39
  });
40
40
  }
41
- export var FILTER_KEY = '00|11|00'; // 需要忽略的key值
42
- /**
43
- * 找出两个数组不等的索引
44
- * @param arr1
45
- * @param arr2
46
- * @returns
47
- */
48
- export function differenceWithIndexs(arr1, arr2) {
49
- var idxs = [];
50
- arr1.forEach(function (item, index) {
51
- if (item && item !== arr2[index]) {
52
- idxs.push({
53
- idx: index,
54
- value: item
55
- });
56
- }
57
- });
58
- return idxs;
59
- }
60
41
  /**
61
42
  * unix时间戳
62
43
  * @param start
@@ -91,4 +72,11 @@ export var completionSegments = function completionSegments(start, end, segments
91
72
  });
92
73
  }
93
74
  return arr;
94
- };
75
+ };
76
+ export function sleep(time) {
77
+ return new Promise(function (reslove) {
78
+ return setTimeout(function () {
79
+ return reslove(time);
80
+ }, time);
81
+ });
82
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "private": false,
3
3
  "name": "@cloud-app-dev/vidc",
4
4
  "description": "Video Image Data Componennts",
5
- "version": "3.1.22",
5
+ "version": "3.2.1",
6
6
  "scripts": {
7
7
  "start": "dumi dev",
8
8
  "docs:build": "dumi build",
@@ -1,8 +0,0 @@
1
- import { ISegmentType } from '../Player/player';
2
- import { RecordItem } from './interface';
3
- interface IUseRecordOptions {
4
- loaddingCallback: (index: number, loading: boolean) => void;
5
- errorCallback: (index: number) => void;
6
- }
7
- declare function useRecordList(list: RecordItem[], queryRecord: (options: any) => Promise<ISegmentType[]>, options: IUseRecordOptions): RecordItem[];
8
- export default useRecordList;
@@ -1,245 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- import _useAsyncEffect from "ahooks/es/useAsyncEffect";
3
- import _useMemoizedFn from "ahooks/es/useMemoizedFn";
4
- import _usePrevious from "ahooks/es/usePrevious";
5
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
6
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
11
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
- 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."); }
13
- 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); }
14
- 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; }
15
- 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; }
16
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
- import { __awaiter } from "tslib";
18
- import { differenceBy, orderBy, uniqBy } from 'lodash-es';
19
- import { useMemo, useState } from 'react';
20
- import { differenceWithIndexs, FILTER_KEY } from './utils';
21
- function useRecordList(list, queryRecord, options) {
22
- var _this = this;
23
- var _useState = useState({
24
- cidSegments: []
25
- }),
26
- _useState2 = _slicedToArray(_useState, 2),
27
- state = _useState2[0],
28
- setState = _useState2[1];
29
- var listKey = useMemo(function () {
30
- return list.map(function (v) {
31
- var _a, _b;
32
- return v ? "".concat(v.cid, "|").concat(v.date, "|").concat((_b = (_a = v.segments) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) : FILTER_KEY;
33
- }).join('-');
34
- }, [list]);
35
- var prevListKey = _usePrevious(listKey);
36
- var loaddingCallback = _useMemoizedFn(options.loaddingCallback);
37
- var errorCallback = _useMemoizedFn(options.errorCallback);
38
- _useAsyncEffect(function () {
39
- return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
40
- var diffIndexs, arr, _iterator, _step, dif, index, item, record, segments, _segments, _segments2, _segments3;
41
- return _regeneratorRuntime().wrap(function _callee$(_context) {
42
- while (1) {
43
- switch (_context.prev = _context.next) {
44
- case 0:
45
- diffIndexs = differenceWithIndexs(listKey ? listKey.split('-') : [], prevListKey ? prevListKey.split('-') : []);
46
- if (!(diffIndexs.length === 0)) {
47
- _context.next = 3;
48
- break;
49
- }
50
- return _context.abrupt("return");
51
- case 3:
52
- arr = []; // 存在披露更新的情况
53
- _iterator = _createForOfIteratorHelper(diffIndexs);
54
- _context.prev = 5;
55
- _iterator.s();
56
- case 7:
57
- if ((_step = _iterator.n()).done) {
58
- _context.next = 52;
59
- break;
60
- }
61
- dif = _step.value;
62
- index = dif.idx;
63
- item = list[index]; // 当前外部传入的对象
64
- record = state.cidSegments[index]; //当前转换的播放对象
65
- if (item) {
66
- _context.next = 16;
67
- break;
68
- }
69
- // 这里可能原来是空,也可能是外部删除
70
- arr.push({
71
- idx: index,
72
- type: 'delete',
73
- segments: []
74
- });
75
- _context.next = 50;
76
- break;
77
- case 16:
78
- if (item.cid && item.date) {
79
- _context.next = 18;
80
- break;
81
- }
82
- return _context.abrupt("continue", 50);
83
- case 18:
84
- _context.prev = 18;
85
- loaddingCallback(index, true);
86
- if (record) {
87
- _context.next = 27;
88
- break;
89
- }
90
- _context.next = 23;
91
- return queryRecord(Object.assign(Object.assign({}, item), {
92
- cid: item.cid,
93
- date: item.date,
94
- recordType: item.recordType
95
- }));
96
- case 23:
97
- segments = _context.sent;
98
- arr.push({
99
- idx: index,
100
- type: 'add',
101
- segments: segments
102
- });
103
- _context.next = 42;
104
- break;
105
- case 27:
106
- if (!(record.cid !== item.cid || record.recordType !== item.recordType)) {
107
- _context.next = 34;
108
- break;
109
- }
110
- _context.next = 30;
111
- return queryRecord(Object.assign(Object.assign({}, item), {
112
- cid: item.cid,
113
- date: item.date,
114
- recordType: item.recordType
115
- }));
116
- case 30:
117
- _segments = _context.sent;
118
- arr.push({
119
- idx: index,
120
- type: 'add',
121
- segments: _segments
122
- });
123
- _context.next = 42;
124
- break;
125
- case 34:
126
- if (!(record.date !== item.date)) {
127
- _context.next = 41;
128
- break;
129
- }
130
- _context.next = 37;
131
- return queryRecord(Object.assign(Object.assign({}, item), {
132
- cid: item.cid,
133
- date: item.date,
134
- recordType: item.recordType
135
- }));
136
- case 37:
137
- _segments2 = _context.sent;
138
- arr.push({
139
- idx: index,
140
- type: 'modify',
141
- segments: _segments2
142
- });
143
- _context.next = 42;
144
- break;
145
- case 41:
146
- if (Array.isArray(item.segments) && item.segments.length > 0) {
147
- // 时间轴更新
148
- _segments3 = item.segments;
149
- arr.push({
150
- idx: index,
151
- type: 'modify',
152
- segments: _segments3
153
- });
154
- } else {
155
- console.debug('无变化!跳过~');
156
- }
157
- case 42:
158
- loaddingCallback(index, false);
159
- _context.next = 50;
160
- break;
161
- case 45:
162
- _context.prev = 45;
163
- _context.t0 = _context["catch"](18);
164
- console.error(_context.t0);
165
- errorCallback(index);
166
- loaddingCallback(index, false);
167
- case 50:
168
- _context.next = 7;
169
- break;
170
- case 52:
171
- _context.next = 57;
172
- break;
173
- case 54:
174
- _context.prev = 54;
175
- _context.t1 = _context["catch"](5);
176
- _iterator.e(_context.t1);
177
- case 57:
178
- _context.prev = 57;
179
- _iterator.f();
180
- return _context.finish(57);
181
- case 60:
182
- setState(function (old) {
183
- var flag = false; //标记是否更新
184
- var cidSegments = state.cidSegments;
185
- arr.forEach(function (_ref) {
186
- var type = _ref.type,
187
- segments = _ref.segments,
188
- idx = _ref.idx;
189
- var index = idx;
190
- var item = list[index];
191
- switch (type) {
192
- case 'add':
193
- // 这里重置播放对象
194
- flag = true;
195
- var arr1 = item.segments ? [].concat(item.segments, segments) : segments;
196
- arr1 = arr1.map(function (v) {
197
- return Object.assign(Object.assign({}, v), {
198
- id: "".concat(v.beginTime, "-").concat(v.endTime)
199
- });
200
- });
201
- cidSegments[index] = Object.assign(Object.assign({}, item), {
202
- segments: orderBy(uniqBy(arr1, 'id'), 'beginTime', 'asc')
203
- });
204
- break;
205
- case 'delete':
206
- // 这里一是保持无播放对象,二是删除当前播放对象
207
- flag = true;
208
- cidSegments[index] = undefined;
209
- break;
210
- case 'modify':
211
- // 这里属于相同的播放对象,需要追加播放片断
212
- flag = true;
213
- cidSegments[index].date = item.date;
214
- cidSegments[index].recordType = item.recordType;
215
- var dif = differenceBy(cidSegments[index].segments, segments, 'beginTime');
216
- if (dif.length === 0) {
217
- flag = false;
218
- } else {
219
- var arr2 = [].concat(cidSegments[index].segments, segments);
220
- arr2 = arr2.map(function (v) {
221
- return Object.assign(Object.assign({}, v), {
222
- id: "".concat(v.beginTime, "-").concat(v.endTime)
223
- });
224
- });
225
- arr2 = uniqBy(arr2, 'id');
226
- cidSegments[index].segments = orderBy(arr2, 'beginTime', 'asc');
227
- }
228
- break;
229
- }
230
- });
231
- return Object.assign(Object.assign({}, old), {
232
- cidSegments: flag ? _toConsumableArray(cidSegments) : cidSegments
233
- });
234
- });
235
- case 61:
236
- case "end":
237
- return _context.stop();
238
- }
239
- }
240
- }, _callee, null, [[5, 54, 57, 60], [18, 45]]);
241
- }));
242
- }, [list, listKey, prevListKey]);
243
- return state.cidSegments;
244
- }
245
- export default useRecordList;