@xhub-short/core 0.1.0-beta.7 → 0.1.0-beta.9

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.d.ts CHANGED
@@ -788,6 +788,7 @@ declare class PlayerEngine {
788
788
  private emitEvent;
789
789
  /**
790
790
  * Start watch time tracking
791
+ * Increments watchTime every second and sends analytics heartbeat
791
792
  */
792
793
  private startWatchTimeTracking;
793
794
  /**
@@ -795,9 +796,14 @@ declare class PlayerEngine {
795
796
  */
796
797
  private stopWatchTimeTracking;
797
798
  /**
798
- * Track completion analytics
799
+ * Track completion analytics (when video loops/ends)
799
800
  */
800
801
  private trackCompletion;
802
+ /**
803
+ * Track when user leaves current video (scrolls to next video)
804
+ * Sends final analytics event before video change
805
+ */
806
+ private trackLeaveVideo;
801
807
  /**
802
808
  * Categorize media error
803
809
  */
package/dist/index.js CHANGED
@@ -790,7 +790,11 @@ var PlayerEngine = class {
790
790
  }
791
791
  return false;
792
792
  }
793
- const currentStatus = this.store.getState().status;
793
+ const currentState = this.store.getState();
794
+ const currentStatus = currentState.status;
795
+ if (currentState.currentVideo && currentState.currentVideo.id !== video.id) {
796
+ this.trackLeaveVideo(currentState);
797
+ }
794
798
  if (currentStatus !== "idle" /* IDLE */ && currentStatus !== "error" /* ERROR */ && currentStatus !== "paused" /* PAUSED */) {
795
799
  if (!this.transitionTo("idle" /* IDLE */)) {
796
800
  return false;
@@ -1198,13 +1202,23 @@ var PlayerEngine = class {
1198
1202
  }
1199
1203
  /**
1200
1204
  * Start watch time tracking
1205
+ * Increments watchTime every second and sends analytics heartbeat
1201
1206
  */
1202
1207
  startWatchTimeTracking() {
1203
1208
  if (this.watchTimeInterval) return;
1204
1209
  this.watchTimeInterval = setInterval(() => {
1205
1210
  const state = this.store.getState();
1206
- if (state.status === "playing" /* PLAYING */) {
1207
- this.store.setState({ watchTime: state.watchTime + 1 });
1211
+ if (state.status === "playing" /* PLAYING */ && state.currentVideo) {
1212
+ const newWatchTime = state.watchTime + 1;
1213
+ this.store.setState({ watchTime: newWatchTime });
1214
+ if (this.analytics && newWatchTime >= this.config.watchTimeThreshold) {
1215
+ this.analytics.trackViewDuration(
1216
+ state.currentVideo.id,
1217
+ state.currentTime,
1218
+ // Use playback position (currentTime) for API
1219
+ state.duration
1220
+ );
1221
+ }
1208
1222
  }
1209
1223
  }, 1e3);
1210
1224
  }
@@ -1218,7 +1232,7 @@ var PlayerEngine = class {
1218
1232
  }
1219
1233
  }
1220
1234
  /**
1221
- * Track completion analytics
1235
+ * Track completion analytics (when video loops/ends)
1222
1236
  */
1223
1237
  trackCompletion(state, loopCount) {
1224
1238
  if (!this.analytics || !state.currentVideo) return;
@@ -1230,6 +1244,27 @@ var PlayerEngine = class {
1230
1244
  this.analytics.trackCompletion(state.currentVideo.id, state.watchTime, loopCount);
1231
1245
  }
1232
1246
  }
1247
+ /**
1248
+ * Track when user leaves current video (scrolls to next video)
1249
+ * Sends final analytics event before video change
1250
+ */
1251
+ trackLeaveVideo(state) {
1252
+ if (!this.analytics || !state.currentVideo) return;
1253
+ if (state.watchTime >= this.config.watchTimeThreshold) {
1254
+ this.analytics.trackViewDuration(
1255
+ state.currentVideo.id,
1256
+ state.currentTime,
1257
+ // Use currentTime (playback position) instead of watchTime
1258
+ state.duration
1259
+ );
1260
+ this.logger?.debug("[PlayerEngine] Tracked leave event", {
1261
+ videoId: state.currentVideo.id,
1262
+ watchTime: state.watchTime,
1263
+ currentTime: state.currentTime
1264
+ });
1265
+ }
1266
+ this.stopWatchTimeTracking();
1267
+ }
1233
1268
  /**
1234
1269
  * Categorize media error
1235
1270
  */
@@ -3130,7 +3165,8 @@ var CommentManager = class {
3130
3165
  }
3131
3166
  try {
3132
3167
  await this.adapter.deleteComment({
3133
- id: commentId,
3168
+ videoId,
3169
+ commentId,
3134
3170
  isReply,
3135
3171
  parentId
3136
3172
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xhub-short/core",
3
3
  "sideEffects": false,
4
- "version": "0.1.0-beta.7",
4
+ "version": "0.1.0-beta.9",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -21,14 +21,14 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "zustand": "^5.0.0",
24
- "@xhub-short/contracts": "0.1.0-beta.7"
24
+ "@xhub-short/contracts": "0.1.0-beta.9"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsup": "^8.3.0",
28
28
  "typescript": "^5.7.0",
29
29
  "vitest": "^2.1.0",
30
30
  "@xhub-short/tsconfig": "0.0.0",
31
- "@xhub-short/vitest-config": "0.0.1-beta.6"
31
+ "@xhub-short/vitest-config": "0.0.1-beta.8"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup",