@vouchfor/embeds 0.0.0-experiment.de7febc → 0.0.0-experiment.df3f29a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/dist/es/embeds.js +1008 -1377
  2. package/dist/es/embeds.js.map +1 -1
  3. package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +20 -0
  4. package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +36 -0
  5. package/dist/es/src/components/DialogEmbed/index.d.ts +38 -0
  6. package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  7. package/dist/es/{components/Embed → src/components/PlayerEmbed}/controllers/fetcher.d.ts +5 -4
  8. package/dist/es/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  9. package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  10. package/dist/es/src/components/PlayerEmbed/index.d.ts +75 -0
  11. package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  12. package/dist/es/src/index.d.ts +2 -0
  13. package/dist/iife/dialog-embed/embed.iife.js +1755 -0
  14. package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
  15. package/dist/iife/embeds.iife.js +767 -442
  16. package/dist/iife/embeds.iife.js.map +1 -1
  17. package/dist/iife/player-embed/embed.iife.js +1617 -0
  18. package/dist/iife/player-embed/embed.iife.js.map +1 -0
  19. package/package.json +43 -31
  20. package/src/components/DialogEmbed/Dialog.stories.ts +91 -0
  21. package/src/components/DialogEmbed/DialogOverlay.ts +131 -0
  22. package/src/components/DialogEmbed/DialogPortal.ts +126 -0
  23. package/src/components/DialogEmbed/index.ts +97 -0
  24. package/src/components/{Embed/Embed.stories.ts → PlayerEmbed/PlayerEmbed.stories.ts} +42 -15
  25. package/src/components/{Embed → PlayerEmbed}/controllers/event-forwarder.ts +6 -5
  26. package/src/components/{Embed → PlayerEmbed}/controllers/fetcher.ts +36 -17
  27. package/src/components/PlayerEmbed/controllers/tracking/index.ts +224 -0
  28. package/src/components/PlayerEmbed/controllers/tracking/utils.ts +95 -0
  29. package/src/components/{Embed → PlayerEmbed}/index.ts +83 -29
  30. package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +80 -0
  31. package/src/components/PlayerEmbed/tests/data.ts +183 -0
  32. package/src/index.ts +2 -1
  33. package/dist/es/components/Embed/controllers/tracking.d.ts +0 -28
  34. package/dist/es/components/Embed/index.d.ts +0 -66
  35. package/dist/es/index.d.ts +0 -1
  36. package/src/components/Embed/controllers/tracking.ts +0 -271
  37. /package/dist/es/{utils → src/utils}/env.d.ts +0 -0
  38. /package/dist/es/{utils → src/utils}/events.d.ts +0 -0
