@vouchfor/embeds 0.0.0-experiment.254513d → 0.0.0-experiment.25d0b5c

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. package/dist/es/browser-1597e474.js +433 -0
  2. package/dist/es/browser-1597e474.js.map +1 -0
  3. package/dist/es/embeds.js +10 -1229
  4. package/dist/es/embeds.js.map +1 -1
  5. package/dist/es/index-4eaa1a0f.js +10478 -0
  6. package/dist/es/index-4eaa1a0f.js.map +1 -0
  7. package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  8. package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  9. package/dist/es/src/components/DialogEmbed/index.d.ts +35 -0
  10. package/dist/es/{components/Embed → src/components/PlayerEmbed}/controllers/event-forwarder.d.ts +6 -5
  11. package/dist/es/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
  12. package/dist/es/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  13. package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  14. package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  15. package/dist/es/src/index.d.ts +2 -0
  16. package/dist/es/src/utils/env.d.ts +12 -0
  17. package/dist/iife/dialog-embed/browser-e532bdb2.js +433 -0
  18. package/dist/iife/dialog-embed/browser-e532bdb2.js.map +1 -0
  19. package/dist/iife/dialog-embed/embed.iife.js +1721 -0
  20. package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
  21. package/dist/iife/dialog-embed/embed.js +5 -0
  22. package/dist/iife/dialog-embed/embed.js.map +1 -0
  23. package/dist/iife/dialog-embed/index-66dabc80.js +32929 -0
  24. package/dist/iife/dialog-embed/index-66dabc80.js.map +1 -0
  25. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  26. package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  27. package/dist/iife/dialog-embed/src/components/DialogEmbed/index.d.ts +35 -0
  28. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  29. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
  30. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  31. package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  32. package/dist/iife/dialog-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  33. package/dist/iife/dialog-embed/src/index.d.ts +2 -0
  34. package/dist/iife/dialog-embed/src/utils/env.d.ts +12 -0
  35. package/dist/iife/dialog-embed/src/utils/events.d.ts +2 -0
  36. package/dist/iife/embeds.iife.js +584 -350
  37. package/dist/iife/embeds.iife.js.map +1 -1
  38. package/dist/iife/player-embed/browser-2462cc69.js +433 -0
  39. package/dist/iife/player-embed/browser-2462cc69.js.map +1 -0
  40. package/dist/iife/player-embed/embed.iife.js +1585 -0
  41. package/dist/iife/player-embed/embed.iife.js.map +1 -0
  42. package/dist/iife/player-embed/embed.js +5 -0
  43. package/dist/iife/player-embed/embed.js.map +1 -0
  44. package/dist/iife/player-embed/index-5a09e0ae.js +32486 -0
  45. package/dist/iife/player-embed/index-5a09e0ae.js.map +1 -0
  46. package/dist/iife/player-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
  47. package/dist/iife/player-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
  48. package/dist/iife/player-embed/src/components/DialogEmbed/index.d.ts +35 -0
  49. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
  50. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
  51. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
  52. package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
  53. package/dist/iife/player-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
  54. package/dist/iife/player-embed/src/index.d.ts +2 -0
  55. package/dist/iife/player-embed/src/utils/env.d.ts +12 -0
  56. package/dist/iife/player-embed/src/utils/events.d.ts +2 -0
  57. package/package.json +17 -9
  58. package/src/components/DialogEmbed/Dialog.stories.ts +79 -0
  59. package/src/components/DialogEmbed/DialogOverlay.ts +130 -0
  60. package/src/components/DialogEmbed/DialogPortal.ts +114 -0
  61. package/src/components/DialogEmbed/index.ts +93 -0
  62. package/src/components/{Embed/Embed.stories.ts → PlayerEmbed/PlayerEmbed.stories.ts} +28 -15
  63. package/src/components/{Embed → PlayerEmbed}/controllers/event-forwarder.ts +6 -5
  64. package/src/components/PlayerEmbed/controllers/fetcher.ts +152 -0
  65. package/src/components/PlayerEmbed/controllers/tracking/index.ts +224 -0
  66. package/src/components/PlayerEmbed/controllers/tracking/utils.ts +95 -0
  67. package/src/components/PlayerEmbed/index.ts +149 -0
  68. package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +80 -0
  69. package/src/components/PlayerEmbed/tests/data.ts +183 -0
  70. package/src/index.ts +2 -1
  71. package/src/mixins/media-player-proxy.ts +116 -0
  72. package/src/utils/env.ts +18 -32
  73. package/dist/es/components/Embed/controllers/fetcher.d.ts +0 -20
  74. package/dist/es/components/Embed/controllers/tracking.d.ts +0 -28
  75. package/dist/es/components/Embed/index.d.ts +0 -62
  76. package/dist/es/index.d.ts +0 -1
  77. package/dist/es/utils/env.d.ts +0 -18
  78. package/src/components/Embed/controllers/fetcher.ts +0 -115
  79. package/src/components/Embed/controllers/tracking.ts +0 -261
  80. package/src/components/Embed/index.ts +0 -202
  81. /package/dist/es/{utils → src/utils}/events.d.ts +0 -0
