@vouchfor/embeds 0.0.0-experiment.4ea86a2 → 0.0.0-experiment.4eb5f06
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/es/components/Embed/controllers/tracking.d.ts +0 -2
- package/dist/es/embeds.js +44 -55
- package/dist/es/embeds.js.map +1 -1
- package/dist/iife/embeds.iife.js +2 -2
- package/dist/iife/embeds.iife.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Embed/controllers/tracking.ts +9 -34
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vouchfor/embeds",
|
3
|
-
"version": "0.0.0-experiment.
|
3
|
+
"version": "0.0.0-experiment.4eb5f06",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Aaron Williams",
|
6
6
|
"main": "dist/es/embeds.js",
|
@@ -36,7 +36,7 @@
|
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
38
|
"@lit/task": "^1.0.0",
|
39
|
-
"@vouchfor/media-player": "0.0.0-experiment.
|
39
|
+
"@vouchfor/media-player": "0.0.0-experiment.4eb5f06",
|
40
40
|
"uuid": "^9.0.1"
|
41
41
|
},
|
42
42
|
"peerDependencies": {
|
@@ -7,7 +7,8 @@ import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
7
7
|
|
8
8
|
import { getEnvUrls } from '~/utils/env';
|
9
9
|
|
10
|
-
|
10
|
+
// In seconds due to checking against node.currentTime
|
11
|
+
const STREAMED_THROTTLE = 10;
|
11
12
|
|
12
13
|
type EmbedHost = ReactiveControllerHost & Embed;
|
13
14
|
|
@@ -39,7 +40,6 @@ class TrackingController implements ReactiveController {
|
|
39
40
|
private _answersViewed: BooleanMap = {};
|
40
41
|
private _streamedTime: TimeMap = {};
|
41
42
|
private _streamLatestTime: TimeMap = {};
|
42
|
-
private _streamedPrevTimestamp: TimeMap = {};
|
43
43
|
|
44
44
|
constructor(host: EmbedHost) {
|
45
45
|
this.host = host;
|
@@ -203,28 +203,6 @@ class TrackingController implements ReactiveController {
|
|
203
203
|
|
204
204
|
this._streamedTime[key] = node.currentTime;
|
205
205
|
this._streamLatestTime[key] = node.currentTime;
|
206
|
-
this._streamedPrevTimestamp[key] = Date.now();
|
207
|
-
};
|
208
|
-
|
209
|
-
private _handleVideoSeeking = ({ detail: { id, key } }: CustomEvent<VideoEventDetail>) => {
|
210
|
-
const vouchId = this._findVouchId();
|
211
|
-
|
212
|
-
if (!vouchId) {
|
213
|
-
return;
|
214
|
-
}
|
215
|
-
|
216
|
-
if (this._streamLatestTime[key]) {
|
217
|
-
this._sendTrackingEvent('VIDEO_STREAMED', {
|
218
|
-
vouchId,
|
219
|
-
answerId: id,
|
220
|
-
streamStart: this._streamedTime[key],
|
221
|
-
streamEnd: this._streamLatestTime[key]
|
222
|
-
});
|
223
|
-
}
|
224
|
-
|
225
|
-
delete this._streamedTime[key];
|
226
|
-
delete this._streamLatestTime[key];
|
227
|
-
delete this._streamedPrevTimestamp[key];
|
228
206
|
};
|
229
207
|
|
230
208
|
private _handleVideoTimeUpdate = ({ detail: { id, key, node } }: CustomEvent<VideoEventDetail>) => {
|
@@ -234,7 +212,6 @@ class TrackingController implements ReactiveController {
|
|
234
212
|
return;
|
235
213
|
}
|
236
214
|
|
237
|
-
const currentTimestamp = Date.now();
|
238
215
|
if (
|
239
216
|
node.currentTime &&
|
240
217
|
!node.paused &&
|
@@ -242,7 +219,7 @@ class TrackingController implements ReactiveController {
|
|
242
219
|
// Only fire the video seeked event when this video is the active one
|
243
220
|
id === this.host.scene?.video?.id &&
|
244
221
|
// Throttle the frequency that we send streamed events while playing
|
245
|
-
|
222
|
+
node.currentTime - this._streamedTime[key] > STREAMED_THROTTLE
|
246
223
|
) {
|
247
224
|
this._sendTrackingEvent('VIDEO_STREAMED', {
|
248
225
|
vouchId,
|
@@ -251,13 +228,14 @@ class TrackingController implements ReactiveController {
|
|
251
228
|
streamEnd: node.currentTime
|
252
229
|
});
|
253
230
|
this._streamedTime[key] = node.currentTime;
|
254
|
-
this._streamedPrevTimestamp[key] = currentTimestamp;
|
255
231
|
}
|
256
232
|
|
257
|
-
this.
|
233
|
+
if (!this.host.paused) {
|
234
|
+
this._streamLatestTime[key] = node.currentTime;
|
235
|
+
}
|
258
236
|
};
|
259
237
|
|
260
|
-
private _handleVideoPause = ({ detail: { id, key
|
238
|
+
private _handleVideoPause = ({ detail: { id, key } }: CustomEvent<VideoEventDetail>) => {
|
261
239
|
const vouchId = this._findVouchId();
|
262
240
|
|
263
241
|
if (!vouchId) {
|
@@ -265,7 +243,7 @@ class TrackingController implements ReactiveController {
|
|
265
243
|
}
|
266
244
|
|
267
245
|
// Don't send a tracking event if the video pauses when seeking backwards
|
268
|
-
if (
|
246
|
+
if (this._streamLatestTime[key] > this._streamedTime[key] + 0.5) {
|
269
247
|
// Send a video streamed event any time the video pauses then reset the streamed state
|
270
248
|
// We do this to capture the last bit of time that the video was played between the previous
|
271
249
|
// stream event and the video being paused manually or stopping because it ended
|
@@ -273,13 +251,12 @@ class TrackingController implements ReactiveController {
|
|
273
251
|
vouchId,
|
274
252
|
answerId: id,
|
275
253
|
streamStart: this._streamedTime[key],
|
276
|
-
streamEnd:
|
254
|
+
streamEnd: this._streamLatestTime[key]
|
277
255
|
});
|
278
256
|
}
|
279
257
|
|
280
258
|
delete this._streamedTime[key];
|
281
259
|
delete this._streamLatestTime[key];
|
282
|
-
delete this._streamedPrevTimestamp[key];
|
283
260
|
};
|
284
261
|
|
285
262
|
hostConnected() {
|
@@ -287,7 +264,6 @@ class TrackingController implements ReactiveController {
|
|
287
264
|
this.host.addEventListener('vouch:loaded', this._handleVouchLoaded);
|
288
265
|
this.host.mediaPlayer?.addEventListener('play', this._handlePlay);
|
289
266
|
this.host.mediaPlayer?.addEventListener('video:play', this._handleVideoPlay);
|
290
|
-
this.host.mediaPlayer?.addEventListener('video:seeking', this._handleVideoSeeking);
|
291
267
|
this.host.mediaPlayer?.addEventListener('video:pause', this._handleVideoPause);
|
292
268
|
this.host.mediaPlayer?.addEventListener('video:timeupdate', this._handleVideoTimeUpdate);
|
293
269
|
});
|
@@ -297,7 +273,6 @@ class TrackingController implements ReactiveController {
|
|
297
273
|
this.host.removeEventListener('vouch:loaded', this._handleVouchLoaded);
|
298
274
|
this.host.mediaPlayer?.removeEventListener('play', this._handlePlay);
|
299
275
|
this.host.mediaPlayer?.removeEventListener('video:play', this._handleVideoPlay);
|
300
|
-
this.host.mediaPlayer?.removeEventListener('video:seeking', this._handleVideoSeeking);
|
301
276
|
this.host.mediaPlayer?.removeEventListener('video:pause', this._handleVideoPause);
|
302
277
|
this.host.mediaPlayer?.removeEventListener('video:timeupdate', this._handleVideoTimeUpdate);
|
303
278
|
}
|