pb-sxp-ui 1.20.45 → 1.20.47

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/dist/index.cjs CHANGED
@@ -19648,18 +19648,23 @@ const PostView = ({ children, videoRef, isVideo, onExposure, autoPlayTriggerRef,
19648
19648
  autoPlayTriggerRef.current = true;
19649
19649
  console.log('[PostView onVisible] 已设置自动播放标记');
19650
19650
  }
19651
+ // 立即更新暂停图标状态,不等待 play() Promise
19652
+ // 这样可以确保图标状态与视频播放状态同步
19653
+ if (onVideoPlay) {
19654
+ onVideoPlay();
19655
+ }
19651
19656
  videoRef.current.play().then(() => {
19652
19657
  console.log('[PostView onVisible] 视频 play() 成功');
19653
- // 触发播放回调,更新暂停图标状态
19654
- if (onVideoPlay) {
19655
- onVideoPlay();
19656
- }
19657
19658
  }).catch(err => {
19658
19659
  console.warn('[PostView] Video autoplay failed:', err);
19659
- // 播放失败时重置标记
19660
+ // 播放失败时重置标记和图标状态
19660
19661
  if (autoPlayTriggerRef) {
19661
19662
  autoPlayTriggerRef.current = false;
19662
19663
  }
19664
+ // 播放失败,恢复暂停图标
19665
+ if (onVideoPause) {
19666
+ onVideoPause();
19667
+ }
19663
19668
  });
19664
19669
  }
19665
19670
  },
@@ -20042,6 +20047,7 @@ const StructurePage = (_a) => {
20042
20047
  const videoLoadTime = React.useRef({});
20043
20048
  const videoAutoPlayReported = React.useRef(new Set()); // 追踪哪些视频已通过自动播放上报
20044
20049
  const videoPlayReportTime = React.useRef({}); // 追踪视频播放上报的时间戳,防止短时间内重复上报
20050
+ const videoLastCurrentTime = React.useRef({}); // 追踪视频的上一次播放时间,用于检测循环
20045
20051
  // 自动播放触发标记(用于区分自动播放和用户手动播放)
20046
20052
  const heroAutoPlayTrigger = React.useRef(false);
20047
20053
  const carouselAutoPlayTriggers = React.useRef({});
@@ -20318,15 +20324,6 @@ const StructurePage = (_a) => {
20318
20324
  videoAutoPlayReported.current.add(videoId);
20319
20325
  console.log('[handleVideoPlay] 标记为已通过自动播放上报');
20320
20326
  }
20321
- else {
20322
- // 如果不是自动播放,但已经通过自动播放上报过,则跳过
20323
- if (videoAutoPlayReported.current.has(videoId)) {
20324
- console.log('[handleVideoPlay] 跳过上报:已经通过自动播放上报过');
20325
- // 只记录播放时间,不上报
20326
- videoStartTime.current[videoId] = videoRef.currentTime || 0;
20327
- return;
20328
- }
20329
- }
20330
20327
  // 记录视频开始播放时间
20331
20328
  videoStartTime.current[videoId] = videoRef.currentTime || 0;
20332
20329
  // 记录本次上报时间
@@ -20352,8 +20349,48 @@ const StructurePage = (_a) => {
20352
20349
  }))
20353
20350
  });
20354
20351
  }, [bffEventReport]);
20352
+ // 视频时间更新事件处理(用于检测循环播放)
20353
+ const handleVideoTimeUpdate = React.useCallback((videoData, viewPosition, sectionIndex, videoRef) => {
20354
+ if (!videoRef || !videoRef.duration)
20355
+ return;
20356
+ const videoId = `${videoData === null || videoData === void 0 ? void 0 : videoData.itemId}-${viewPosition}-${sectionIndex}`;
20357
+ const currentTime = videoRef.currentTime;
20358
+ const lastTime = videoLastCurrentTime.current[videoId] || 0;
20359
+ // 检测视频循环(当前时间明显小于上次时间,说明视频重新开始了)
20360
+ if (lastTime > 0 && currentTime < lastTime && lastTime > videoRef.duration * 0.9) {
20361
+ console.log('[handleVideoTimeUpdate] 检测到视频循环,currentTime:', currentTime, 'lastTime:', lastTime);
20362
+ // 上报 playOverVideo(循环结束)
20363
+ const videoDuration = videoRef.duration.toFixed(2);
20364
+ const startTime = videoStartTime.current[videoId] || 0;
20365
+ const playDuration = (lastTime - startTime).toFixed(2);
20366
+ if (parseFloat(playDuration) >= 0.1) {
20367
+ console.log('[handleVideoTimeUpdate] 上报循环结束的 playOverVideo 事件');
20368
+ bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
20369
+ eventInfo: {
20370
+ eventSubject: 'playOverVideo',
20371
+ eventDescription: 'User finished playing the video',
20372
+ sceneId: '',
20373
+ contentId: (videoData === null || videoData === void 0 ? void 0 : videoData.itemId) || '',
20374
+ contentName: (videoData === null || videoData === void 0 ? void 0 : videoData.title) || '',
20375
+ endTime: videoDuration,
20376
+ videoDuration,
20377
+ playDuration,
20378
+ contentTags: (videoData === null || videoData === void 0 ? void 0 : videoData.tags) ? JSON.stringify(videoData.tags) : '[]',
20379
+ position: `${sectionIndex || 0}`,
20380
+ contentFormat: 'video',
20381
+ rtc: '',
20382
+ traceInfo: (videoData === null || videoData === void 0 ? void 0 : videoData.traceInfo) || ''
20383
+ }
20384
+ });
20385
+ }
20386
+ // 重置上次上报时间,让下次 play 事件可以上报
20387
+ delete videoPlayReportTime.current[videoId];
20388
+ }
20389
+ // 更新上次播放时间
20390
+ videoLastCurrentTime.current[videoId] = currentTime;
20391
+ }, [bffEventReport]);
20355
20392
  // 视频播放结束/暂停事件处理
20356
- const handleVideoPlayOver = React.useCallback((videoData, viewPosition, sectionIndex, videoRef) => {
20393
+ const handleVideoPlayOver = React.useCallback((videoData, viewPosition, sectionIndex, videoRef, isEndedEvent) => {
20357
20394
  if (!videoRef || !videoRef.duration)
20358
20395
  return;
20359
20396
  const videoId = `${videoData === null || videoData === void 0 ? void 0 : videoData.itemId}-${viewPosition}-${sectionIndex}`;
@@ -20362,6 +20399,18 @@ const StructurePage = (_a) => {
20362
20399
  // 计算播放时长
20363
20400
  const startTime = videoStartTime.current[videoId] || 0;
20364
20401
  const playDuration = (videoRef.currentTime - startTime).toFixed(2);
20402
+ // 如果播放时长过短(小于100ms),可能是误触发,不上报
20403
+ if (parseFloat(playDuration) < 0.1) {
20404
+ console.log('[handleVideoPlayOver] 播放时长过短,跳过上报:', playDuration);
20405
+ return;
20406
+ }
20407
+ console.log('[handleVideoPlayOver] 上报 playOverVideo 事件:', {
20408
+ videoId,
20409
+ isEndedEvent,
20410
+ endTime,
20411
+ playDuration,
20412
+ videoDuration
20413
+ });
20365
20414
  bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
20366
20415
  eventInfo: {
20367
20416
  eventSubject: 'playOverVideo',
@@ -20569,8 +20618,8 @@ const StructurePage = (_a) => {
20569
20618
  return;
20570
20619
  }
20571
20620
  // 构建 CMS 接口的 URL 和请求体
20572
- // apiUrl 应该是域名(如 http://localhost:8001),然后拼接 /api/console/ad/multiCta/rec/detail
20573
- finalApiUrl = `${apiUrl}/api/console/ad/multiCta/rec/detail`;
20621
+ // apiUrl 应该是域名(如 https://us-sxp3-be.chatlabs.net),然后拼接 /console/ad/multiCta/rec/detail
20622
+ finalApiUrl = `${apiUrl}/console/ad/multiCta/rec/detail`;
20574
20623
  bodyToSend = { storyId };
20575
20624
  }
20576
20625
  else {
@@ -21049,7 +21098,15 @@ const StructurePage = (_a) => {
21049
21098
  return textStyle;
21050
21099
  })()) }, data.heroSection.text))),
21051
21100
  React.createElement("div", { style: baseStyles.heroImageContainer },
21052
- React.createElement(PostView, { videoRef: heroVideoRef, isVideo: !!data.heroSection.url, autoPlayTriggerRef: heroAutoPlayTrigger }, data.heroSection.url ? (React.createElement("div", { style: { position: 'relative', width: '100%', height: '100%' }, onClick: handleHeroVideoClick },
21101
+ React.createElement(PostView, { videoRef: heroVideoRef, isVideo: !!data.heroSection.url, autoPlayTriggerRef: heroAutoPlayTrigger, onVideoPlay: () => {
21102
+ // 视频开始播放,隐藏暂停图标
21103
+ console.log('[Hero PostView] onVideoPlay 回调');
21104
+ setIsHeroVideoPaused(false);
21105
+ }, onVideoPause: () => {
21106
+ // 视频暂停,显示暂停图标
21107
+ console.log('[Hero PostView] onVideoPause 回调');
21108
+ setIsHeroVideoPaused(true);
21109
+ } }, data.heroSection.url ? (React.createElement("div", { style: { position: 'relative', width: '100%', height: '100%' }, onClick: handleHeroVideoClick },
21053
21110
  React.createElement("video", { ref: (el) => {
21054
21111
  if (heroVideoRef) {
21055
21112
  heroVideoRef.current = el;
@@ -21075,7 +21132,10 @@ const StructurePage = (_a) => {
21075
21132
  });
21076
21133
  el.addEventListener('ended', (e) => {
21077
21134
  console.log('[Hero Video] ended event triggered');
21078
- handleVideoPlayOver(data.heroSection, 'heroSection', 0, e.currentTarget);
21135
+ handleVideoPlayOver(data.heroSection, 'heroSection', 0, e.currentTarget, true);
21136
+ });
21137
+ el.addEventListener('timeupdate', (e) => {
21138
+ handleVideoTimeUpdate(data.heroSection, 'heroSection', 0, e.currentTarget);
21079
21139
  });
21080
21140
  }
21081
21141
  }, src: data.heroSection.url, style: baseStyles.heroVideo, muted: true, loop: true, playsInline: true, controls: false, onLoadedMetadata: () => {
@@ -21141,7 +21201,10 @@ const StructurePage = (_a) => {
21141
21201
  });
21142
21202
  el.addEventListener('ended', (e) => {
21143
21203
  console.log('[Carousel Video] ended event triggered, index:', index);
21144
- handleVideoPlayOver(item, 'carouselSection', index, e.currentTarget);
21204
+ handleVideoPlayOver(item, 'carouselSection', index, e.currentTarget, true);
21205
+ });
21206
+ el.addEventListener('timeupdate', (e) => {
21207
+ handleVideoTimeUpdate(item, 'carouselSection', index, e.currentTarget);
21145
21208
  });
21146
21209
  }
21147
21210
  }, src: item.url, style: baseStyles.carouselVideo, muted: true, loop: true, playsInline: true, controls: false, draggable: false, onDragStart: (e) => e.preventDefault(), onLoadedMetadata: () => {
@@ -21174,7 +21237,10 @@ const StructurePage = (_a) => {
21174
21237
  });
21175
21238
  el.addEventListener('ended', (e) => {
21176
21239
  console.log('[Carousel Video (non-current)] ended event triggered, index:', index);
21177
- handleVideoPlayOver(item, 'carouselSection', index, e.currentTarget);
21240
+ handleVideoPlayOver(item, 'carouselSection', index, e.currentTarget, true);
21241
+ });
21242
+ el.addEventListener('timeupdate', (e) => {
21243
+ handleVideoTimeUpdate(item, 'carouselSection', index, e.currentTarget);
21178
21244
  });
21179
21245
  }
21180
21246
  }, src: item.url, style: baseStyles.carouselVideo, muted: true, loop: true, playsInline: true, controls: false, draggable: false, onDragStart: (e) => e.preventDefault(), onLoadedMetadata: () => {