yootd 0.0.87 → 0.0.89

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.
@@ -7,6 +7,7 @@ export interface VideoPlayerRef {
7
7
  useFaceExpression: (type: 'emotion' | 'character' | 'anchor' | 'pose', use: boolean) => void;
8
8
  currentTime: () => number;
9
9
  }
10
+ type AIFeature = 'emotion' | 'character' | 'anchor' | 'pose';
10
11
  export interface VideoPlayerProps {
11
12
  /**
12
13
  * 视频地址
@@ -44,6 +45,10 @@ export interface VideoPlayerProps {
44
45
  * 是否旋转全屏
45
46
  */
46
47
  rotateWhenFullScreen?: boolean;
48
+ /**
49
+ * AI 功能列表
50
+ */
51
+ aiFeatures?: AIFeature[];
47
52
  /**
48
53
  * 视频封面
49
54
  */
@@ -88,3 +93,4 @@ export interface VideoPlayerProps {
88
93
  onError?: (error: string) => void;
89
94
  }
90
95
  export declare const VideoPlayer: React.ForwardRefExoticComponent<VideoPlayerProps & React.RefAttributes<VideoPlayerRef>>;
96
+ export {};
@@ -1,10 +1,10 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- 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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
5
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
6
5
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
7
6
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
+ 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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8
8
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
9
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
10
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
@@ -14,15 +14,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
14
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
15
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
- import * as faceapi from '@vladmandic/face-api';
18
- import * as posedetection from '@tensorflow-models/pose-detection';
19
- import * as tf from '@tensorflow/tfjs';
17
+ // import * as faceapi from '@vladmandic/face-api';
18
+ //
19
+ // import * as posedetection from '@tensorflow-models/pose-detection';
20
+ // import * as tf from '@tensorflow/tfjs';
21
+
20
22
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
21
23
  import { EndPoint } from 'yootd-webrtc-sdk';
22
24
  import { useBem } from "../hooks/useBem";
23
25
  import "./index.scss";
24
26
  import { throttle } from 'lodash';
25
- import { message, Spin } from "./..";
27
+ import { Spin } from "./..";
26
28
  import { useOSS } from "../hooks/useOSS";
27
29
  import controlBottomBg from "./assets/control-background.png";
28
30
  var PROGRESS_BAR_HEIGHT = 63;
@@ -31,6 +33,8 @@ var MAX_RESULTS = 20; // maximum number of results to return
31
33
 
32
34
  // print hello world
33
35
 
36
+ // type DetectionResult = Record<string, any>;
37
+
34
38
  var speeds = ['2.0', '1.75', '1.5', '1.25', '1.0', '0.75', '0.5'];
35
39
  export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
36
40
  var src = _ref.src,
@@ -39,6 +43,8 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
39
43
  autoPlay = _ref.autoPlay,
40
44
  muted = _ref.muted,
41
45
  style = _ref.style,
46
+ _ref$aiFeatures = _ref.aiFeatures,
47
+ aiFeatures = _ref$aiFeatures === void 0 ? ['emotion', 'character', 'anchor', 'pose'] : _ref$aiFeatures,
42
48
  _ref$retry = _ref.retry,
43
49
  retry = _ref$retry === void 0 ? false : _ref$retry,
44
50
  _ref$retryInterval = _ref.retryInterval,
@@ -62,6 +68,8 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
62
68
  var videoRef = useRef(null);
63
69
  var canvasRef = useRef(null);
64
70
  var poseCanvasRef = useRef(null);
71
+ var detectAllFacesRef = useRef();
72
+ var getAdjacentPairsRef = useRef();
65
73
  var _useState = useState(null),
66
74
  _useState2 = _slicedToArray(_useState, 2),
67
75
  poseDetector = _useState2[0],
@@ -119,49 +127,53 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
119
127
  _useState28 = _slicedToArray(_useState27, 2),
120
128
  showSettingPanel = _useState28[0],
121
129
  setShowSettingPanel = _useState28[1];
122
- var _useState29 = useState({
130
+ var _useState29 = useState(false),
131
+ _useState30 = _slicedToArray(_useState29, 2),
132
+ tfInitialized = _useState30[0],
133
+ setTfInitialized = _useState30[1];
134
+ var _useState31 = useState({
123
135
  emotion: false,
124
136
  character: false,
125
137
  anchor: false,
126
138
  pose: false
127
139
  }),
128
- _useState30 = _slicedToArray(_useState29, 2),
129
- aiFeature = _useState30[0],
130
- setAIFeature = _useState30[1];
131
- var _useState31 = useState(null),
132
140
  _useState32 = _slicedToArray(_useState31, 2),
133
- options = _useState32[0],
134
- setOptions = _useState32[1];
135
- var _useState33 = useState(false),
141
+ aiFeature = _useState32[0],
142
+ setAIFeature = _useState32[1];
143
+ var _useState33 = useState(null),
136
144
  _useState34 = _slicedToArray(_useState33, 2),
137
- faceApiInited = _useState34[0],
138
- setFaceApiInited = _useState34[1];
139
- var _useState35 = useState({
140
- width: 0,
141
- height: 0
142
- }),
145
+ options = _useState34[0],
146
+ setOptions = _useState34[1];
147
+ var _useState35 = useState(false),
143
148
  _useState36 = _slicedToArray(_useState35, 2),
144
- canvasSize = _useState36[0],
145
- setCanvasSize = _useState36[1];
149
+ faceApiInited = _useState36[0],
150
+ setFaceApiInited = _useState36[1];
146
151
  var _useState37 = useState({
147
152
  width: 0,
148
153
  height: 0
149
154
  }),
150
155
  _useState38 = _slicedToArray(_useState37, 2),
151
- videoEleSize = _useState38[0],
152
- setVideoEleSize = _useState38[1];
153
- var _useState39 = useState(false),
156
+ canvasSize = _useState38[0],
157
+ setCanvasSize = _useState38[1];
158
+ var _useState39 = useState({
159
+ width: 0,
160
+ height: 0
161
+ }),
154
162
  _useState40 = _slicedToArray(_useState39, 2),
155
- isSeeking = _useState40[0],
156
- setIsSeeking = _useState40[1];
163
+ videoEleSize = _useState40[0],
164
+ setVideoEleSize = _useState40[1];
157
165
  var _useState41 = useState(false),
158
166
  _useState42 = _slicedToArray(_useState41, 2),
159
- isError = _useState42[0],
160
- setIsError = _useState42[1];
161
- var _useState43 = useState(),
167
+ isSeeking = _useState42[0],
168
+ setIsSeeking = _useState42[1];
169
+ var _useState43 = useState(false),
162
170
  _useState44 = _slicedToArray(_useState43, 2),
163
- features = _useState44[0],
164
- setFeatures = _useState44[1];
171
+ isError = _useState44[0],
172
+ setIsError = _useState44[1];
173
+ var _useState45 = useState(),
174
+ _useState46 = _slicedToArray(_useState45, 2),
175
+ features = _useState46[0],
176
+ setFeatures = _useState46[1];
165
177
  useImperativeHandle(ref, function () {
166
178
  return {
167
179
  play: function play() {
@@ -291,7 +303,6 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
291
303
 
292
304
  // convert video duration (seconds) to hh::mm:ss if the duration is larger than 3600 , else convert to mm:ss
293
305
  var formatDuration = function formatDuration(duration) {
294
- console.log('duration 111111111', duration);
295
306
  var hours = Math.floor(duration / 3600);
296
307
  var minutes = Math.floor(duration % 3600 / 60);
297
308
  var seconds = Math.floor(duration % 60);
@@ -357,80 +368,6 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
357
368
  return !prev;
358
369
  });
359
370
  };
360
- var initFaceApi = useCallback(function () {
361
- void _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
362
- return _regeneratorRuntime().wrap(function _callee$(_context) {
363
- while (1) switch (_context.prev = _context.next) {
364
- case 0:
365
- _context.prev = 0;
366
- _context.next = 3;
367
- return faceapi.nets.ssdMobilenetv1.load("".concat(OSS, "/model-zoo/face-api-models/model"));
368
- case 3:
369
- _context.next = 5;
370
- return faceapi.nets.ssdMobilenetv1.load("".concat(OSS, "/model-zoo/face-api-models/model"));
371
- case 5:
372
- _context.next = 7;
373
- return faceapi.nets.ageGenderNet.load("".concat(OSS, "/face-api-models/model"));
374
- case 7:
375
- _context.next = 9;
376
- return faceapi.nets.faceLandmark68Net.load("".concat(OSS, "/model-zoo/face-api-models/model"));
377
- case 9:
378
- _context.next = 11;
379
- return faceapi.nets.faceRecognitionNet.load("".concat(OSS, "/model-zoo/face-api-models/model"));
380
- case 11:
381
- _context.next = 13;
382
- return faceapi.nets.faceExpressionNet.load("".concat(OSS, "/model-zoo/face-api-models/model"));
383
- case 13:
384
- setOptions(new faceapi.SsdMobilenetv1Options({
385
- minConfidence: MIN_SCORE,
386
- maxResults: MAX_RESULTS
387
- }));
388
- setFaceApiInited(true);
389
- _context.next = 20;
390
- break;
391
- case 17:
392
- _context.prev = 17;
393
- _context.t0 = _context["catch"](0);
394
- console.log(_context.t0);
395
- case 20:
396
- case "end":
397
- return _context.stop();
398
- }
399
- }, _callee, null, [[0, 17]]);
400
- }))();
401
- }, []);
402
- var initPoseDetecter = useCallback(function () {
403
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
404
- var detectorConfig, _poseDetector;
405
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
406
- while (1) switch (_context2.prev = _context2.next) {
407
- case 0:
408
- _context2.prev = 0;
409
- detectorConfig = {
410
- modelType: posedetection.movenet.modelType.MULTIPOSE_LIGHTNING,
411
- enableTracking: true,
412
- trackerType: posedetection.TrackerType.BoundingBox,
413
- scoreThreshold: 0.3,
414
- modelUrl: "".concat(OSS, "/model-zoo/pose-detection-models/model.json")
415
- };
416
- _context2.next = 4;
417
- return posedetection.createDetector(posedetection.SupportedModels.MoveNet, detectorConfig);
418
- case 4:
419
- _poseDetector = _context2.sent;
420
- setPoseDetector(_poseDetector);
421
- _context2.next = 11;
422
- break;
423
- case 8:
424
- _context2.prev = 8;
425
- _context2.t0 = _context2["catch"](0);
426
- void message.error('初始化姿态检测器失败');
427
- case 11:
428
- case "end":
429
- return _context2.stop();
430
- }
431
- }, _callee2, null, [[0, 8]]);
432
- }))();
433
- }, []);
434
371
  var drawFaces = useCallback(function (canvas, detections, fps, faceFeature) {
435
372
  var ctx = canvas.getContext('2d', {
436
373
  willReadFrequently: true
@@ -543,9 +480,9 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
543
480
  }, []);
544
481
  var detectFaces = useCallback(function () {
545
482
  return new Promise(function (resolve, reject) {
546
- if (videoRef.current != null && options != null && faceApiInited) {
483
+ if (videoRef.current != null && detectAllFacesRef.current != null && options != null && faceApiInited) {
547
484
  var t0 = performance.now();
548
- faceapi.detectAllFaces(videoRef.current, options).withFaceLandmarks().withFaceExpressions().withAgeAndGender()
485
+ detectAllFacesRef.current(videoRef.current, options).withFaceLandmarks().withFaceExpressions().withAgeAndGender()
549
486
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
550
487
  // @ts-ignore
551
488
  .then(function (detections) {
@@ -581,11 +518,15 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
581
518
 
582
519
  // 绘制骨架
583
520
  var drawSkeleton = function drawSkeleton(keypoints, ctx) {
584
- var adjacentPairs = posedetection.util.getAdjacentPairs(posedetection.SupportedModels.MoveNet);
585
- adjacentPairs.forEach(function (_ref5) {
586
- var _ref6 = _slicedToArray(_ref5, 2),
587
- i = _ref6[0],
588
- j = _ref6[1];
521
+ if (getAdjacentPairsRef.current == null) {
522
+ return;
523
+ }
524
+ // @ts-expect-error
525
+ var adjacentPairs = getAdjacentPairsRef.current('MoveNet');
526
+ adjacentPairs.forEach(function (_ref3) {
527
+ var _ref4 = _slicedToArray(_ref3, 2),
528
+ i = _ref4[0],
529
+ j = _ref4[1];
589
530
  var kp1 = keypoints[i];
590
531
  var kp2 = keypoints[j];
591
532
  if (kp1.score && kp2.score && kp1.score > 0.3 && kp2.score > 0.3) {
@@ -616,34 +557,34 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
616
557
  var video = videoRef.current;
617
558
  var canvas = poseCanvasRef.current;
618
559
  var detect = /*#__PURE__*/function () {
619
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
560
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
620
561
  var pose;
621
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
622
- while (1) switch (_context3.prev = _context3.next) {
562
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
563
+ while (1) switch (_context.prev = _context.next) {
623
564
  case 0:
624
- _context3.prev = 0;
625
- _context3.next = 3;
565
+ _context.prev = 0;
566
+ _context.next = 3;
626
567
  return poseDetector.estimatePoses(video, {
627
568
  flipHorizontal: false,
628
569
  maxPoses: 1
629
570
  });
630
571
  case 3:
631
- pose = _context3.sent;
572
+ pose = _context.sent;
632
573
  drawPose(canvas, pose);
633
- _context3.next = 10;
574
+ _context.next = 10;
634
575
  break;
635
576
  case 7:
636
- _context3.prev = 7;
637
- _context3.t0 = _context3["catch"](0);
638
- console.error('检测肢体失败', _context3.t0);
577
+ _context.prev = 7;
578
+ _context.t0 = _context["catch"](0);
579
+ console.error('检测肢体失败', _context.t0);
639
580
  case 10:
640
581
  case "end":
641
- return _context3.stop();
582
+ return _context.stop();
642
583
  }
643
- }, _callee3, null, [[0, 7]]);
584
+ }, _callee, null, [[0, 7]]);
644
585
  }));
645
586
  return function detect() {
646
- return _ref7.apply(this, arguments);
587
+ return _ref5.apply(this, arguments);
647
588
  };
648
589
  }();
649
590
  detect();
@@ -698,6 +639,120 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
698
639
  }
699
640
  }
700
641
  };
642
+ useEffect(function () {
643
+ var loaded = true;
644
+ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
645
+ var tf, faceapi, posedetection, detectorConfig, _poseDetector;
646
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
647
+ while (1) switch (_context2.prev = _context2.next) {
648
+ case 0:
649
+ if (loaded) {
650
+ _context2.next = 2;
651
+ break;
652
+ }
653
+ return _context2.abrupt("return");
654
+ case 2:
655
+ _context2.prev = 2;
656
+ if (!((aiFeature.anchor || aiFeature.emotion || aiFeature.character || aiFeature.pose) && !tfInitialized)) {
657
+ _context2.next = 12;
658
+ break;
659
+ }
660
+ _context2.next = 6;
661
+ return import('@tensorflow/tfjs');
662
+ case 6:
663
+ tf = _context2.sent;
664
+ _context2.next = 9;
665
+ return tf.ready();
666
+ case 9:
667
+ _context2.next = 11;
668
+ return tf.setBackend('webgl');
669
+ case 11:
670
+ setTfInitialized(true);
671
+ case 12:
672
+ _context2.next = 17;
673
+ break;
674
+ case 14:
675
+ _context2.prev = 14;
676
+ _context2.t0 = _context2["catch"](2);
677
+ console.error('tensorflow 加载失败: ', _context2.t0);
678
+ case 17:
679
+ _context2.prev = 17;
680
+ if (!((aiFeature.anchor || aiFeature.emotion || aiFeature.character) && !faceApiInited)) {
681
+ _context2.next = 35;
682
+ break;
683
+ }
684
+ _context2.next = 21;
685
+ return import('@vladmandic/face-api');
686
+ case 21:
687
+ faceapi = _context2.sent;
688
+ _context2.next = 24;
689
+ return faceapi.nets.ssdMobilenetv1.load("".concat(OSS, "/model-zoo/face-api-models/model"));
690
+ case 24:
691
+ _context2.next = 26;
692
+ return faceapi.nets.ageGenderNet.load("".concat(OSS, "/face-api-models/model"));
693
+ case 26:
694
+ _context2.next = 28;
695
+ return faceapi.nets.faceLandmark68Net.load("".concat(OSS, "/model-zoo/face-api-models/model"));
696
+ case 28:
697
+ _context2.next = 30;
698
+ return faceapi.nets.faceRecognitionNet.load("".concat(OSS, "/model-zoo/face-api-models/model"));
699
+ case 30:
700
+ _context2.next = 32;
701
+ return faceapi.nets.faceExpressionNet.load("".concat(OSS, "/model-zoo/face-api-models/model"));
702
+ case 32:
703
+ setOptions(new faceapi.SsdMobilenetv1Options({
704
+ minConfidence: MIN_SCORE,
705
+ maxResults: MAX_RESULTS
706
+ }));
707
+ detectAllFacesRef.current = faceapi.detectAllFaces;
708
+ setFaceApiInited(true);
709
+ case 35:
710
+ _context2.next = 40;
711
+ break;
712
+ case 37:
713
+ _context2.prev = 37;
714
+ _context2.t1 = _context2["catch"](17);
715
+ console.error('faceapi 加载失败: ', _context2.t1);
716
+ case 40:
717
+ _context2.prev = 40;
718
+ if (!(aiFeature.pose && poseDetector == null)) {
719
+ _context2.next = 51;
720
+ break;
721
+ }
722
+ _context2.next = 44;
723
+ return import('@tensorflow-models/pose-detection');
724
+ case 44:
725
+ posedetection = _context2.sent;
726
+ detectorConfig = {
727
+ modelType: posedetection.movenet.modelType.MULTIPOSE_LIGHTNING,
728
+ enableTracking: true,
729
+ trackerType: posedetection.TrackerType.BoundingBox,
730
+ scoreThreshold: 0.3,
731
+ modelUrl: "".concat(OSS, "/model-zoo/pose-detection-models/model.json")
732
+ };
733
+ _context2.next = 48;
734
+ return posedetection.createDetector(posedetection.SupportedModels.MoveNet, detectorConfig);
735
+ case 48:
736
+ _poseDetector = _context2.sent;
737
+ getAdjacentPairsRef.current = posedetection.util.getAdjacentPairs;
738
+ setPoseDetector(_poseDetector);
739
+ case 51:
740
+ _context2.next = 56;
741
+ break;
742
+ case 53:
743
+ _context2.prev = 53;
744
+ _context2.t2 = _context2["catch"](40);
745
+ console.error('pose detection 加载失败: ', _context2.t2);
746
+ case 56:
747
+ case "end":
748
+ return _context2.stop();
749
+ }
750
+ }, _callee2, null, [[2, 14], [17, 37], [40, 53]]);
751
+ }))();
752
+ return function () {
753
+ loaded = false;
754
+ };
755
+ }, [aiFeature, faceApiInited, poseDetector, tfInitialized]);
701
756
  useEffect(function () {
702
757
  var player = null;
703
758
  if (isLive && videoRef.current != null) {
@@ -739,34 +794,6 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
739
794
  dom === null || dom === void 0 || dom.removeEventListener('fullscreenchange', handleFullScreen);
740
795
  };
741
796
  }, []);
742
- useEffect(function () {
743
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
744
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
745
- while (1) switch (_context4.prev = _context4.next) {
746
- case 0:
747
- _context4.prev = 0;
748
- _context4.next = 3;
749
- return tf.ready();
750
- case 3:
751
- if ((aiFeature.emotion || aiFeature.character || aiFeature.anchor) && !faceApiInited) {
752
- // 开始初始化人脸
753
- initFaceApi();
754
- }
755
- if (aiFeature.pose && !poseDetector) {
756
- initPoseDetecter();
757
- }
758
- _context4.next = 9;
759
- break;
760
- case 7:
761
- _context4.prev = 7;
762
- _context4.t0 = _context4["catch"](0);
763
- case 9:
764
- case "end":
765
- return _context4.stop();
766
- }
767
- }, _callee4, null, [[0, 7]]);
768
- }))();
769
- }, [aiFeature, faceApiInited, initFaceApi, initPoseDetecter, poseDetector]);
770
797
  useEffect(function () {
771
798
  if (features == null) {
772
799
  return;
@@ -780,29 +807,6 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
780
807
  }, [features, showSettingPanel]);
781
808
  useEffect(function () {
782
809
  var handler = null;
783
- // let lastTime = Date.now();
784
- /* const start = () => {
785
- if (
786
- !faceFeature.anchor &&
787
- !faceFeature.emotion &&
788
- !faceFeature.character
789
- ) {
790
- return;
791
- }
792
- if (lastTime + 1000 <= Date.now()) {
793
- lastTime = Date.now();
794
- detect()
795
- .catch((e) => {
796
- console.log("error", e);
797
- })
798
- .finally(() => {
799
- handler = requestAnimationFrame(start);
800
- });
801
- } else {
802
- handler = requestAnimationFrame(start);
803
- }
804
- }; */
805
-
806
810
  var lastTime = 0;
807
811
  var fps = 30;
808
812
  var start = function start(currentTime) {
@@ -1076,7 +1080,7 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
1076
1080
  onClick: function onClick(e) {
1077
1081
  return e.stopPropagation();
1078
1082
  }
1079
- }, /*#__PURE__*/React.createElement("div", {
1083
+ }, aiFeatures !== null && aiFeatures !== void 0 && aiFeatures.includes('emotion') ? /*#__PURE__*/React.createElement("div", {
1080
1084
  className: "".concat(bem.b('container').e('controls-setting').e('panel').e('item'))
1081
1085
  }, /*#__PURE__*/React.createElement("div", null, "\u9762\u90E8\u8868\u60C5"), /*#__PURE__*/React.createElement("input", {
1082
1086
  onClick: function onClick(e) {
@@ -1092,7 +1096,7 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
1092
1096
  });
1093
1097
  });
1094
1098
  }
1095
- })), /*#__PURE__*/React.createElement("div", {
1099
+ })) : null, aiFeatures !== null && aiFeatures !== void 0 && aiFeatures.includes('character') ? /*#__PURE__*/React.createElement("div", {
1096
1100
  className: "".concat(bem.b('container').e('controls-setting').e('panel').e('item'))
1097
1101
  }, /*#__PURE__*/React.createElement("div", null, "\u9762\u90E8\u7279\u5F81"), /*#__PURE__*/React.createElement("input", {
1098
1102
  onClick: function onClick(e) {
@@ -1108,7 +1112,7 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
1108
1112
  });
1109
1113
  });
