x-star-design 0.0.71 → 0.0.72

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.
@@ -5,10 +5,12 @@ import React from 'react';
5
5
  export interface AliplayerConfig {
6
6
  vid: string;
7
7
  playauth: string;
8
+ preventRecord?: boolean;
8
9
  autoplay?: boolean;
9
10
  language?: string;
10
11
  encryptType?: number;
11
12
  keyShortCuts?: boolean;
13
+ ratio?: number;
12
14
  }
13
15
  /**
14
16
  * Aliplayer 实例
@@ -17,7 +19,6 @@ export interface AliplayerInstance {
17
19
  pause: () => void;
18
20
  seek: (time: number) => void;
19
21
  getCurrentTime: () => number;
20
- setPlayerSize: (w: string, h: string) => void;
21
22
  dispose: () => void;
22
23
  on: (name: string, handler: () => void) => void;
23
24
  }
@@ -1,5 +1,4 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import { useMemoizedFn, useSize } from 'ahooks';
3
2
  import React, { useEffect, useMemo, useRef } from 'react';
4
3
  import { randomString } from 'x-star-utils';
5
4
 
@@ -18,58 +17,45 @@ var Aliplayer = function Aliplayer(_ref) {
18
17
  return "aliplayer-".concat(randomString(8));
19
18
  }, []);
20
19
  var player = useRef();
21
- var wrapper = useRef(null);
22
- var size = useSize(wrapper);
23
- var importAliPlayer = function importAliPlayer() {
24
- var link = window.document.createElement('link');
25
- link.rel = 'stylesheet';
26
- link.href = 'https://g.alicdn.com/apsara-media-box/imp-web-player/2.16.3/skins/default/aliplayer-min.css';
27
- var script = window.document.createElement('script');
28
- script.type = 'text/javascript';
29
- script.src = 'https://g.alicdn.com/apsara-media-box/imp-web-player/2.16.3/aliplayer-h5-min.js';
30
- var head = window.document.querySelector('head');
31
- head === null || head === void 0 ? void 0 : head.append(link);
32
- head === null || head === void 0 ? void 0 : head.append(script);
33
- };
34
- if (!window.Aliplayer) {
35
- importAliPlayer();
36
- }
37
-
38
- /**
39
- * 根据宽度调整高度,比例为 16:9
40
- */
41
- var resize = useMemoizedFn(function () {
42
- return player.current && size && player.current.setPlayerSize("".concat(size.width, "px"), "".concat(size.width / 16 * 9, "px"));
43
- });
44
- useEffect(resize, [size]);
45
20
  useEffect(function () {
46
- var create = function create() {
47
- var run = function run(retry) {
48
- var Aliplayer = window.Aliplayer;
49
- if (Aliplayer) {
50
- // 创建 Aliplayer 实例
51
- player.current = new Aliplayer(_objectSpread(_objectSpread({
52
- encryptType: 1,
53
- keyShortCuts: true
54
- }, config), {}, {
55
- id: id
56
- }), function (player) {
57
- return onCreate === null || onCreate === void 0 ? void 0 : onCreate(player);
58
- });
59
- resize();
60
- } else if (retry > 0) {
61
- // 轮询获取 Aliplayer
62
- window.setTimeout(function () {
63
- return run(retry - 1);
64
- }, 100);
65
- }
66
- };
67
- window.setTimeout(function () {
68
- return run(100);
69
- });
21
+ if (!window.Aliplayer) {
22
+ var link = document.createElement('link');
23
+ link.rel = 'stylesheet';
24
+ link.href = 'https://g.alicdn.com/apsara-media-box/imp-web-player/2.25.0/skins/default/aliplayer-min.css';
25
+ var script = document.createElement('script');
26
+ script.type = 'text/javascript';
27
+ script.src = 'https://g.alicdn.com/apsara-media-box/imp-web-player/2.25.0/aliplayer-h5-min.js';
28
+ var head = document.head;
29
+ head.append(link);
30
+ head.append(script);
31
+ }
32
+ }, []);
33
+ useEffect(function () {
34
+ var timer;
35
+ var tryCreate = function tryCreate(retry) {
36
+ var Aliplayer = window.Aliplayer;
37
+ if (Aliplayer) {
38
+ // 创建 Aliplayer 实例
39
+ player.current = new Aliplayer(_objectSpread(_objectSpread({
40
+ preventRecord: true,
41
+ encryptType: 1,
42
+ keyShortCuts: true,
43
+ ratio: 16 / 9
44
+ }, config), {}, {
45
+ id: id
46
+ }), function (player) {
47
+ return onCreate === null || onCreate === void 0 ? void 0 : onCreate(player);
48
+ });
49
+ } else if (retry > 0) {
50
+ // 轮询获取 Aliplayer 类
51
+ timer = window.setTimeout(function () {
52
+ return tryCreate(retry - 1);
53
+ }, 100);
54
+ }
70
55
  };
71
- create();
56
+ tryCreate(100);
72
57
  return function () {
58
+ window.clearTimeout(timer);
73
59
  if (player.current) {
74
60
  player.current.dispose();
75
61
  player.current = undefined;
@@ -77,10 +63,8 @@ var Aliplayer = function Aliplayer(_ref) {
77
63
  };
78
64
  }, [config.vid, config.playauth]);
79
65
  return /*#__PURE__*/React.createElement("div", {
80
- ref: wrapper
81
- }, /*#__PURE__*/React.createElement("div", {
82
- id: id,
83
- "data-testid": "aliplayer-wrapper"
84
- }));
66
+ "data-testid": "aliplayer",
67
+ id: id
68
+ });
85
69
  };
86
70
  export default Aliplayer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-star-design",
3
- "version": "0.0.71",
3
+ "version": "0.0.72",
4
4
  "description": "A react component library developed by turingstar",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",