@conecli/cone-render 0.10.1-beta.3 → 0.10.1-beta.5

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.
Files changed (56) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/index.h5.ts +1 -1
  4. package/dist/common/index.weapp.ts +1 -1
  5. package/dist/common/sgmCustomCode.ts +1 -1
  6. package/dist/components/ErrorBoundary.tsx +1 -1
  7. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  8. package/dist/components/base/CustomVideo/index.tsx +1 -1
  9. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  10. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  11. package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
  12. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  13. package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
  14. package/dist/components/base/LazyLoadImage/index.h5.module.scss +3 -0
  15. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  16. package/dist/components/base/MobileCommonHeader/index.module.scss +8 -0
  17. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  18. package/dist/components/base/NetworkDataError/index.module.scss +3 -0
  19. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  20. package/dist/components/decorate/DecorateFloorModule/index.module.scss +11 -0
  21. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  22. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  23. package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
  24. package/dist/components/floorItem.tsx +1 -1
  25. package/dist/components/remoteFloorItem.tsx +1 -1
  26. package/dist/interface/common.ts +1 -1
  27. package/dist/interface/component.ts +1 -1
  28. package/dist/interface/jumpEventReport.ts +1 -1
  29. package/dist/interface/service.ts +1 -1
  30. package/dist/jumpEventReport/base.ts +1 -1
  31. package/dist/jumpEventReport/const.ts +1 -1
  32. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  33. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  34. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  35. package/dist/jumpEventReport/web.base.ts +1 -1
  36. package/dist/jumpEventReport/web.jd.ts +1 -1
  37. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  38. package/dist/modules/ContainerFloorList/index.h5.module.scss +1 -0
  39. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  40. package/dist/open/api/device.ts +1 -1
  41. package/dist/open/api/request.ts +1 -1
  42. package/dist/open/api/shopMember.ts +1 -1
  43. package/dist/open/api/util.ts +1 -1
  44. package/dist/open/components/index.ts +1 -1
  45. package/dist/sass/app.h5.scss +5 -0
  46. package/dist/sass/base.scss +45 -0
  47. package/dist/service/requestServer.ts +1 -1
  48. package/dist/utils/connectNativeJsBridge.ts +1 -1
  49. package/dist/utils/h5Utils.ts +1 -1
  50. package/dist/utils/index.h5.ts +1 -1
  51. package/dist/utils/index.ts +1 -1
  52. package/dist/utils/index.weapp.ts +1 -1
  53. package/dist/utils/sgmCodeUtils.ts +1 -1
  54. package/dist/utils/taroRenderUtil.ts +1 -1
  55. package/dist/utils/utils.ts +1 -1
  56. package/package.json +24 -23
