pixuireactcomponents 1.3.69 → 1.3.71

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.69",
3
+ "version": "1.3.71",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,25 @@
1
+ import { h } from 'preact';
2
+ export interface VideoPlayerProps {
3
+ playUrl: string;
4
+ autoPlay?: boolean;
5
+ playEvent: {
6
+ onPlay?: () => void;
7
+ onPause?: () => void;
8
+ onEnded?: () => void;
9
+ onFirstFrame?: () => void;
10
+ };
11
+ elementClass: {
12
+ playIcon?: string;
13
+ pauseIcon?: string;
14
+ reloadIcon?: string;
15
+ };
16
+ sliderBG: {
17
+ outerBG?: string;
18
+ innerBG?: string;
19
+ dotBG?: string;
20
+ };
21
+ durations: {
22
+ hideSliderDuration?: number;
23
+ };
24
+ }
25
+ export declare const VideoPlayer: (props: VideoPlayerProps) => h.JSX.Element;
@@ -0,0 +1,239 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { createRef, h } from 'preact';
13
+ import { useEffect, useRef, useState } from 'preact/hooks';
14
+ import { Slider } from '../slider/Slider';
15
+ var videoWrapperStyle = {
16
+ width: '100%',
17
+ height: '100%',
18
+ position: 'absolute',
19
+ // backgroundColor: '#FFF00066'
20
+ };
21
+ var screenClickerStyle = {
22
+ position: 'absolute',
23
+ width: '100%',
24
+ height: '100%',
25
+ alignItems: 'center',
26
+ justifyContent: 'center',
27
+ };
28
+ var loadingContainerStyle = {
29
+ position: 'absolute',
30
+ width: '100%',
31
+ height: '100%',
32
+ };
33
+ // 4个视频播放态
34
+ var VideoStatus;
35
+ (function (VideoStatus) {
36
+ VideoStatus[VideoStatus["Loading"] = 0] = "Loading";
37
+ // LoadError,
38
+ VideoStatus[VideoStatus["Playing"] = 1] = "Playing";
39
+ VideoStatus[VideoStatus["Pause"] = 2] = "Pause";
40
+ VideoStatus[VideoStatus["End"] = 3] = "End";
41
+ })(VideoStatus || (VideoStatus = {}));
42
+ export var VideoPlayer = function (props) {
43
+ var playUrl = props.playUrl, _a = props.autoPlay, autoPlay = _a === void 0 ? true : _a, playEvent = props.playEvent, elementClass = props.elementClass, _b = props.durations, durations = _b === void 0 ? { hideSliderDuration: 3000 } : _b, sliderBG = props.sliderBG;
44
+ var refVideo = createRef();
45
+ var hideSliderDuration = 1000;
46
+ var _c = useState(VideoStatus.Loading), videoStatus = _c[0], setVideoStatus = _c[1];
47
+ var _d = useState(0), currentTime = _d[0], setCurrentTime = _d[1];
48
+ var _e = useState(0), totalTime = _e[0], setTotalTime = _e[1];
49
+ var _f = useState(false), showSlider = _f[0], setShowSlider = _f[1];
50
+ var sliderTimmer = useRef(null);
51
+ var updateInfoTimmer = useRef(null);
52
+ var updatePlayTime = function () {
53
+ console.log('updatePlayTime-----------------pp1', videoStatus);
54
+ console.log('updatePlayTime-----------------pp2', refVideo.current.currentTime);
55
+ console.log('updatePlayTime-----------------pp3', refVideo.current.duration);
56
+ if (videoStatus != VideoStatus.Playing)
57
+ return;
58
+ var playTime = refVideo.current.currentTime;
59
+ var currentSeconds = Math.floor(playTime / 1000 + 0.5);
60
+ var duration = refVideo.current.duration;
61
+ var totalSeconds = Math.floor(duration / 1000 + 0.5);
62
+ setCurrentTime(currentSeconds);
63
+ setTotalTime(totalSeconds);
64
+ console.log('updatePlayTime-----------------', 'currentSeconds:', currentSeconds, 'totalSeconds:', totalSeconds, Math.floor((currentTime / totalTime) * 100 + 0.5));
65
+ };
66
+ //用于更新函数环境
67
+ var updatePlayTimeRef = useRef(updatePlayTime);
68
+ useEffect(function () {
69
+ updatePlayTimeRef.current = updatePlayTime;
70
+ });
71
+ useEffect(function () {
72
+ updatePlayTimeRef.current = updatePlayTime;
73
+ updateInfoTimmer.current = setInterval(function () {
74
+ updatePlayTimeRef.current();
75
+ }, 1000);
76
+ return function () {
77
+ clearInterval(sliderTimmer.current);
78
+ };
79
+ }, []);
80
+ // 开始拖就长显Bar
81
+ var onSliderDragStart = function () {
82
+ console.log('onDragStart-----------------');
83
+ clearTimeout(sliderTimmer.current);
84
+ refVideo.current.pause();
85
+ };
86
+ var onSliderDrag = function (value) {
87
+ console.warn('value: ========================', value);
88
+ var totlaTime = (value / 100) * refVideo.current.duration;
89
+ var playSeconds = Math.floor(totlaTime / 1000 + 0.5);
90
+ setCurrentTime(playSeconds);
91
+ };
92
+ // 结束拖就3秒隐藏Bar
93
+ var onSliderDragEnd = function () {
94
+ console.warn('onDragEnd-----------------');
95
+ clearTimeout(sliderTimmer.current);
96
+ sliderTimmer.current = setTimeout(function () {
97
+ setShowSlider(false);
98
+ }, durations.hideSliderDuration);
99
+ refVideo.current.play();
100
+ };
101
+ var onplaying = function () {
102
+ // 加载第一帧画面
103
+ console.warn('-----------onplaying');
104
+ setVideoStatus(VideoStatus.Playing);
105
+ playEvent.onPlay && playEvent.onPlay();
106
+ clearInterval(updateInfoTimmer.current);
107
+ updateInfoTimmer.current = setInterval(function () {
108
+ updatePlayTimeRef.current();
109
+ }, 1000);
110
+ };
111
+ var onerror = function (error) {
112
+ console.error('----------onerror', JSON.stringify(error));
113
+ // 播放错误,比如给一个无法播放的url
114
+ };
115
+ var onpause = function () {
116
+ console.warn('-----------onpause');
117
+ setVideoStatus(VideoStatus.Pause);
118
+ };
119
+ var onended = function () {
120
+ // 视频播放结束
121
+ console.warn('-----------onended');
122
+ setVideoStatus(VideoStatus.End);
123
+ clearInterval(updateInfoTimmer.current);
124
+ setCurrentTime(0);
125
+ clearTimeout(sliderTimmer.current);
126
+ setShowSlider(true);
127
+ playEvent.onEnded && playEvent.onEnded();
128
+ };
129
+ var updateSliderHideTimmer = function () {
130
+ clearTimeout(sliderTimmer.current);
131
+ sliderTimmer.current = setTimeout(function () {
132
+ setShowSlider(false);
133
+ }, durations.hideSliderDuration);
134
+ };
135
+ var onScreenClick = function () {
136
+ clearTimeout(sliderTimmer.current);
137
+ if (showSlider) {
138
+ setShowSlider(false);
139
+ }
140
+ else {
141
+ setShowSlider(true);
142
+ updateSliderHideTimmer();
143
+ }
144
+ };
145
+ var onIconClick = function () {
146
+ switchPlayState();
147
+ };
148
+ var onPause = function () {
149
+ console.warn('onPause');
150
+ setVideoStatus(VideoStatus.Pause);
151
+ playEvent.onPause && playEvent.onPause();
152
+ };
153
+ var onFirstFrame = function () {
154
+ console.warn('onFirstFrame');
155
+ playEvent.onFirstFrame && playEvent.onFirstFrame();
156
+ };
157
+ var switchPlayState = function () {
158
+ console.log('switchPlayState ', videoStatus);
159
+ if (videoStatus == VideoStatus.Playing) {
160
+ refVideo.current.pause();
161
+ }
162
+ else if (videoStatus == VideoStatus.Pause) {
163
+ refVideo.current.play();
164
+ setShowSlider(false);
165
+ clearInterval(sliderTimmer.current);
166
+ }
167
+ else if (videoStatus == VideoStatus.End) {
168
+ refVideo.current.load();
169
+ }
170
+ };
171
+ console.log('currentTime', currentTime, 'totalTime', totalTime);
172
+ return (h("div", { style: {
173
+ width: '100%',
174
+ height: '100%',
175
+ position: 'absolute',
176
+ backgroundColor: 'rgba(0, 0, 0,1)',
177
+ } },
178
+ h("video", { ref: refVideo, src: playUrl, "object-fit": "no", autoPlay: autoPlay, style: { width: '100%', height: '100%' }, onPlaying: onplaying, onPlay: onplaying, onError: onerror, onEnded: onended, onPause: onpause, onLoadStart: function () {
179
+ console.warn('onloadstart');
180
+ }, onLoadedData: function () {
181
+ console.warn('onloadeddata');
182
+ }, onCanPlay: onplaying,
183
+ //@ts-ignore
184
+ onfirstframe: onFirstFrame }),
185
+ h("div", { style: screenClickerStyle, onClick: function (e) {
186
+ console.log('screenClickerStyle click');
187
+ e.stopPropagation();
188
+ onScreenClick();
189
+ } }, showSlider ? (h("div", { className: videoStatus == VideoStatus.Playing
190
+ ? elementClass.pauseIcon
191
+ : videoStatus == VideoStatus.Pause
192
+ ? elementClass.playIcon
193
+ : elementClass.reloadIcon, onClick: function (e) {
194
+ e.stopPropagation();
195
+ onIconClick();
196
+ } })) : null),
197
+ showSlider ? (h("div", { style: {
198
+ width: '100%',
199
+ height: '15px',
200
+ fontSize: '18px',
201
+ color: '#FFFFFF',
202
+ flexDirection: 'row',
203
+ justifyContent: 'spaceAround',
204
+ alignItems: 'center',
205
+ position: 'absolute',
206
+ bottom: '10px',
207
+ margin: '10px',
208
+ marginBottom: '30px',
209
+ } },
210
+ h("text", null, FormatSecondCountDownTime(currentTime)),
211
+ h("div", { style: { marginRight: '30px', marginLeft: '30px' } },
212
+ h(Slider, __assign({}, progressData, { outerBg: sliderBG.outerBG || '', innerBg: sliderBG.innerBG || '', dotBg: sliderBG.dotBG || '', onDrag: onSliderDrag, onDragEnd: onSliderDragEnd, onDragStart: onSliderDragStart, discrete: totalTime > 0 ? Math.floor((currentTime / totalTime) * 100 + 0.5) : 0 }))),
213
+ h("text", null, FormatSecondCountDownTime(totalTime)))) : null));
214
+ };
215
+ var progressData = {
216
+ percent: 0,
217
+ wrapperHeight: 15,
218
+ wrapperWidth: window.innerWidth - 180,
219
+ height: 3,
220
+ dotWidth: 12,
221
+ dotHeight: 12,
222
+ dotWrapperWidth: 42,
223
+ dotWrapperHeight: 42,
224
+ isDiscrete: true,
225
+ maxDiscrete: 100,
226
+ outerBg: '',
227
+ innerBg: '',
228
+ dotBg: '',
229
+ onDragStart: null,
230
+ onDrag: null,
231
+ onDragEnd: null,
232
+ };
233
+ var FormatSecondCountDownTime = function (seconds) {
234
+ var minutes = Math.floor(seconds / 60);
235
+ var remainingSeconds = seconds % 60;
236
+ var formattedMinutes = minutes < 10 ? "0".concat(minutes) : "".concat(minutes);
237
+ var formattedSeconds = remainingSeconds < 10 ? "0".concat(remainingSeconds) : "".concat(remainingSeconds);
238
+ return "".concat(formattedMinutes, ":").concat(formattedSeconds);
239
+ };
@@ -8,10 +8,10 @@ export declare namespace assetCache {
8
8
  * @param force 是否强制缓存,如果为true,会强制重新下载并覆盖本地缓存
9
9
  * @returns 返回本地缓存文件路径
10
10
  */
11
- const cache: (url: string, force?: boolean) => Promise<string>;
11
+ const cache: (url: string, force?: boolean, retryTimes?: number) => Promise<string>;
12
12
  /**
13
13
  * 返回url在本地的缓存文件路径,无缓存时返回空字符串
14
14
  */
15
15
  const getAssetPath: (url: string) => string;
16
- const download: (url: string, responseType: 'arraybuffer' | 'json' | 'text') => Promise<string>;
16
+ const download: (url: string, responseType: 'arraybuffer' | 'json' | 'text', retryTimes?: number) => Promise<string>;
17
17
  }