1110
1114
  }
1111
- })), /*#__PURE__*/React.createElement("div", {
1115
+ })) : null, aiFeatures !== null && aiFeatures !== void 0 && aiFeatures.includes('anchor') ? /*#__PURE__*/React.createElement("div", {
1112
1116
  className: "".concat(bem.b('container').e('controls-setting').e('panel').e('item'))
1113
1117
  }, /*#__PURE__*/React.createElement("div", null, "\u9762\u90E8\u951A\u70B9"), /*#__PURE__*/React.createElement("input", {
1114
1118
  onClick: function onClick(e) {
@@ -1124,7 +1128,7 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
1124
1128
  });
1125
1129
  });
1126
1130
  }
1127
- })), /*#__PURE__*/React.createElement("div", {
1131
+ })) : null, aiFeatures !== null && aiFeatures !== void 0 && aiFeatures.includes('pose') ? /*#__PURE__*/React.createElement("div", {
1128
1132
  className: "".concat(bem.b('container').e('controls-setting').e('panel').e('item'))
1129
1133
  }, /*#__PURE__*/React.createElement("div", null, "\u80A2\u4F53\u7EBF\u6761"), /*#__PURE__*/React.createElement("input", {
1130
1134
  onClick: function onClick(e) {
@@ -1140,7 +1144,7 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
1140
1144
  });
1141
1145
  });