@@ -1 +1 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react'
2
1
  (props: ComponentInterFace.CustomVideoProps, ref: any) => {
3
2
  const {
4
3
  isSystemVideo,
5
4
  style,
6
5
  videoStyle,
7
6
  src,
8
7
  width,
9
8
  height,
10
9
  controls,
11
10
  id,
12
11
  poster,
13
12
  autoplay: isvAutoplay,
14
13
  loop,
15
14
  showMuteBtn: isvShowMuteBtn,
16
15
  muteButtonPostion,
17
16
  showFullscreenBtn,
18
17
  muteBtnPicSrcObj,
19
18
  muteBtnClassName,
20
19
  muteBtnStyle,
21
20
  objectFit,
22
21
  mockAutoplay,
23
22
  threshold,
24
23
  onPlayCallback,
25
24
  onPauseCallback,
26
25
  onVideoApiCall,
27
26
  inViewCallback,
28
27
  outViewCallback,
29
28
  } = props
30
29
  const {
31
30
  wifiVideoAutoPlay,
32
31
  } = global.info.sysInfo
33
32
  const isFollowAppVideoPlayStatus = global.getDynamicConfig('isFollowAppVideoPlayStatus')
34
33
  let showMuteBtn = isvShowMuteBtn
35
34
  let autoplay = isvAutoplay
36
35
  if (isSystemVideo) {
37
36
  showMuteBtn = false
38
37
  autoplay = wifiVideoAutoPlay
39
38
  } else {
40
39
  if (isvAutoplay && isFollowAppVideoPlayStatus) {
41
40
  autoplay = wifiVideoAutoPlay
42
41
  }
43
42
  }
44
43
  console.log(
45
44
  'CustomVideo',
46
45
  'isSystemVideo:',
47
46
  isSystemVideo,
48
47
  'wifiVideoAutoPlay:',
49
48
  wifiVideoAutoPlay,
50
49
  ',isvAutoplay:',
51
50
  isvAutoplay,
52
51
  ',isFollowAppVideoPlayStatus:',
53
52
  isFollowAppVideoPlayStatus,
54
53
  ',autoplay:',
55
54
  autoplay,
56
55
  ',id:',
57
56
  id,
58
57
  )
59
58
  const [videoMutedState, setVideoMutedState] = useState(MUTED)
60
59
  const lastPlayStatusRef = useRef(-1)
61
60
  const manualPauseStateRef = useRef(false)
62
61
  const initPlayStatusRef = useRef(false)
63
62
  const isInViewStateRef = useRef(false)
64
63
  const disposeRef = useRef<Function | null>()
65
64
  ref === null && (ref = useRef<HTMLVideoElement | null>())
66
65
 
67
66
  const playVideo = useCallback(() => {
68
67
  if (ref && ref.current) {
69
68
  console.log(`CustomVideo id:${id} 开始播放视频`)
70
69
  const result = ref.current.play()
71
70
  result &&
72
71
  result
73
72
  .then(() => {
74
73
  console.log(`播放视频成功`)
75
74
  })
76
75
  .catch(e => {
77
76
  console.log('playVideo Error:', e.message)
78
77
  })
79
78
  }
80
79
  }, [])
81
80
 
82
81
  const pauseVideo = useCallback(() => {
83
82
  if (ref && ref.current) {
84
83
  console.log(`CustomVideo id:${id} 暂停视频`)
85
84
  ref.current.pause()
86
85
  }
87
86
  }, [])
88
87
 
89
88
  useEffect(() => {
90
89
  if (!isH5 || !ref.current) return
91
90
  if (autoplay && mockAutoplay) {
92
91
 
93
92
  const callInitAutoplay = () => {
94
93
  console.log(
95
94
  `CustomVideo id:${id} 触发初始化autoplay callInitAutoplay`,
96
95
  )
97
96
  if (
98
97
  autoplay &&
99
98
  mockAutoplay &&
100
99
  !initPlayStatusRef.current &&
101
100
  isInViewStateRef.current &&
102
101
  ref.current.paused
103
102
  ) {
104
103
  playVideo()
105
104
  }
106
105
  }
107
106
  const onWeixinJSBridgeReady = e => {
108
107
  callInitAutoplay()
109
108
  }
110
109
  const onTouchstart = e => {
111
110
  callInitAutoplay()
112
111
  }
113
112
  const onScroll = e => {
114
113
  callInitAutoplay()
115
114
  }
116
115
  const onPlay = e => {
117
116
  if (!initPlayStatusRef.current) {
118
117
  const dispose = disposeRef.current
119
118
  dispose && dispose()
120
119
  disposeRef.current = null
121
120
  }
122
121
  initPlayStatusRef.current = true
123
122
  }
124
123
  document?.addEventListener('WeixinJSBridgeReady', onWeixinJSBridgeReady)
125
124
  document?.addEventListener('touchstart', onTouchstart)
126
125
  document?.addEventListener('scroll', onScroll)
127
126
  ref.current.addEventListener('play', onPlay)
128
127
  const dispose = () => {
129
128
  console.log('调用dispose')
130
129
  document?.removeEventListener(
131
130
  'WeixinJSBridgeReady',
132
131
  onWeixinJSBridgeReady,
133
132
  )
134
133
  document?.removeEventListener('touchstart', onTouchstart)
135
134
  document?.removeEventListener('scroll', onScroll)
136
135
  ref?.current?.removeEventListener('play', onPlay)
137
136
  }
138
137
  disposeRef.current = dispose
139
138
  }
140
139
  const handleVideoPlayApiCall = () => {
141
140
  if (!isH5 || !ref.current) return
142
141
  playVideo()
143
142
  manualPauseStateRef.current = false
144
143
  }
145
144
  const handleVideoPauseApiCall = () => {
146
145
  if (!isH5 || !ref.current) return
147
146
  manualPauseStateRef.current = true
148
147
  pauseVideo()
149
148
  }
150
149
 
151
150
  const handleVideoSeekApiCall = (position: number) => {
152
151
  if (!isH5 || !ref.current) return
153
152
  if (typeof position === 'undefined' || typeof position !== 'number')
154
153
  return
155
154
  ref.current.currentTime = position
156
155
  }
157
156
 
158
157
  if (onVideoApiCall) {
159
158
  onVideoApiCall({
160
159
  play: handleVideoPlayApiCall,
161
160
  pause: handleVideoPauseApiCall,
162
161
  seek: handleVideoSeekApiCall,
163
162
  })
164
163
  }
165
164
  return () => {
166
165
  const dispose = disposeRef.current
167
166
  dispose && dispose()
168
167
  disposeRef.current = null
169
168
  }
170
169
  }, [])
171
170
 
172
171
  const handleMuted = useCallback(() => {
173
172
  if (!isH5 || !ref.current) return
174
173
  const handleMutedState = ref.current.muted
175
174
  if (handleMutedState === true) {
176
175
  ref.current.muted = false
177
176
  setVideoMutedState(false)
178
177
  } else {
179
178
  ref.current.muted = true
180
179
  setVideoMutedState(true)
181
180
  }
182
181
  }, [videoMutedState])
183
182
 
184
183
  const handleVideoInViewCallback = useCallback(() => {
185
184
  if (!isH5 || !ref.current) return
186
185
  console.log(
187
186
  `
188
187
  )} CustomVideo handleVideoInViewCallback id:${id} 进入可视区域 lastPlayStatusRef.current:${lastPlayStatusRef.current},paused:${ref.current.paused}`,
189
188
  )
190
189
  isInViewStateRef.current = true
191
190
  if (
192
191
  autoplay &&
193
192
  mockAutoplay &&
194
193
  !initPlayStatusRef.current &&
195
194
  ref.current.paused
196
195
  ) {
197
196
  console.log(`CustomVideo id:${id} 首次进入可视区域`)
198
197
  playVideo()
199
198
  } else if (lastPlayStatusRef.current === 1 && ref.current.paused) {
200
199
  console.log(`CustomVideo id:${id} 非首次进入可视区域`)
201
200
  playVideo()
202
201
  }
203
202
  typeof inViewCallback === 'function' && inViewCallback()
204
203
  }, [])
205
204
 
206
205
  const handleVideoOutViewCallback = useCallback(() => {
207
206
  if (!isH5 || !ref.current) return
208
207
  isInViewStateRef.current = false
209
208
  console.log(
210
209
  `CustomVideo handleVideoOutViewCallback id:${id} 不在可视区域,视频暂停,lastPlayStatusRef:${lastPlayStatusRef.current}`,
211
210
  )
212
211
  pauseVideo()
213
212
  typeof outViewCallback === 'function' && outViewCallback()
214
213
  }, [])
215
214
 
216
215
  const getVideoWidthAndHeightStyle = () => {
217
216
  const style = {}
218
217
  width && (style['width'] = width)
219
218
  height && (style['height'] = height)
220
219
  return style
221
220
  }
222
221
 
223
222
  const getMuteBtnBackgroundImageStyle = useCallback(() => {
224
223
  const isMutedPicSrc = muteBtnPicSrcObj?.IS_MUTED
225
224
  const notMutedPicSrc = muteBtnPicSrcObj?.NOT_MUTED
226
225
  const finalIsMutedPicSrc =
227
226
  typeof isMutedPicSrc !== 'undefined' && isMutedPicSrc !== ''
228
227
  ? isMutedPicSrc
229
228
  : DEFAULT_MUTE_BTN_PIC.IS_MUTED
230
229
  const finalNotMutedPicSrc =
231
230
  typeof notMutedPicSrc !== 'undefined' && notMutedPicSrc !== ''
232
231
  ? notMutedPicSrc
233
232
  : DEFAULT_MUTE_BTN_PIC.NOT_MUTED
234
233
  return {
235
234
  backgroundImage: `url(${
236
235
  videoMutedState ? finalIsMutedPicSrc : finalNotMutedPicSrc
237
236
  })`,
238
237
  }
239
238
  }, [videoMutedState])
240
239
  return src ? (
241
240
  <InOrOutViewObserver
242
241
  inViewCallback={handleVideoInViewCallback}
243
242
  outViewCallback={handleVideoOutViewCallback}
244
243
  threshold={threshold}
245
244
  >
246
245
  {isH5 ? (
247
246
  <View
248
247
  className={customVideoStyle['d-video-wrap']}
249
248
  style={{ ...style, ...getVideoWidthAndHeightStyle() }}
250
249
  >
251
250
  <video
252
251
  style={{ ...videoStyle }}
253
252
  className={classNames(customVideoStyle['d-video-play'], {
254
253
  'd-video-forbid-fullscreen-button': isSystemVideo,
255
254
  })}
256
255
  id={id}
257
256
  data-jd-video={true}
258
257
  src={src}
259
258
  controls={controls}
260
259
  poster={poster ? addHttps(poster) : ''}
261
260
  ref={ref}
262
261
  loop={loop}
263
262
  autoPlay={autoplay}
264
263
  muted={MUTED}
265
264
  x5-playsinline="true"
266
265
  playsInline
267
266
  webkit-playsinline="true"
268
267
  controlsList={
269
268
  isH5AndJdShopView
270
269
  ? 'nodownload nofullscreen noremoteplayback'
271
270
  : ''
272
271
  }
273
272
  onPlay={e => {
274
273
  lastPlayStatusRef.current = 1
275
274
  onPlayCallback && onPlayCallback(e)
276
275
  }}
277
276
  onPause={e => {
278
277
  if (isInViewStateRef.current) {
279
278
  lastPlayStatusRef.current = 0
280
279
  }
281
280
  onPauseCallback && onPauseCallback(e)
282
281
  }}
283
282
  />
284
283
  {!controls && showMuteBtn && (
285
284
  <View
286
285
  className={classNames(
287
286
  customVideoStyle['d-video-mute-btn'],
288
287
  customVideoStyle[`d-mute-btn-${muteButtonPostion}`],
289
288
  `${muteBtnClassName}`,
290
289
  )}
291
290
  style={{ ...getMuteBtnBackgroundImageStyle(), ...muteBtnStyle }}
292
291
  onClick={handleMuted}
293
292
  ></View>
294
293
  )}
295
294
  </View>
296
295
  ) : (
297
296
  <Video
298
297
  style={{ ...videoStyle }}
299
298
  ref={ref}
300
299
  className={customVideoStyle['d-video-play']}
301
300
  src={src}
302
301
  id={id}
303
302
  controls={controls}
304
303
  poster={poster ? addHttps(poster) : ''}
305
304
  loop={loop}
306
305
  data-jd-video={true}
307
306
  autoplay={autoplay}
308
307
  muted={MUTED}
309
308
  showMuteBtn={showMuteBtn}
310
309
  showFullscreenBtn={showFullscreenBtn}
311
310
  objectFit={objectFit}
312
311
  onPlay={e => {
313
312
  lastPlayStatusRef.current = 1
314
313
  onPlayCallback && onPlayCallback(e)
315
314
  }}
316
315
  onPause={e => {
317
316
  if (isInViewStateRef.current) {
318
317
  lastPlayStatusRef.current = 0
319
318
  }
320
319
  onPauseCallback && onPauseCallback(e)
321
320
  }}
322
321
  />
323
322
  )}
324
323
  </InOrOutViewObserver>
325
324
  ) : null
326
325
  },