@@ -0,0 +1,80 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ import { expect, fixture, waitUntil } from '@open-wc/testing';
3
+ import { html } from 'lit';
4
+ import sinon from 'sinon';
5
+
6
+ import type { PlayerEmbed } from '../index.js';
7
+ import type { VideoMap } from '@vouchfor/media-player';
8
+
9
+ import { data } from './data.js';
10
+
11
+ // Can't use typescript aliases with esbuild file transforms apparently
12
+ // No idea what a good way to actually build before testing is, the examples give nothing
13
+ // https://modern-web.dev/guides/test-runner/typescript/
14
+ import '../../../test/lib/embeds.js';
15
+
16
+ function getVideo(videos: VideoMap) {
17
+ return Object.values(videos)[0];
18
+ }
19
+
20
+ function playerLoaded(player: PlayerEmbed) {
21
+ return waitUntil(
22
+ () => {
23
+ return player.mediaPlayer?.initialised;
24
+ },
25
+ 'Player has not loaded video',
26
+ { timeout: 20000 }
27
+ );
28
+ }
29
+
30
+ describe('Embeds', () => {
31
+ it('passes', async () => {
32
+ const player = await fixture<PlayerEmbed>(
33
+ html`<vouch-embed-player env="dev" .data=${data} aspectratio=${1}></vouch-embed-player>`
34
+ );
35
+ // @ts-ignore - accessing private property
36
+ const sendTrackingSpy = sinon.spy(player._trackingController, '_sendTrackingEvent');
37
+ // @ts-ignore - accessing private property
38
+ const createTrackingSpy = sinon.spy(player._trackingController, '_createTrackingEvent');
39
+
40
+ await playerLoaded(player);
41
+ // Have to mute the player because we can't programmatically play videos with sound
42
+ player.muted = true;
43
+ player.play();
44
+ expect(player.paused).eq(false);
45
+ await waitUntil(
46
+ () => {
47
+ // Video plays for 3 seconds
48
+ return (getVideo(player.mediaPlayer!.videos)?.node?.currentTime ?? 0) > 3;
49
+ },
50
+ 'Video did not play for 3 seconds',
51
+ { timeout: 20000 }
52
+ );
53
+ expect(getVideo(player.mediaPlayer!.videos)?.node?.paused).eq(false);
54
+ player.pause();
55
+ expect(getVideo(player.mediaPlayer!.videos)?.node?.paused).eq(true);
56
+ expect(sendTrackingSpy.callCount).to.be.eq(0);
57
+ // Destroy node because events are sent when node is removed from the document
58
+ player.remove();
59
+ expect(sendTrackingSpy.callCount).to.be.eq(1);
60
+ expect(createTrackingSpy.args[0]).to.eql([
61
+ 'VIDEO_PLAYED',
62
+ {
63
+ streamStart: 0
64
+ }
65
+ ]);
66
+ expect(createTrackingSpy.args[1]).to.eql([
67
+ 'VOUCH_RESPONSE_VIEWED',
68
+ {
69
+ answerId: '5c66bb3a-ed68-41a0-a601-a49865104418'
70
+ }
71
+ ]);
72
+ expect(createTrackingSpy.args[2][0]).to.eq('VIDEO_STREAMED');
73
+ // Remove streamStart and streamEnd as these are non-deterministic
74
+ expect({ ...createTrackingSpy.args[2][1], streamStart: undefined, streamEnd: undefined }).to.eql({
75
+ answerId: '5c66bb3a-ed68-41a0-a601-a49865104418',
76
+ streamStart: undefined,
77
+ streamEnd: undefined
78
+ });
79
+ });
80
+ });
@@ -0,0 +1,183 @@
1
+ import type { Vouch } from '@vouchfor/video-utils';
2
+
3
+ /* eslint-disable max-lines */
4
+ const data = {
5
+ id: '85a7f7fb-897c-41a4-be7b-2636cf991f2c',
6
+ hashId: '6JQEIPeStt',
7
+ questions: {
8
+ items: [
9
+ {
10
+ id: '5c66bb3a-ed68-41a0-a601-a49865104418',
11
+ title: `"Emoji": 🇯🇵 🙏
12
+ Arabic: خَرَجَ الوَلَدُ.
13
+ Chinese: 简化字不讲理
14
+ Hebrew: עִבְרִית
15
+ Japanese Kanji: 漢字
16
+ Japanese Hiragana: 平仮名
17
+ Japanese Katakana: 片仮名
18
+ Devangari Hindi: ॳॴॶॷऎऒऔ
19
+ Korean Hangul: 정음/正音
20
+ Cyrillic: АБВГДЕЖЗИКЛМН
21
+ Greek: αβγδ`,
22
+ answer: {
23
+ id: '5c66bb3a-ed68-41a0-a601-a49865104418',
24
+ label: null,
25
+ metadata: {
26
+ duration: 18.5
27
+ },
28
+ settings: {
29
+ endOffset: 0,
30
+ startOffset: 0
31
+ },
32
+ media: {
33
+ input:
34
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/5c66bb3a-ed68-41a0-a601-a49865104418/5c66bb3a-ed68-41a0-a601-a49865104418_input.mp4?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTQ1NDI2MzV9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=vh-ZjBnHDhIIKRe4vr8GHppegY2VIRwXvC~QdX8aV9b5eylmQ~I~EmQ2MKwLOWuQ14DHOF~GU8oAfjXTMWgmZdeu1YzHkDHpQzi1b~NLgipJmpYe9-9OR67MC8jvNTva6OQ5PKsdN6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
35
+ video:
36
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/5c66bb3a-ed68-41a0-a601-a49865104418/5c66bb3a-ed68-41a0-a601-a49865104418.mp4?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTQ1NDI2MzV9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=vh-ZjBnHDhIIKRe4vr8GHppegY2VIRwXvC~QdX8aV9b5eylmQ~I~EmQ2MKwLOWuQ14DHOF~GU8oAfjXTMWgmZdeu1YzHkDHpQzi1b~NLgipJmpYe9-9OR67MC8jvNTva6OQ5PKsdN6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
37
+ playlist:
38
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/5c66bb3a-ed68-41a0-a601-a49865104418/5c66bb3a-ed68-41a0-a601-a49865104418.m3u8?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTQ1NDI2MzV9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=vh-ZjBnHDhIIKRe4vr8GHppegY2VIRwXvC~QdX8aV9b5eylmQ~I~EmQ2MKwLOWuQ14DHOF~GU8oAfjXTMWgmZdeu1YzHkDHpQzi1b~NLgipJmpYe9-9OR67MC8jvNTva6OQ5PKsdN6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
39
+ thumbnail:
40
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/5c66bb3a-ed68-41a0-a601-a49865104418/5c66bb3a-ed68-41a0-a601-a49865104418_poster.0000001.jpg?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTYzMjM0Mjl9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=SGA54MFpy4jaqKJHKEuxRfjk-~NBFAh1tdW9Y6uYJwc0LFjDDgX1sraerSyohmVhj~-QVIrglY5BvglDIhrFcLJWGTkgj4vhyLprk1a7EDckv0HBgp-k1ZKvoDtt3wBOzrL4GicfXBkuMpIu5jv5MY3xemlJj2a6V~h65XJuLO4u-xS~McH6rS3mRxoNl4GcYUVm4upre1DGQx-5Suy6Ateoxl6xxoF8kg5EL02KxkIGiRpwXJTvVmUuVF0rpBj-IE40MfmhLBQ1NNSXiqb3-HjpkKwhYPvB5APVh23mzGmqJ0P3jbr2F1cU4Jvlqsjb6GVP61wGOz9ITeWPZkOy8A__'
41
+ },
42
+ contact: {
43
+ id: 'b62f62a3-0cd4-4512-9b52-121cb2f3e72f',
44
+ name: 'Aaron Williams',
45
+ client: {
46
+ id: '03540d70-1c75-4867-a235-bac842ed6ce4',
47
+ name: 'Not Supplied',
48
+ logoSrc: 'https://logo.clearbit.com/vouchfor.com?size=260'
49
+ }
50
+ },
51
+ captions: {
52
+ current:
53
+ 'WEBVTT\n\n1\n00:00:01.549 --> 00:00:05.920\n🇯🇵 🙏 こんにちは 藤森 章 です 。 え ? 今 日本 の え ? 東京 に 住ん で\n\n2\n00:00:05.929 --> 00:00:11.359\nいる 高校 三 年 生 です 。 えっと 父親 が 日本 人 で 母親 が は\n\n3\n00:00:11.619 --> 00:00:13.130\nえー 中国 人 な ん です けれど も 。\n\n4\n00:00:13.939 --> 00:00:17.889\nえ ? 上海 に 行っ た 時 に 国際 学校 に 通っ て い た の で 。\n\n5\n00:00:17.899 --> 00:00:20.389\nえー 英語 を 日本 語 、 中国 語 、 三 語 を しゃ ます\n\n6\n00:00:21.030 --> 00:00:23.549\nえー で 、 その 中 で 経験 し た こと な ん です けれど も 、\n\n7\n00:00:24.040 --> 00:00:26.700\n日本 語 の 素晴らしい ところ って いう の は 、\n\n8\n00:00:27.260 --> 00:00:27.809\nやっぱり\n\n9\n00:00:28.489 --> 00:00:31.540\n和歌 に も 見 られる よう な 多彩 な 表現 力 と\n\n10\n00:00:32.349 --> 00:00:33.819\nえ 奥深い\n\n11\n00:00:34.770 --> 00:00:38.520\nえー 、 感情 表現 など に ある と 思い ます 。 えー これ を 見 て\n\n12\n00:00:38.759 --> 00:00:41.599\n日本 語 に 興味 を 持っ た 方 は 、 是非 その\n\n13\n00:00:43.180 --> 00:00:43.770\n奥深い\n\n14\n00:00:44.299 --> 00:00:45.630\n表現 など を え 、\n\n15\n00:00:46.299 --> 00:00:49.209\n見 て 、 感じ て えー 、 触れ て み て ください 。 ありがとう\n\n16\n00:00:49.220 --> 00:00:49.599\nござい まし た 。\n'
54
+ }
55
+ }
56
+ },
57
+ {
58
+ id: '5c66bb3a-ed68-41a0-a601-a49865104418',
59
+ // title: "What is the business problem you're trying to solve?",
60
+ answer: {
61
+ id: '5c66bb3a-ed68-41a0-a601-a49865104418',
62
+ label: 'Hello this label is overridden',
63
+ metadata: {
64
+ duration: 18.5
65
+ },
66
+ settings: {
67
+ endOffset: 0.385945945945946,
68
+ startOffset: 0.3037837837837838,
69
+ crop: {
70
+ x: 0.4,
71
+ y: 0.4,
72
+ width: 0.4,
73
+ height: 0.4
74
+ }
75
+ },
76
+ media: {
77
+ input:
78
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/5c66bb3a-ed68-41a0-a601-a49865104418/5c66bb3a-ed68-41a0-a601-a49865104418_input.mp4?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTQ1NDI2MzV9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=vh-ZjBnHDhIIKRe4vr8GHppegY2VIRwXvC~QdX8aV9b5eylmQ~I~EmQ2MKwLOWuQ14DHOF~GU8oAfjXTMWgmZdeu1YzHkDHpQzi1b~NLgipJmpYe9-9OR67MC8jvNTva6OQ5PKsdN6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
79
+ video:
80
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/5c66bb3a-ed68-41a0-a601-a49865104418/5c66bb3a-ed68-41a0-a601-a49865104418.mp4?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cH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H5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
83
+ thumbnail:
84
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/5c66bb3a-ed68-41a0-a601-a49865104418/5c66bb3a-ed68-41a0-a601-a49865104418_poster.0000001.jpg?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTYzMjM0Mjl9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=SGA54MFpy4jaqKJHKEuxRfjk-~NBFAh1tdW9Y6uYJwc0LFjDDgX1sraerSyohmVhj~-QVIrglY5BvglDIhrFcLJWGTkgj4vhyLprk1a7EDckv0HBgp-k1ZKvoDtt3wBOzrL4GicfXBkuMpIu5jv5MY3xemlJj2a6V~h65XJuLO4u-xS~McH6rS3mRxoNl4GcYUVm4upre1DGQx-5Suy6Ateoxl6xxoF8kg5EL02KxkIGiRpwXJTvVmUuVF0rpBj-IE40MfmhLBQ1NNSXiqb3-HjpkKwhYPvB5APVh23mzGmqJ0P3jbr2F1cU4Jvlqsjb6GVP61wGOz9ITeWPZkOy8A__'
85
+ },
86
+ contact: {
87
+ id: 'b62f62a3-0cd4-4512-9b52-121cb2f3e72f',
88
+ name: 'Aaron Williams',
89
+ roleTitle: 'Software Engineer',
90
+ client: {
91
+ id: '03540d70-1c75-4867-a235-bac842ed6ce4',
92
+ logoSrc: 'https://logo.clearbit.com/vouchfor.com?size=260'
93
+ }
94
+ },
95
+ captions: {
96
+ current:
97
+ "WEBVTT\r\n\r\n1\r\n00:00:01.710 --> 00:00:05.250\r\nwe are trying to solve, uh, world hunger.\r\n\r\n2\r\n00:00:05.420 --> 00:00:08.369\r\nI think it's an important goal. Uh, we\r\n\r\n3\r\n00:00:08.380 --> 00:00:09.489\r\nalso would like to get rid of\r\n\r\n4\r\n00:00:09.500 --> 00:00:12.050\r\ntuberculosis. Um, in general. And\r\n\r\n5\r\n00:00:12.060 --> 00:00:15.329\r\nprobably malaria, too. Uh, it's gonna be\r\n\r\n6\r\n00:00:15.340 --> 00:00:17.180\r\na couple of weeks, but I think we can do\r\n\r\n7\r\n00:00:17.190 --> 00:00:17.319\r\nit.\r\n"
98
+ }
99
+ }
100
+ },
101
+ {
102
+ id: 'e77c81a7-f6ef-4eae-91fc-b620d092d8d6',
103
+ title: 'What are the priorities for your business/team this quarter?',
104
+ answer: {
105
+ id: 'e77c81a7-f6ef-4eae-91fc-b620d092d8d6',
106
+ label: null,
107
+ metadata: {
108
+ duration: 16.167
109
+ },
110
+ settings: {
111
+ endOffset: 0,
112
+ startOffset: 0
113
+ },
114
+ media: {
115
+ input:
116
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/e77c81a7-f6ef-4eae-91fc-b620d092d8d6/e77c81a7-f6ef-4eae-91fc-b620d092d8d6_input.mp4?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTQ1NDI2MzV9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=vh-ZjBnHDhIIKRe4vr8GHppegY2VIRwXvC~QdX8aV9b5eylmQ~I~EmQ2MKwLOWuQ14DHOF~GU8oAfjXTMWgmZdeu1YzHkDHpQzi1b~NLgipJmpYe9-9OR67MC8jvNTva6OQ5PKsdN6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
117
+ video:
118
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/e77c81a7-f6ef-4eae-91fc-b620d092d8d6/e77c81a7-f6ef-4eae-91fc-b620d092d8d6.mp4?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTQ1NDI2MzV9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=vh-ZjBnHDhIIKRe4vr8GHppegY2VIRwXvC~QdX8aV9b5eylmQ~I~EmQ2MKwLOWuQ14DHOF~GU8oAfjXTMWgmZdeu1YzHkDHpQzi1b~NLgipJmpYe9-9OR67MC8jvNTva6OQ5PKsdN6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
119
+ playlist:
120
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/e77c81a7-f6ef-4eae-91fc-b620d092d8d6/e77c81a7-f6ef-4eae-91fc-b620d092d8d6.m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ZKvoDtt3wBOzrL4GicfXBkuMpIu5jv5MY3xemlJj2a6V~h65XJuLO4u-xS~McH6rS3mRxoNl4GcYUVm4upre1DGQx-5Suy6Ateoxl6xxoF8kg5EL02KxkIGiRpwXJTvVmUuVF0rpBj-IE40MfmhLBQ1NNSXiqb3-HjpkKwhYPvB5APVh23mzGmqJ0P3jbr2F1cU4Jvlqsjb6GVP61wGOz9ITeWPZkOy8A__'
123
+ },
124
+ contact: {
125
+ id: 'b62f62a3-0cd4-4512-9b52-121cb2f3e72f',
126
+ name: 'Aaron Williams',
127
+ roleTitle: 'Software Engineer',
128
+ client: {
129
+ id: '03540d70-1c75-4867-a235-bac842ed6ce4',
130
+ name: 'Vouch',
131
+ logoSrc: 'https://logo.clearbit.com/vouchfor.com?size=260'
132
+ }
133
+ },
134
+ captions: {
135
+ current:
136
+ 'WEBVTT\r\n\r\n1\r\n00:00:00.709 --> 00:00:03.059\r\npriorities for this business. Uh, for\r\n\r\n2\r\n00:00:03.069 --> 00:00:06.010\r\nthis quarter, uh, to make more money,\r\n\r\n3\r\n00:00:06.019 --> 00:00:09.050\r\nmore profits, Uh, get everything, uh,\r\n\r\n4\r\n00:00:09.069 --> 00:00:13.439\r\nswept away. All our heuristics should be\r\n\r\n5\r\n00:00:13.529 --> 00:00:15.119\r\ntop of the line.\r\n'
137
+ }
138
+ }
139
+ },
140
+ {
141
+ id: '39fd188d-a4dc-43b9-bac8-32fd71bfbc90',
142
+ title: 'What are your biggest pain points?',
143
+ answer: {
144
+ id: '39fd188d-a4dc-43b9-bac8-32fd71bfbc90',
145
+ label: null,
146
+ metadata: {
147
+ duration: 13.792
148
+ },
149
+ settings: {
150
+ endOffset: 0,
151
+ startOffset: 0
152
+ },
153
+ media: {
154
+ input:
155
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/39fd188d-a4dc-43b9-bac8-32fd71bfbc90/39fd188d-a4dc-43b9-bac8-32fd71bfbc90_input.mp4?Policy=eyJT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N6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
158
+ playlist:
159
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/39fd188d-a4dc-43b9-bac8-32fd71bfbc90/39fd188d-a4dc-43b9-bac8-32fd71bfbc90.m3u8?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTQ1NDI2MzV9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=vh-ZjBnHDhIIKRe4vr8GHppegY2VIRwXvC~QdX8aV9b5eylmQ~I~EmQ2MKwLOWuQ14DHOF~GU8oAfjXTMWgmZdeu1YzHkDHpQzi1b~NLgipJmpYe9-9OR67MC8jvNTva6OQ5PKsdN6tQBn9vWbBOP5gXEMZLtBP1tsopNu7ZpaUduyPiSVIH5VlWi~KRvMRZnQpHWxfVvnvvxifuk8bODDHh1Ba7MJxrAkdoskzP7xVYO3NbROscTPZ5tKnK9SVt2tnpdW0Aqxj1e2kH6WJhqwgxFfCDqDojMEesx-om71R99U0hMjwDHUF~EDEk6L6wrmD0OfXxbeKd-g5FoTPdJg__',
160
+ thumbnail:
161
+ 'https://d2rxhdlm2q91uk.cloudfront.net/TVik9uTMgE/6JQEIPeStt/39fd188d-a4dc-43b9-bac8-32fd71bfbc90/39fd188d-a4dc-43b9-bac8-32fd71bfbc90_poster.0000001.jpg?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMnJ4aGRsbTJxOTF1ay5jbG91ZGZyb250Lm5ldC9UVmlrOXVUTWdFLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjIwMTYzMjM0Mjl9fX1dfQ__&Key-Pair-Id=K2SWKOH0FA5F6M&Signature=SGA54MFpy4jaqKJHKEuxRfjk-~NBFAh1tdW9Y6uYJwc0LFjDDgX1sraerSyohmVhj~-QVIrglY5BvglDIhrFcLJWGTkgj4vhyLprk1a7EDckv0HBgp-k1ZKvoDtt3wBOzrL4GicfXBkuMpIu5jv5MY3xemlJj2a6V~h65XJuLO4u-xS~McH6rS3mRxoNl4GcYUVm4upre1DGQx-5Suy6Ateoxl6xxoF8kg5EL02KxkIGiRpwXJTvVmUuVF0rpBj-IE40MfmhLBQ1NNSXiqb3-HjpkKwhYPvB5APVh23mzGmqJ0P3jbr2F1cU4Jvlqsjb6GVP61wGOz9ITeWPZkOy8A__'
162
+ },
163
+ contact: {
164
+ id: 'b62f62a3-0cd4-4512-9b52-121cb2f3e72f',
165
+ name: 'Aaron Williams',
166
+ roleTitle: 'Software Engineer',
167
+ client: {
168
+ id: '03540d70-1c75-4867-a235-bac842ed6ce4',
169
+ name: 'Vouch',
170
+ logoSrc: 'https://logo.clearbit.com/vouchfor.com?size=260'
171
+ }
172
+ },
173
+ captions: {
174
+ current:
175
+ "WEBVTT\r\n\r\n1\r\n00:00:00.790 --> 00:00:03.269\r\nuh, the biggest pain points this this\r\n\r\n2\r\n00:00:03.279 --> 00:00:07.170\r\nquarter. Um, Jerry has been doing the\r\n\r\n3\r\n00:00:07.179 --> 00:00:09.180\r\nworst work that he's ever been doing.\r\n\r\n4\r\n00:00:09.390 --> 00:00:11.680\r\nAnd we must fire him, Jerry. Goodbye,\r\n\r\n5\r\n00:00:11.689 --> 00:00:12.149\r\nJerry.\r\n"
176
+ }
177
+ }
178
+ }
179
+ ]
180
+ }
181
+ } as Vouch;
182
+
183
+ export { data };
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
- export { Embed } from '~/components/Embed';
1
+ export { PlayerEmbed } from '~/components/PlayerEmbed';
2
+ export { DialogEmbed } from '~/components/DialogEmbed';
@@ -1,28 +0,0 @@
1
- import type { Embed } from '..';
2
- import type { ReactiveController, ReactiveControllerHost } from 'lit';
3
- type EmbedHost = ReactiveControllerHost & Embed;
4
- declare class TrackingController implements ReactiveController {
5
- host: EmbedHost;
6
- private _tabId;
7
- private _clientId;
8
- private _visitorId;
9
- private _hasPlayed;
10
- private _hasLoaded;
11
- private _answersViewed;
12
- private _streamedTime;
13
- private _streamedPrevTimestamp;
14
- constructor(host: EmbedHost);
15
- private _findVouchId;
16
- private _createVisitor;
17
- private _getUids;
18
- private _getReportingMetadata;
19
- private _sendTrackingEvent;
20
- private _handleVouchLoaded;
21
- private _handlePlay;
22
- private _handleVideoPlay;
23
- private _handleVideoTimeUpdate;
24
- private _handleVideoPause;
25
- hostConnected(): void;
26
- hostDisconnected(): void;
27
- }
28
- export { TrackingController };
@@ -1,66 +0,0 @@
1
- import { LitElement } from 'lit';
2
- import type { Scene, TemplateInstance } from '@vouchfor/canvas-video';
3
- import type { MediaPlayer, MediaPlayerProps } from '@vouchfor/media-player';
4
- import type { Environment } from '../../utils/env';
5
- type EmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload' | 'autoplay' | 'controls'> & {
6
- env: Environment;
7
- apiKey: string;
8
- enableTracking?: boolean;
9
- trackingSource?: string;
10
- vouchId?: string;
11
- templateId?: string;
12
- };
13
- declare class Embed extends LitElement {
14
- private _mediaPlayerRef;
15
- data: EmbedProps['data'];
16
- vouchId: EmbedProps['vouchId'];
17
- templateId: EmbedProps['templateId'];
18
- env: EmbedProps['env'];
19
- apiKey: EmbedProps['apiKey'];
20
- enableTracking: EmbedProps['enableTracking'];
21
- trackingSource: EmbedProps['trackingSource'];
22
- controls: EmbedProps['controls'];
23
- preload: EmbedProps['preload'];
24
- autoplay: EmbedProps['autoplay'];
25
- aspectRatio: EmbedProps['aspectRatio'];
26
- private eventController;
27
- private _fetcherController;
28
- private _trackingController;
29
- vouch: EmbedProps['data'];
30
- template: TemplateInstance | undefined;
31
- get fetching(): boolean;
32
- get waiting(): boolean | undefined;
33
- get seeking(): boolean | undefined;
34
- get paused(): boolean | undefined;
35
- get captions(): boolean | undefined;
36
- get fullscreen(): boolean | undefined;
37
- get duration(): number | undefined;
38
- set currentTime(value: number);
39
- get currentTime(): number;
40
- set playbackRate(value: number);
41
- get playbackRate(): number;
42
- set volume(value: number);
43
- get volume(): number;
44
- set muted(value: boolean);
45
- get muted(): boolean;
46
- get scene(): Scene | null;
47
- get scenes(): Scene[];
48
- get videoState(): import("@vouchfor/media-player/dist/src/components/MediaPlayer/controllers/scenes").VideoStateMap | undefined;
49
- get mediaPlayer(): MediaPlayer | undefined;
50
- play(): void;
51
- pause(): void;
52
- setScene(index: number): void;
53
- render(): import("lit").TemplateResult<1>;
54
- }
55
- declare global {
56
- interface HTMLElementTagNameMap {
57
- 'vouch-embed': Embed;
58
- }
59
- namespace JSX {
60
- interface IntrinsicElements {
61
- 'vouch-embed': Embed;
62
- }
63
- }
64
- }
65
- export { Embed };
66
- export type { EmbedProps };
@@ -1 +0,0 @@
1
- export { Embed } from './components/Embed';
@@ -1,271 +0,0 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
-
3
- import type { Embed } from '..';
4
- import type { VideoEventDetail } from '@vouchfor/media-player';
5
- import type { ReactiveController, ReactiveControllerHost } from 'lit';
6
-
7
- import { getEnvUrls } from '~/utils/env';
8
-
9
- const STREAMED_THROTTLE = 10000;
10
-
11
- type EmbedHost = ReactiveControllerHost & Embed;
12
-
13
- type TrackingEvent = 'VOUCH_LOADED' | 'VOUCH_RESPONSE_VIEWED' | 'VIDEO_PLAYED' | 'VIDEO_STREAMED';
14
- type TrackingPayload = {
15
- vouchId: string;
16
- answerId?: string;
17
- streamStart?: number;
18
- streamEnd?: number;
19
- };
20
-
21
- type TimeMap = {
22
- [key: string]: number;
23
- };
24
-
25
- type BooleanMap = {
26
- [key: string]: boolean;
27
- };
28
-
29
- class TrackingController implements ReactiveController {
30
- host: EmbedHost;
31
-
32
- private _tabId: string | undefined = undefined;
33
- private _clientId: string | undefined = undefined;
34
- private _visitorId: string | undefined = undefined;
35
-
36
- private _hasPlayed = false;
37
- private _hasLoaded: BooleanMap = {};
38
- private _answersViewed: BooleanMap = {};
39
- private _streamedTime: TimeMap = {};
40
- private _streamedPrevTimestamp: TimeMap = {};
41
-
42
- constructor(host: EmbedHost) {
43
- this.host = host;
44
- host.addController(this);
45
- }
46
-
47
- private _findVouchId() {
48
- if (this.host.vouch) {
49
- if ('uuid' in this.host.vouch) {
50
- return this.host.vouch.uuid;
51
- }
52
- return this.host.vouch.id;
53
- }
54
- }
55
-
56
- private _createVisitor = (visitorId: string) => {
57
- const { publicApiUrl } = getEnvUrls(this.host.env);
58
- window.localStorage?.setItem?.('vouch-uid-visitor', visitorId);
59
- navigator.sendBeacon(`${publicApiUrl}/api/visitor`, JSON.stringify({ visitorId }));
60
- return visitorId;
61
- };
62
-
63
- private _getUids() {
64
- if (typeof window === 'undefined') {
65
- return {
66
- client: null,
67
- tab: null,
68
- request: uuidv4()
69
- };
70
- }
71
-
72
- // Persisted for a user for the same device + browser, so we can e.g. search for all logs related to that browser
73
- const visitorId =
74
- this._visitorId || window.localStorage?.getItem?.('vouch-uid-visitor') || this._createVisitor(uuidv4());
75
- // Persisted for a user for the same device + browser, so we can e.g. search for all logs related to that browser
76
- const clientId = this._clientId || window.localStorage?.getItem?.('vouch-uid-client') || uuidv4();
77
- // Persisted in session storage, so we can search for everything the user has done in a specific tab
78
- const tabId = this._tabId || window.sessionStorage?.getItem?.('vouch-uid-tab') || uuidv4();
79
- // Not persisted, allows us to search for any logs related to a single FE request
80
- // E.g. BE should pass this request ID through all other services to be able to group logs
81
- const requestId = uuidv4();
82
-
83
- // Cache and persist uids
84
- if (visitorId !== this._visitorId) {
85
- this._visitorId = visitorId;
86
- window.localStorage?.setItem?.('vouch-uid-visitor', visitorId);
87
- }
88
-
89
- if (clientId !== this._clientId) {
90
- this._clientId = clientId;
91
- window.localStorage?.setItem?.('vouch-uid-client', clientId);
92
- }
93
-
94
- if (tabId !== this._tabId) {
95
- this._tabId = tabId;
96
- window.sessionStorage?.setItem?.('vouch-uid-tab', tabId);
97
- }
98
-
99
- return {
100
- client: clientId,
101
- tab: tabId,
102
- request: requestId,
103
- visitor: visitorId
104
- };
105
- }
106
-
107
- private _getReportingMetadata = () => {
108
- const [country, region] = Intl.DateTimeFormat().resolvedOptions().timeZone?.split?.('/') ?? [];
109
-
110
- const utmParams: any = {};
111
- [...new URLSearchParams(location.search).entries()].forEach(([key, value]) => {
112
- if (/utm/.test(key)) {
113
- const param = key.toLowerCase().replace(/[-_][a-z0-9]/g, (group) => group.slice(-1).toUpperCase());
114
- utmParams[param] = value;
115
- }
116
- });
117
-
118
- return {
119
- source: this.host.trackingSource,
120
- time: new Date(),
121
- region,
122
- country,
123
- screenHeight: window.screen.height,
124
- screenWidth: window.screen.width,
125
- referrer: document.referrer,
126
- currentUrl: location.href,
127
- ...utmParams
128
- };
129
- };
130
-
131
- private _sendTrackingEvent = (event: TrackingEvent, payload: TrackingPayload) => {
132
- const { publicApiUrl } = getEnvUrls(this.host.env);
133
- const { client, tab, request, visitor } = this._getUids();
134
-
135
- if (this.host.enableTracking) {
136
- navigator.sendBeacon(
137
- `${publicApiUrl}/api/events`,
138
- JSON.stringify({
139
- event,
140
- payload,
141
- context: {
142
- 'x-uid-client': client,
143
- 'x-uid-tab': tab,
144
- 'x-uid-request': request,
145
- 'x-uid-visitor': visitor,
146
- 'x-reporting-metadata': this._getReportingMetadata()
147
- }
148
- })
149
- );
150
- }
151
- };
152
-
153
- private _handleVouchLoaded = ({ detail: vouchId }: CustomEvent<string>) => {
154
- if (!vouchId) {
155
- return;
156
- }
157
-
158
- // Only send loaded event once per session
159
- if (!this._hasLoaded[vouchId]) {
160
- this._sendTrackingEvent('VOUCH_LOADED', {
161
- vouchId
162
- });
163
- this._hasLoaded[vouchId] = true;
164
- }
165
- };
166
-
167
- private _handlePlay = () => {
168
- const vouchId = this._findVouchId();
169
-
170
- if (!vouchId) {
171
- return;
172
- }
173
-
174
- // Only send the video played event once per session
175
- if (!this._hasPlayed) {
176
- this._sendTrackingEvent('VIDEO_PLAYED', {
177
- vouchId,
178
- streamStart: this.host.currentTime
179
- });
180
- this._hasPlayed = true;
181
- }
182
- };
183
-
184
- private _handleVideoPlay = ({ detail: { id, node } }: CustomEvent<VideoEventDetail>) => {
185
- const vouchId = this._findVouchId();
186
-
187
- if (!vouchId) {
188
- return;
189
- }
190
- // Only increment play count once per session
191
- if (!this._answersViewed[id]) {
192
- this._sendTrackingEvent('VOUCH_RESPONSE_VIEWED', {
193
- vouchId,
194
- answerId: id
195
- });
196
- this._answersViewed[id] = true;
197
- }
198
- this._streamedTime[id] = node.currentTime;
199
- this._streamedPrevTimestamp[id] = Date.now();
200
- };
201
-
202
- private _handleVideoTimeUpdate = ({ detail: { id, node } }: CustomEvent<VideoEventDetail>) => {
203
- const vouchId = this._findVouchId();
204
-
205
- if (!vouchId) {
206
- return;
207
- }
208
- const currentTimestamp = Date.now();
209
- if (
210
- node.currentTime &&
211
- !node.paused &&
212
- !this.host.paused &&
213
- // Only fire the video seeked event when this video is the active one
214
- id === this.host.scene?.video?.id &&
215
- // Throttle the frequency that we send streamed events while playing
216
- currentTimestamp - this._streamedPrevTimestamp[id] > STREAMED_THROTTLE
217
- ) {
218
- this._sendTrackingEvent('VIDEO_STREAMED', {
219
- vouchId,
220
- answerId: id,
221
- streamStart: this._streamedTime[id],
222
- streamEnd: node.currentTime
223
- });
224
- this._streamedTime[id] = node.currentTime;
225
- this._streamedPrevTimestamp[id] = currentTimestamp;
226
- }
227
- };
228
-
229
- private _handleVideoPause = ({ detail: { id, node } }: CustomEvent<VideoEventDetail>) => {
230
- const vouchId = this._findVouchId();
231
-
232
- if (!vouchId) {
233
- return;
234
- }
235
-
236
- // Don't send a tracking event if the video pauses when seeking backwards
237
- if (node.currentTime > this._streamedTime[id]) {
238
- // Send a video streamed event any time the video pauses then reset the streamed state
239
- // We do this to capture the last bit of time that the video was played between the previous
240
- // stream event and the video being paused manually or stopping because it ended
241
- this._sendTrackingEvent('VIDEO_STREAMED', {
242
- vouchId,
243
- answerId: id,
244
- streamStart: this._streamedTime[id],
245
- streamEnd: node.currentTime
246
- });
247
- }
248
- delete this._streamedTime[id];
249
- delete this._streamedPrevTimestamp[id];
250
- };
251
-
252
- hostConnected() {
253
- requestAnimationFrame(() => {
254
- this.host.addEventListener('vouch:loaded', this._handleVouchLoaded);
255
- this.host.mediaPlayer?.addEventListener('play', this._handlePlay);
256
- this.host.mediaPlayer?.addEventListener('video:play', this._handleVideoPlay);
257
- this.host.mediaPlayer?.addEventListener('video:pause', this._handleVideoPause);
258
- this.host.mediaPlayer?.addEventListener('video:timeupdate', this._handleVideoTimeUpdate);
259
- });
260
- }
261
-
262
- hostDisconnected() {
263
- this.host.removeEventListener('vouch:loaded', this._handleVouchLoaded);
264
- this.host.mediaPlayer?.removeEventListener('play', this._handlePlay);
265
- this.host.mediaPlayer?.removeEventListener('video:play', this._handleVideoPlay);
266
- this.host.mediaPlayer?.removeEventListener('video:pause', this._handleVideoPause);
267
- this.host.mediaPlayer?.removeEventListener('video:timeupdate', this._handleVideoTimeUpdate);
268
- }
269
- }
270
-
271
- export { TrackingController };
File without changes
File without changes