1142
1146
  }
1143
- }))) : null), !isFullScreen ? /*#__PURE__*/React.createElement("svg", {
1147
+ })) : null) : null), !isFullScreen ? /*#__PURE__*/React.createElement("svg", {
1144
1148
  className: "".concat(bem.b('container').e('controls-full-screen')),
1145
1149
  onClick: handleFullScreen,
1146
1150
  viewBox: "0 0 1024 1024",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yootd",
3
- "version": "0.0.87",
3
+ "version": "0.0.89",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -62,24 +62,17 @@
62
62
  "@types/react-dom": "^18.0.0",
63
63
  "@umijs/lint": "^4.0.0",
64
64
  "@vladmandic/face-api": "^1.7.14",
65
- "axios": "^1.7.7",
66
- "dayjs": "^1.11.13",
67
65
  "dumi": "^2.3.0",
68
66
  "dumi-theme-antd": "^0.4.2",
69
67
  "eslint": "^8.23.0",
70
68
  "father": "^4.1.0",
71
69
  "husky": "^8.0.1",
72
70
  "lint-staged": "^13.0.3",
73
- "lodash": "^4.17.21",
74
- "nanoid": "^5.0.8",
75
71
  "prettier": "^2.7.1",
76
72
  "prettier-plugin-organize-imports": "^3.0.0",
77
73
  "prettier-plugin-packagejson": "^2.2.18",
78
- "react": "^18.0.0",
79
- "react-dom": "^18.0.0",
80
74
  "sass": "^1.80.0",
81
- "stylelint": "^14.9.1",
82
- "yootd-webrtc-sdk": "^1.0.1"
75
+ "stylelint": "^14.9.1"
83
76
  },
84
77
  "peerDependencies": {
85
78
  "@dnd-kit/core": ">=6.1.0",
@@ -94,8 +87,8 @@
94
87
  "dayjs": ">=1.11.13",
95
88
  "lodash": ">=4.17.21",
96
89
  "nanoid": ">=5.0.8",
97
- "react": ">=16.9.0",
98
- "react-dom": ">=16.9.0",
90
+ "react": ">=18.0.0",
91
+ "react-dom": ">=18.0.0",
99
92
  "yootd-webrtc-sdk": "^1.0.1"
100
93
  },
101
94
  "publishConfig": {