@@ -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,62 +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
- vouchId?: string;
9
- templateId?: string;
10
- };
11
- declare class Embed extends LitElement {
12
- private _mediaPlayerRef;
13
- data: EmbedProps['data'];
14
- vouchId: EmbedProps['vouchId'];
15
- templateId: EmbedProps['templateId'];
16
- env: EmbedProps['env'];
17
- apiKey: EmbedProps['apiKey'];
18
- controls: EmbedProps['controls'];
19
- preload: EmbedProps['preload'];
20
- autoplay: EmbedProps['autoplay'];
21
- aspectRatio: EmbedProps['aspectRatio'];
22
- private eventController;
23
- private _fetcherController;
24
- private _trackingController;
25
- get vouch(): import("@vouchfor/media-player/dist/src/components/MediaPlayer/types").Vouch | undefined;
26
- get template(): TemplateInstance | undefined;
27
- get fetching(): boolean;
28
- get waiting(): boolean | undefined;
29
- get seeking(): boolean | undefined;
30
- get paused(): boolean | undefined;
31
- get captions(): boolean | undefined;
32
- get fullscreen(): boolean | undefined;
33
- get duration(): number | undefined;
34
- set currentTime(value: number);
35
- get currentTime(): number;
36
- set playbackRate(value: number);
37
- get playbackRate(): number;
38
- set volume(value: number);
39
- get volume(): number;
40
- set muted(value: boolean);
41
- get muted(): boolean;
42
- get scene(): Scene | null;
43
- get scenes(): Scene[];
44
- get videoState(): import("@vouchfor/media-player/dist/src/components/MediaPlayer/controllers/scenes").VideoStateMap | undefined;
45
- get mediaPlayer(): MediaPlayer | undefined;
46
- play(): void;
47
- pause(): void;
48
- setScene(index: number): void;
49
- render(): import("lit-html").TemplateResult<1>;
50
- }
51
- declare global {
52
- interface HTMLElementTagNameMap {
53
- 'vouch-embed': Embed;
54
- }
55
- namespace JSX {
56
- interface IntrinsicElements {
57
- 'vouch-embed': Embed;
58
- }
59
- }
60
- }
61
- export { Embed };
62
- export type { EmbedProps };
@@ -1 +0,0 @@
1
- export { Embed } from './components/Embed';
@@ -1,18 +0,0 @@
1
- type Environment = 'dev' | 'staging' | 'prod';
2
- type GetEnvUrlsReturn = {
3
- marketingUrl: string;
4
- videoUrl: string;
5
- publicApiUrl: string;
6
- embedApiUrl: string;
7
- publicRecorderUrl: string;
8
- };
9
- declare const marketingUrl = "https://vouchfor.com";
10
- declare const devEmbedApiUrl = "http://localhost:6060/v1";
11
- declare const stagingEmbedApiUrl = "https://embed-staging.vouchfor.com/v1";
12
- declare const prodEmbedApiUrl = "https://embed.vouchfor.com/v1";
13
- declare const devPublicRecorderUrl = "https://dev.vouchfor.com";
14
- declare const stagingPublicRecorderUrl = "https://staging.vouchfor.com";
15
- declare const prodPublicRecorderUrl = "https://app.vouchfor.com";
16
- declare function getEnvUrls(env: Environment): GetEnvUrlsReturn;
17
- export { marketingUrl, devEmbedApiUrl, stagingEmbedApiUrl, prodEmbedApiUrl, devPublicRecorderUrl, stagingPublicRecorderUrl, prodPublicRecorderUrl, getEnvUrls };
18
- export type { Environment };
@@ -1,115 +0,0 @@
1
- import { Task } from '@lit/task';
2
-
3
- import type { Embed, EmbedProps } from '..';
4
- import type { TemplateInstance } from '@vouchfor/canvas-video';
5
- import type { ReactiveControllerHost } from 'lit';
6
- import type { Environment } from '~/utils/env';
7
-
8
- import { getEnvUrls } from '~/utils/env';
9
-
10
- type EmbedHost = ReactiveControllerHost & Embed;
11
-
12
- type TaskDeps = [
13
- EmbedProps['env'],
14
- EmbedProps['apiKey'],
15
- EmbedProps['data'],
16
- EmbedProps['vouchId'],
17
- EmbedProps['templateId']
18
- ];
19
-
20
- class FetcherController {
21
- host: EmbedHost;
22
-
23
- private _fetching = false;
24
- private _vouch?: EmbedProps['data'];
25
- private _template?: TemplateInstance;
26
-
27
- set fetching(value) {
28
- if (this._fetching !== value) {
29
- this._fetching = value;
30
- this.host.requestUpdate();
31
- }
32
- }
33
- get fetching() {
34
- return this._fetching;
35
- }
36
-
37
- set vouch(value) {
38
- if (this._vouch !== value) {
39
- this._vouch = value;
40
- this.host.requestUpdate();
41
- }
42
- }
43
- get vouch() {
44
- return this._vouch;
45
- }
46
-
47
- set template(value) {
48
- if (this._template !== value) {
49
- this._template = value;
50
- this.host.requestUpdate();
51
- }
52
- }
53
- get template() {
54
- return this._template;
55
- }
56
-
57
- private async getVouch(env: Environment, apiKey: string, vouchId?: string) {
58
- const { embedApiUrl } = getEnvUrls(env);
59
-
60
- if (vouchId) {
61
- return fetch(`${embedApiUrl}/vouches/${vouchId}`, {
62
- method: 'GET',
63
- headers: [['X-Api-Key', apiKey]]
64
- }).then((response) => response.json());
65
- }
66
-
67
- return null;
68
- }
69
-
70
- private async getTemplate(env: Environment, apiKey: string, templateId?: string) {
71
- const { embedApiUrl } = getEnvUrls(env);
72
-
73
- if (templateId) {
74
- return fetch(`${embedApiUrl}/templates/${templateId}`, {
75
- method: 'GET',
76
- headers: [['X-Api-Key', apiKey]]
77
- }).then((response) => response.json());
78
- }
79
-
80
- return null;
81
- }
82
-
83
- constructor(host: EmbedHost) {
84
- this.host = host;
85
- new Task<TaskDeps, void>(
86
- this.host,
87
- async ([env, apiKey, data, vouchId, templateId]: TaskDeps) => {
88
- try {
89
- this.vouch = undefined;
90
- this.template = undefined;
91
-
92
- if (data) {
93
- const template = await this.getTemplate(env, apiKey, templateId);
94
- this.vouch = data;
95
- this.template = data?.settings?.template?.instance ?? template;
96
- } else if (vouchId) {
97
- this.fetching = true;
98
-
99
- const [vouch, template] = await Promise.all([
100
- this.getVouch(env, apiKey, vouchId),
101
- this.getTemplate(env, apiKey, templateId)
102
- ]);
103
- this.vouch = vouch;
104
- this.template = vouch?.settings?.template?.instance ?? template;
105
- }
106
- } finally {
107
- this.fetching = false;
108
- }
109
- },
110
- () => [host.env, host.apiKey, host.data, host.vouchId, host.templateId]
111
- );
112
- }
113
- }
114
-
115
- export { FetcherController };
@@ -1,261 +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 = 2000;
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.data) {
49
- if ('uuid' in this.host.data) {
50
- return this.host.data.uuid;
51
- }
52
- return this.host.data.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: 'media_player',
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
- // Don't send tracking if we don't have a source
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
- private _handleVouchLoaded = ({ detail: vouchId }: CustomEvent<string>) => {
153
- if (!vouchId) {
154
- return;
155
- }
156
-
157
- // Only send loaded event once per session
158
- if (!this._hasLoaded[vouchId]) {
159
- this._sendTrackingEvent('VOUCH_LOADED', {
160
- vouchId
161
- });
162
- this._hasLoaded[vouchId] = true;
163
- }
164
- };
165
-
166
- private _handlePlay = () => {
167
- const vouchId = this._findVouchId();
168
-
169
- if (!vouchId) {
170
- return;
171
- }
172
-
173
- // Only send the video played event once per session
174
- if (!this._hasPlayed) {
175
- this._sendTrackingEvent('VIDEO_PLAYED', {
176
- vouchId,
177
- streamStart: this.host.currentTime
178
- });
179
- this._hasPlayed = true;
180
- }
181
- };
182
-
183
- private _handleVideoPlay = ({ detail: { id, node } }: CustomEvent<VideoEventDetail>) => {
184
- const vouchId = this._findVouchId();
185
- if (!vouchId) {
186
- return;
187
- }
188
- // Only increment play count once per session
189
- if (!this._answersViewed[id]) {
190
- this._sendTrackingEvent('VOUCH_RESPONSE_VIEWED', {
191
- vouchId,
192
- answerId: id
193
- });
194
- this._answersViewed[id] = true;
195
- }
196
- this._streamedTime[id] = node.currentTime;
197
- this._streamedPrevTimestamp[id] = Date.now();
198
- };
199
-
200
- private _handleVideoTimeUpdate = ({ detail: { id, node } }: CustomEvent<VideoEventDetail>) => {
201
- const vouchId = this._findVouchId();
202
- if (!vouchId) {
203
- return;
204
- }
205
- const currentTimestamp = Date.now();
206
- if (
207
- !this.host.paused &&
208
- // Only fire the video seeked event when this video is the active one
209
- id === this.host.scene?.video?.id &&
210
- // Throttle the frequency that we send streamed events while playing
211
- currentTimestamp - this._streamedPrevTimestamp[id] > STREAMED_THROTTLE
212
- ) {
213
- this._sendTrackingEvent('VIDEO_STREAMED', {
214
- vouchId,
215
- answerId: id,
216
- streamStart: this._streamedTime[id],
217
- streamEnd: node.currentTime
218
- });
219
- this._streamedTime[id] = node.currentTime;
220
- this._streamedPrevTimestamp[id] = currentTimestamp;
221
- }
222
- };
223
-
224
- private _handleVideoPause = ({ detail: { id, node } }: CustomEvent<VideoEventDetail>) => {
225
- const vouchId = this._findVouchId();
226
- if (!vouchId) {
227
- return;
228
- }
229
- // Send a video streamed event any time the video pauses then reset the streamed state
230
- // We do this to capture the last bit of time that the video was played between the previous
231
- // stream event and the video being paused manually or stopping because it ended
232
- this._sendTrackingEvent('VIDEO_STREAMED', {
233
- vouchId,
234
- answerId: id,
235
- streamStart: this._streamedTime[id],
236
- streamEnd: node.currentTime
237
- });
238
- delete this._streamedTime[id];
239
- delete this._streamedPrevTimestamp[id];
240
- };
241
-
242
- hostConnected() {
243
- requestAnimationFrame(() => {
244
- this.host.addEventListener('vouch:loaded', this._handleVouchLoaded);
245
- this.host.mediaPlayer?.addEventListener('play', this._handlePlay);
246
- this.host.mediaPlayer?.addEventListener('video:play', this._handleVideoPlay);
247
- this.host.mediaPlayer?.addEventListener('video:pause', this._handleVideoPause);
248
- this.host.mediaPlayer?.addEventListener('video:timeupdate', this._handleVideoTimeUpdate);
249
- });
250
- }
251
-
252
- hostDisconnected() {
253
- this.host.removeEventListener('vouch:loaded', this._handleVouchLoaded);
254
- this.host.mediaPlayer?.removeEventListener('play', this._handlePlay);
255
- this.host.mediaPlayer?.removeEventListener('video:play', this._handleVideoPlay);
256
- this.host.mediaPlayer?.removeEventListener('video:pause', this._handleVideoPause);
257
- this.host.mediaPlayer?.removeEventListener('video:timeupdate', this._handleVideoTimeUpdate);
258
- }
259
- }
260
-
261
- export { TrackingController };
@@ -1,202 +0,0 @@
1
- import { html, LitElement } from 'lit';
2
- import { customElement, property } from 'lit/decorators.js';
3
- import { ifDefined } from 'lit/directives/if-defined.js';
4
- import { createRef, ref } from 'lit/directives/ref.js';
5
-
6
- import type { Scene, TemplateInstance } from '@vouchfor/canvas-video';
7
- import type { MediaPlayer, MediaPlayerProps } from '@vouchfor/media-player';
8
- import type { Ref } from 'lit/directives/ref.js';
9
- import type { Environment } from '~/utils/env';
10
-
11
- import { EventForwardController } from './controllers/event-forwarder';
12
- import { FetcherController } from './controllers/fetcher';
13
- import { TrackingController } from './controllers/tracking';
14
-
15
- import '@vouchfor/media-player';
16
-
17
- type EmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload' | 'autoplay' | 'controls'> & {
18
- env: Environment;
19
- apiKey: string;
20
- vouchId?: string;
21
- templateId?: string;
22
- };
23
-
24
- @customElement('vouch-embed')
25
- class Embed extends LitElement {
26
- private _mediaPlayerRef: Ref<MediaPlayer> = createRef();
27
-
28
- @property({ type: Object, attribute: 'data' }) data: EmbedProps['data'];
29
- @property({ type: String }) vouchId: EmbedProps['vouchId'];
30
- @property({ type: String }) templateId: EmbedProps['templateId'];
31
-
32
- @property({ type: String }) env: EmbedProps['env'] = 'prod';
33
- @property({ type: String }) apiKey: EmbedProps['apiKey'] = '';
34
-
35
- @property({ type: Array }) controls: EmbedProps['controls'];
36
- @property({ type: String }) preload: EmbedProps['preload'] = 'auto';
37
- @property({ type: Boolean }) autoplay: EmbedProps['autoplay'] = false;
38
- @property({ type: Number }) aspectRatio: EmbedProps['aspectRatio'] = 0;
39
-
40
- private eventController = new EventForwardController(this, [
41
- 'durationchange',
42
- 'ended',
43
- 'error',
44
- 'loadeddata',
45
- 'pause',
46
- 'stalled',
47
- 'play',
48
- 'playing',
49
- 'ratechange',
50
- 'scenechange',
51
- 'seeking',
52
- 'seeked',
53
- 'timeupdate',
54
- 'volumechange',
55
- 'waiting',
56
-
57
- 'video:loadeddata',
58
- 'video:seeked',
59
- 'video:play',
60
- 'video:playing',
61
- 'video:pause',
62
- 'video:stalled',
63
- 'video:timeupdate',
64
- 'video:ended',
65
- 'video:error'
66
- ]);
67
- private _fetcherController = new FetcherController(this);
68
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
69
- // @ts-ignore
70
- private _trackingController = new TrackingController(this);
71
-
72
- get vouch() {
73
- return this._fetcherController.vouch;
74
- }
75
-
76
- get template(): TemplateInstance | undefined {
77
- return this._fetcherController.template;
78
- }
79
-
80
- get fetching() {
81
- return this._fetcherController.fetching;
82
- }
83
-
84
- get waiting() {
85
- return this._mediaPlayerRef.value?.waiting;
86
- }
87
-
88
- get seeking() {
89
- return this._mediaPlayerRef.value?.seeking;
90
- }
91
-
92
- get paused() {
93
- return this._mediaPlayerRef.value?.paused;
94
- }
95
-
96
- get captions() {
97
- return this._mediaPlayerRef.value?.captions;
98
- }
99
-
100
- get fullscreen() {
101
- return this._mediaPlayerRef.value?.fullscreen;
102
- }
103
-
104
- get duration() {
105
- return this._mediaPlayerRef.value?.duration;
106
- }
107
-
108
- set currentTime(value: number) {
109
- if (this._mediaPlayerRef.value) {
110
- this._mediaPlayerRef.value.currentTime = value;
111
- }
112
- }
113
- get currentTime() {
114
- return this._mediaPlayerRef.value?.currentTime ?? 0;
115
- }
116
-
117
- set playbackRate(value: number) {
118
- if (this._mediaPlayerRef.value) {
119
- this._mediaPlayerRef.value.playbackRate = value;
120
- }
121
- }
122
- get playbackRate() {
123
- return this._mediaPlayerRef.value?.playbackRate ?? 1;
124
- }
125
-
126
- set volume(value: number) {
127
- if (this._mediaPlayerRef.value) {
128
- this._mediaPlayerRef.value.volume = value;
129
- }
130
- }
131
- get volume() {
132
- return this._mediaPlayerRef.value?.volume ?? 1;
133
- }
134
-
135
- set muted(value: boolean) {
136
- if (this._mediaPlayerRef.value) {
137
- this._mediaPlayerRef.value.muted = value;
138
- }
139
- }
140
- get muted() {
141
- return this._mediaPlayerRef.value?.muted ?? false;
142
- }
143
-
144
- get scene(): Scene | null {
145
- return this._mediaPlayerRef.value?.scene ?? null;
146
- }
147
-
148
- get scenes(): Scene[] {
149
- return this._mediaPlayerRef.value?.scenes ?? [];
150
- }
151
-
152
- get videoState() {
153
- return this._mediaPlayerRef.value?.videoState;
154
- }
155
-
156
- get mediaPlayer() {
157
- return this._mediaPlayerRef.value;
158
- }
159
-
160
- play() {
161
- this._mediaPlayerRef.value?.play();
162
- }
163
-
164
- pause() {
165
- this._mediaPlayerRef.value?.pause();
166
- }
167
-
168
- setScene(index: number) {
169
- this._mediaPlayerRef.value?.setScene(index);
170
- }
171
-
172
- render() {
173
- return html`
174
- <vmp-media-player
175
- ${ref(this._mediaPlayerRef)}
176
- ${this.eventController.register()}
177
- ?autoplay=${this.autoplay}
178
- ?loading=${this.fetching}
179
- .data=${this.vouch}
180
- .template=${this.template}
181
- aspectRatio=${ifDefined(this.aspectRatio)}
182
- preload=${ifDefined(this.preload)}
183
- .controls=${this.controls}
184
- ></vmp-media-player>
185
- `;
186
- }
187
- }
188
-
189
- declare global {
190
- interface HTMLElementTagNameMap {
191
- 'vouch-embed': Embed;
192
- }
193
-
194
- namespace JSX {
195
- interface IntrinsicElements {
196
- 'vouch-embed': Embed;
197
- }
198
- }
199
- }
200
-
201
- export { Embed };
202
- export type { EmbedProps };
File without changes