@@ -54,51 +54,66 @@ export var assetCache;
54
54
  * @param force 是否强制缓存,如果为true,会强制重新下载并覆盖本地缓存
55
55
  * @returns 返回本地缓存文件路径
56
56
  */
57
- assetCache.cache = function (url, force) { return __awaiter(_this, void 0, void 0, function () {
58
- var _this = this;
59
- return __generator(this, function (_a) {
60
- console.log('cacheAsset---', url);
61
- return [2 /*return*/, new Promise(function (resolve, reject) {
62
- if (!isJssdkEnv()) {
63
- console.log('非jssdk环境');
64
- reject();
65
- return;
66
- }
67
- var lib = LibMgr.getInstance().getMainLib();
68
- var localPath = getLocalPath(url);
69
- if (!force) {
70
- if (lib.fileExists(localPath)) {
71
- console.log('cacheAsset file exist', localPath);
72
- resolve(localPath);
57
+ assetCache.cache = function (url, force, retryTimes) {
58
+ if (retryTimes === void 0) { retryTimes = 3; }
59
+ return __awaiter(_this, void 0, void 0, function () {
60
+ var _this = this;
61
+ return __generator(this, function (_a) {
62
+ console.log('cacheAsset---', url);
63
+ return [2 /*return*/, new Promise(function (resolve, reject) {
64
+ if (!isJssdkEnv()) {
65
+ console.log('非jssdk环境');
66
+ reject();
73
67
  return;
74
68
  }
75
- }
76
- var xhr = new XMLHttpRequest();
77
- xhr.open('GET', url, true);
78
- xhr.responseType = 'arraybuffer';
79
- xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
80
- var buf;
81
- return __generator(this, function (_a) {
82
- if (xhr.status === 200) {
83
- buf = Buffer.from(xhr.response, 'binary').buffer;
84
- lib.saveToFile(localPath, buf);
69
+ var lib = LibMgr.getInstance().getMainLib();
70
+ var localPath = getLocalPath(url);
71
+ if (!force) {
72
+ if (lib.fileExists(localPath)) {
73
+ console.log('cacheAsset file exist', localPath);
85
74
  resolve(localPath);
75
+ return;
76
+ }
77
+ }
78
+ var xhr = new XMLHttpRequest();
79
+ xhr.open('GET', url, true);
80
+ xhr.responseType = 'arraybuffer';
81
+ xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
82
+ var buf;
83
+ return __generator(this, function (_a) {
84
+ if (xhr.status === 200) {
85
+ buf = Buffer.from(xhr.response, 'binary').buffer;
86
+ lib.saveToFile(localPath, buf);
87
+ resolve(localPath);
88
+ }
89
+ else {
90
+ console.warn('cacheAsset xhr statue!=200', xhr.status);
91
+ if (retryTimes > 0) {
92
+ console.log('retry cacheAsset', retryTimes);
93
+ assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
94
+ }
95
+ else {
96
+ reject();
97
+ }
98
+ }
99
+ return [2 /*return*/];
100
+ });
101
+ }); };
102
+ xhr.onerror = function () {
103
+ console.warn('cacheAsset XHR error', xhr.status);
104
+ if (retryTimes > 0) {
105
+ console.log('retry cacheAsset', retryTimes);
106
+ assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
86
107
  }
87
108
  else {
88
- console.warn('cacheAsset xhr statue!=200', xhr.status);
89
109
  reject();
90
110
  }
91
- return [2 /*return*/];
92
- });
93
- }); };
94
- xhr.onerror = function () {
95
- console.warn('cacheAsset XHR error', xhr.status);
96
- reject();
97
- };
98
- xhr.send();
99
- })];
111
+ };
112
+ xhr.send();
113
+ })];
114
+ });
100
115
  });
101
- }); };
116
+ };
102
117
  /**
103
118
  * 返回url在本地的缓存文件路径,无缓存时返回空字符串
104
119
  */