327
326
  return process.env.BUILD_TYPE !== BUILD_TYPE.DECORATE
328
327
  isSystemVideo: false,
329
328
  id: '',
330
329
  style: {},
331
330
  videoStyle: {},
332
331
  className: '',
333
332
  src: '',
334
333
  width: '100%',
335
334
  height: '100%',
336
335
  controls: false,
337
336
  poster: '',
338
337
  autoplay: true,
339
338
  mockAutoplay: getDefaultMockAutoplay(),
340
339
  loop: true,
341
340
  showMuteBtn: true,
342
341
  muteButtonPostion: 'topLeft',
343
342
  muteBtnPicSrcObj: DEFAULT_MUTE_BTN_PIC,
344
343
  muteBtnClassName: '',
345
344
  muteBtnStyle: {},
346
345
  showFullscreenBtn: false,
347
346
  objectFit: 'cover',
348
347
  threshold: 0.6,
348
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
349
349
  (props: ComponentInterFace.CustomVideoProps, ref: any) => {
350
350
  const {
351
351
  isSystemVideo,
352
352
  style,
353
353
  videoStyle,
354
354
  src,
355
355
  width,
356
356
  height,
357
357
  controls,
358
358
  id,
359
359
  poster,
360
360
  autoplay: isvAutoplay,
361
361
  loop,
362
362
  showMuteBtn: isvShowMuteBtn,
363
363
  muteButtonPostion,
364
364
  showFullscreenBtn,
365
365
  muteBtnPicSrcObj,
366
366
  muteBtnClassName,
367
367
  muteBtnStyle,
368
368
  objectFit,
369
369
  mockAutoplay,
370
370
  threshold,
371
371
  onPlayCallback,
372
372
  onPauseCallback,
373
373
  onVideoApiCall,
374
374
  inViewCallback,
375
375
  outViewCallback,
376
376
  } = props
377
377
  const { wifiVideoAutoPlay } = global.info.sysInfo
378
378
  const isFollowAppVideoPlayStatus = global.getDynamicConfig(
379
379
  'isFollowAppVideoPlayStatus',
380
380
  )
381
381
  let showMuteBtn = isvShowMuteBtn
382
382
  let autoplay = isvAutoplay
383
383
  if (isSystemVideo) {
384
384
  showMuteBtn = false
385
385
  autoplay = wifiVideoAutoPlay
386
386
  } else {
387
387
  if (isvAutoplay && isFollowAppVideoPlayStatus) {
388
388
  autoplay = wifiVideoAutoPlay
389
389
  }
390
390
  }
391
391
  console.log(
392
392
  'CustomVideo',
393
393
  'isSystemVideo:',
394
394
  isSystemVideo,
395
395
  'wifiVideoAutoPlay:',
396
396
  wifiVideoAutoPlay,
397
397
  ',isvAutoplay:',
398
398
  isvAutoplay,
399
399
  ',isFollowAppVideoPlayStatus:',
400
400
  isFollowAppVideoPlayStatus,
401
401
  ',autoplay:',
402
402
  autoplay,
403
403
  ',id:',
404
404
  id,
405
405
  )
406
406
  const [videoMutedState, setVideoMutedState] = useState(MUTED)
407
407
  const lastPlayStatusRef = useRef(-1)
408
408
  const manualPauseStateRef = useRef(false)
409
409
  const initPlayStatusRef = useRef(false)
410
410
  const isInViewStateRef = useRef(false)
411
411
  const disposeRef = useRef<Function | null>()
412
412
  ref === null && (ref = useRef<HTMLVideoElement | null>())
413
413
 
414
414
  const playVideo = useCallback(() => {
415
415
  if (ref && ref.current) {
416
416
  console.log(`CustomVideo id:${id} 开始播放视频`)
417
417
  const result = ref.current.play()
418
418
  result &&
419
419
  result
420
420
  .then(() => {
421
421
  console.log(`播放视频成功`)
422
422
  })
423
423
  .catch(e => {
424
424
  console.log('playVideo Error:', e.message)
425
425
  })
426
426
  }
427
427
  }, [])
428
428
 
429
429
  const pauseVideo = useCallback(() => {
430
430
  if (ref && ref.current) {
431
431
  console.log(`CustomVideo id:${id} 暂停视频`)
432
432
  ref.current.pause()
433
433
  }
434
434
  }, [])
435
435
 
436
436
  useEffect(() => {
437
437
  if (!isH5 || !ref.current) return
438
438
  if (autoplay && mockAutoplay) {
439
439
 
440
440
  const callInitAutoplay = () => {
441
441
  console.log(
442
442
  `CustomVideo id:${id} 触发初始化autoplay callInitAutoplay`,
443
443
  )
444
444
  if (
445
445
  autoplay &&
446
446
  mockAutoplay &&
447
447
  !initPlayStatusRef.current &&
448
448
  isInViewStateRef.current &&
449
449
  ref.current.paused
450
450
  ) {
451
451
  playVideo()
452
452
  }
453
453
  }
454
454
  const onWeixinJSBridgeReady = e => {
455
455
  callInitAutoplay()
456
456
  }
457
457
  const onTouchstart = e => {
458
458
  callInitAutoplay()
459
459
  }
460
460
  const onScroll = e => {
461
461
  callInitAutoplay()
462
462
  }
463
463
  const onPlay = e => {
464
464
  if (!initPlayStatusRef.current) {
465
465
  const dispose = disposeRef.current
466
466
  dispose && dispose()
467
467
  disposeRef.current = null
468
468
  }
469
469
  initPlayStatusRef.current = true
470
470
  }
471
471
  document?.addEventListener('WeixinJSBridgeReady', onWeixinJSBridgeReady)
472
472
  document?.addEventListener('touchstart', onTouchstart)
473
473
  document?.addEventListener('scroll', onScroll)
474
474
  ref.current.addEventListener('play', onPlay)
475
475
  const dispose = () => {
476
476
  console.log('调用dispose')
477
477
  document?.removeEventListener(
478
478
  'WeixinJSBridgeReady',
479
479
  onWeixinJSBridgeReady,
480
480
  )
481
481
  document?.removeEventListener('touchstart', onTouchstart)
482
482
  document?.removeEventListener('scroll', onScroll)
483
483
  ref?.current?.removeEventListener('play', onPlay)
484
484
  }
485
485
  disposeRef.current = dispose
486
486
  }
487
487
  const handleVideoPlayApiCall = () => {
488
488
  if (!isH5 || !ref.current) return
489
489
  playVideo()
490
490
  manualPauseStateRef.current = false
491
491
  }
492
492
  const handleVideoPauseApiCall = () => {
493
493
  if (!isH5 || !ref.current) return
494
494
  manualPauseStateRef.current = true
495
495
  pauseVideo()
496
496
  }
497
497
 
498
498
  const handleVideoSeekApiCall = (position: number) => {
499
499
  if (!isH5 || !ref.current) return
500
500
  if (typeof position === 'undefined' || typeof position !== 'number')
501
501
  return
502
502
  ref.current.currentTime = position
503
503
  }
504
504
 
505
505
  if (onVideoApiCall) {
506
506
  onVideoApiCall({
507
507
  play: handleVideoPlayApiCall,
508
508
  pause: handleVideoPauseApiCall,
509
509
  seek: handleVideoSeekApiCall,
510
510
  })
511
511
  }
512
512
  return () => {
513
513
  const dispose = disposeRef.current
514
514
  dispose && dispose()
515
515
  disposeRef.current = null
516
516
  }
517
517
  }, [])
518
518
 
519
519
  const handleMuted = useCallback(() => {
520
520
  if (!isH5 || !ref.current) return
521
521
  const handleMutedState = ref.current.muted
522
522
  if (handleMutedState === true) {
523
523
  ref.current.muted = false
524
524
  setVideoMutedState(false)
525
525
  } else {
526
526
  ref.current.muted = true
527
527
  setVideoMutedState(true)
528
528
  }
529
529
  }, [videoMutedState])
530
530
 
531
531
  const handleVideoInViewCallback = useCallback(() => {
532
532
  if (!isH5 || !ref.current) return
533
533
  console.log(
534
534
  `
535
535
  )} CustomVideo handleVideoInViewCallback id:${id} 进入可视区域 lastPlayStatusRef.current:${lastPlayStatusRef.current},paused:${ref.current.paused}`,
536
536
  )
537
537
  isInViewStateRef.current = true
538
538
  if (
539
539
  autoplay &&
540
540
  ((mockAutoplay && !initPlayStatusRef.current) ||
541
541
  lastPlayStatusRef.current === -1) &&
542
542
  ref.current.paused
543
543
  ) {
544
544
  console.log(`CustomVideo id:${id} 首次进入可视区域`)
545
545
  playVideo()
546
546
  } else if (lastPlayStatusRef.current === 1 && ref.current.paused) {
547
547
  console.log(`CustomVideo id:${id} 非首次进入可视区域`)
548
548
  playVideo()
549
549
  }
550
550
  typeof inViewCallback === 'function' && inViewCallback()
551
551
  }, [])
552
552
 
553
553
  const handleVideoOutViewCallback = useCallback(() => {
554
554
  if (!isH5 || !ref.current) return
555
555
  isInViewStateRef.current = false
556
556
  console.log(
557
557
  `CustomVideo handleVideoOutViewCallback id:${id} 不在可视区域,视频暂停,lastPlayStatusRef:${lastPlayStatusRef.current}`,
558
558
  )
559
559
  pauseVideo()
560
560
  typeof outViewCallback === 'function' && outViewCallback()
561
561
  }, [])
562
562
 
563
563
  const getVideoWidthAndHeightStyle = () => {
564
564
  const style = {}
565
565
  width && (style['width'] = width)
566
566
  height && (style['height'] = height)
567
567
  return style
568
568
  }
569
569
 
570
570
  const getMuteBtnBackgroundImageStyle = useCallback(() => {
571
571
  const isMutedPicSrc = muteBtnPicSrcObj?.IS_MUTED
572
572
  const notMutedPicSrc = muteBtnPicSrcObj?.NOT_MUTED
573
573
  const finalIsMutedPicSrc =
574
574
  typeof isMutedPicSrc !== 'undefined' && isMutedPicSrc !== ''
575
575
  ? isMutedPicSrc
576
576
  : DEFAULT_MUTE_BTN_PIC.IS_MUTED
577
577
  const finalNotMutedPicSrc =
578
578
  typeof notMutedPicSrc !== 'undefined' && notMutedPicSrc !== ''
579
579
  ? notMutedPicSrc
580
580
  : DEFAULT_MUTE_BTN_PIC.NOT_MUTED
581
581
  return {
582
582
  backgroundImage: `url(${
583
583
  videoMutedState ? finalIsMutedPicSrc : finalNotMutedPicSrc
584
584
  })`,
585
585
  }
586
586
  }, [videoMutedState])
587
587
  return src ? (
588
588
  <InOrOutViewObserver
589
589
  inViewCallback={handleVideoInViewCallback}
590
590
  outViewCallback={handleVideoOutViewCallback}
591
591
  threshold={threshold}
592
592
  >
593
593
  {isH5 ? (
594
594
  <View
595
595
  className={customVideoStyle['d-video-wrap']}
596
596
  style={{ ...style, ...getVideoWidthAndHeightStyle() }}
597
597
  >
598
598
  <video
599
599
  style={{ ...videoStyle }}
600
600
  className={classNames(customVideoStyle['d-video-play'], {
601
601
  'd-video-forbid-fullscreen-button': isSystemVideo,
602
602
  })}
603
603
  id={id}
604
604
  data-jd-video={true}
605
605
  src={src}
606
606
  controls={controls}
607
607
  poster={poster ? addHttps(poster) : ''}
608
608
  ref={ref}
609
609
  loop={loop}
610
610
  autoPlay={autoplay}
611
611
  muted={MUTED}
612
612
  x5-playsinline="true"
613
613
  playsInline
614
614
  webkit-playsinline="true"
615
615
  controlsList={
616
616
  isH5AndJdShopView
617
617
  ? 'nodownload nofullscreen noremoteplayback'
618
618
  : ''
619
619
  }
620
620
  onPlay={e => {
621
621
  lastPlayStatusRef.current = 1
622
622
  onPlayCallback && onPlayCallback(e)
623
623
  }}
624
624
  onPause={e => {
625
625
  if (isInViewStateRef.current) {
626
626
  lastPlayStatusRef.current = 0
627
627
  }
628
628
  onPauseCallback && onPauseCallback(e)
629
629
  }}
630
630
  />
631
631
  {!controls && showMuteBtn && (
632
632
  <View
633
633
  className={classNames(
634
634
  customVideoStyle['d-video-mute-btn'],
635
635
  customVideoStyle[`d-mute-btn-${muteButtonPostion}`],
636
636
  `${muteBtnClassName}`,
637
637
  )}
638
638
  style={{ ...getMuteBtnBackgroundImageStyle(), ...muteBtnStyle }}
639
639
  onClick={handleMuted}
640
640
  ></View>
641
641
  )}
642
642
  </View>
643
643
  ) : (
644
644
  <Video
645
645
  style={{ ...videoStyle }}
646
646
  ref={ref}
647
647
  className={customVideoStyle['d-video-play']}
648
648
  src={src}
649
649
  id={id}
650
650
  controls={controls}
651
651
  poster={poster ? addHttps(poster) : ''}
652
652
  loop={loop}
653
653
  data-jd-video={true}
654
654
  autoplay={autoplay}
655
655
  muted={MUTED}
656
656
  showMuteBtn={showMuteBtn}
657
657
  showFullscreenBtn={showFullscreenBtn}
658
658
  objectFit={objectFit}
659
659
  onPlay={e => {
660
660
  lastPlayStatusRef.current = 1
661
661
  onPlayCallback && onPlayCallback(e)
662
662
  }}
663
663
  onPause={e => {
664
664
  if (isInViewStateRef.current) {
665
665
  lastPlayStatusRef.current = 0
666
666
  }
667
667
  onPauseCallback && onPauseCallback(e)
668
668
  }}
669
669
  />
670
670
  )}
671
671
  </InOrOutViewObserver>
672
672
  ) : null
673
673
  },
674
674
  return process.env.BUILD_TYPE !== BUILD_TYPE.DECORATE
675
675
  isSystemVideo: false,
676
676
  id: '',
677
677
  style: {},
678
678
  videoStyle: {},
679
679
  className: '',
680
680
  src: '',
681
681
  width: '100%',
682
682
  height: '100%',
683
683
  controls: false,
684
684
  poster: '',
685
685
  autoplay: true,
686
686
  mockAutoplay: getDefaultMockAutoplay(),
687
687
  loop: true,
688
688
  showMuteBtn: true,
689
689
  muteButtonPostion: 'topLeft',
690
690
  muteBtnPicSrcObj: DEFAULT_MUTE_BTN_PIC,
691
691
  muteBtnClassName: '',
692
692
  muteBtnStyle: {},
693
693
  showFullscreenBtn: false,
694
694
  objectFit: 'cover',
695
695
  threshold: 0.6,