@@ -115,7 +130,8 @@ export var assetCache;
115
130
  }
116
131
  return localPath;
117
132
  };
118
- assetCache.download = function (url, responseType) {
133
+ assetCache.download = function (url, responseType, retryTimes) {
134
+ if (retryTimes === void 0) { retryTimes = 3; }
119
135
  console.log('download---', url);
120
136
  return new Promise(function (resolve, reject) {
121
137
  var xhr = new XMLHttpRequest();
@@ -128,14 +144,26 @@ export var assetCache;
128
144
  }
129
145
  else {
130
146
  console.warn('cacheAsset xhr statue!=200', xhr.status);
131
- reject();
147
+ if (retryTimes > 0) {
148
+ console.log('retry cacheAsset', retryTimes);
149
+ assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
150
+ }
151
+ else {
152
+ reject();
153
+ }
132
154
  }
133
155
  return [2 /*return*/];
134
156
  });
135
157
  }); };
136
158
  xhr.onerror = function () {
137
159
  console.warn('cacheAsset XHR error', xhr.status);
138
- reject();
160
+ if (retryTimes > 0) {
161
+ console.log('retry cacheAsset', retryTimes);
162
+ assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
163
+ }
164
+ else {
165
+ reject();
166
+ }
139
167
  };
140
168
  xhr.send();
141
169
  });