@vouchfor/embeds 0.0.0-experiment.1b80037 → 0.0.0-experiment.1f98c5e

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
- import { html, LitElement } from 'lit';
2
- import { customElement, property } from 'lit/decorators.js';
1
+ import { css, html, LitElement } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
3
  import { ifDefined } from 'lit/directives/if-defined.js';
4
4
  import { createRef, ref } from 'lit/directives/ref.js';
5
5
 
6
- import type { Scene, TemplateInstance } from '@vouchfor/canvas-video';
6
+ import type { Scene, Scenes, TemplateInstance } from '@vouchfor/canvas-video';
7
7
  import type { MediaPlayer, MediaPlayerProps } from '@vouchfor/media-player';
8
8
  import type { Ref } from 'lit/directives/ref.js';
9
9
  import type { Environment } from '~/utils/env';
@@ -14,33 +14,43 @@ import { TrackingController } from './controllers/tracking';
14
14
 
15
15
  import '@vouchfor/media-player';
16
16
 
17
- type EmbedProps = Pick<
18
- MediaPlayerProps,
19
- 'data' | 'resolution' | 'aspectRatio' | 'preload' | 'autoplay' | 'controls'
20
- > & {
17
+ type EmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload' | 'autoplay' | 'controls'> & {
21
18
  env: Environment;
22
19
  apiKey: string;
20
+ disableTracking?: boolean;
21
+ trackingSource?: string;
23
22
  vouchId?: string;
24
23
  templateId?: string;
24
+ // Index of the questions to include starting from 1
25
+ questions?: number[];
25
26
  };
26
27
 
27
28
  @customElement('vouch-embed')
28
29
  class Embed extends LitElement {
30
+ static styles = [
31
+ css`
32
+ :host {
33
+ display: flex;
34
+ }
35
+ `
36
+ ];
37
+
29
38
  private _mediaPlayerRef: Ref<MediaPlayer> = createRef();
30
39
 
31
- @property({ type: Object, attribute: 'data' }) data: EmbedProps['data'];
40
+ @property({ type: Object }) data: EmbedProps['data'];
32
41
  @property({ type: String }) vouchId: EmbedProps['vouchId'];
33
42
  @property({ type: String }) templateId: EmbedProps['templateId'];
43
+ @property({ type: Array }) questions: EmbedProps['questions'];
34
44
 
35
45
  @property({ type: String }) env: EmbedProps['env'] = 'prod';
36
46
  @property({ type: String }) apiKey: EmbedProps['apiKey'] = '';
47
+ @property({ type: Boolean }) disableTracking: EmbedProps['disableTracking'] = false;
48
+ @property({ type: String }) trackingSource: EmbedProps['trackingSource'] = 'embedded_player';
37
49
 
50
+ @property({ type: Array }) controls: EmbedProps['controls'];
38
51
  @property({ type: String }) preload: EmbedProps['preload'] = 'auto';
39
52
  @property({ type: Boolean }) autoplay: EmbedProps['autoplay'] = false;
40
-
41
- @property({ type: Number }) resolution: EmbedProps['resolution'] = 1080;
42
53
  @property({ type: Number }) aspectRatio: EmbedProps['aspectRatio'] = 0;
43
- @property({ type: Array }) controls: EmbedProps['controls'];
44
54
 
45
55
  private eventController = new EventForwardController(this, [
46
56
  'durationchange',
@@ -60,6 +70,7 @@ class Embed extends LitElement {
60
70
  'waiting',
61
71
 
62
72
  'video:loadeddata',
73
+ 'video:seeking',
63
74
  'video:seeked',
64
75
  'video:play',
65
76
  'video:playing',
@@ -74,13 +85,8 @@ class Embed extends LitElement {
74
85
  // @ts-ignore
75
86
  private _trackingController = new TrackingController(this);
76
87
 
77
- get vouch() {
78
- return this._fetcherController.vouch;
79
- }
80
-
81
- get template(): TemplateInstance | null {
82
- return this._fetcherController.template;
83
- }
88
+ @state() vouch: EmbedProps['data'];
89
+ @state() template: TemplateInstance | undefined;
84
90
 
85
91
  get fetching() {
86
92
  return this._fetcherController.fetching;
@@ -154,6 +160,10 @@ class Embed extends LitElement {
154
160
  return this._mediaPlayerRef.value?.scenes ?? [];
155
161
  }
156
162
 
163
+ get sceneConfig(): Scenes | null {
164
+ return this._mediaPlayerRef.value?.sceneConfig ?? null;
165
+ }
166
+
157
167
  get videoState() {
158
168
  return this._mediaPlayerRef.value?.videoState;
159
169
  }
@@ -183,7 +193,6 @@ class Embed extends LitElement {
183
193
  ?loading=${this.fetching}
184
194
  .data=${this.vouch}
185
195
  .template=${this.template}
186
- resolution=${ifDefined(this.resolution)}
187
196
  aspectRatio=${ifDefined(this.aspectRatio)}
188
197
  preload=${ifDefined(this.preload)}
189
198
  .controls=${this.controls}
package/src/utils/env.ts CHANGED
@@ -1,15 +1,11 @@
1
- type Environment = 'dev' | 'staging' | 'prod';
1
+ type Environment = 'local' | 'dev' | 'staging' | 'prod';
2
2
 
3
3
  type GetEnvUrlsReturn = {
4
- marketingUrl: string;
5
4
  videoUrl: string;
6
5
  publicApiUrl: string;
7
6
  embedApiUrl: string;
8
- publicRecorderUrl: string;
9
7
  };
10
8
 
11
- const marketingUrl = 'https://vouchfor.com';
12
-
13
9
  const devVideoUrl = 'https://d2rxhdlm2q91uk.cloudfront.net';
14
10
  const stagingVideoUrl = 'https://d1ix11aj5kfygl.cloudfront.net';
15
11
  const prodVideoUrl = 'https://d157jlwnudd93d.cloudfront.net';
@@ -18,61 +14,51 @@ const devPublicApiUrl = 'https://bshyfw4h5a.execute-api.ap-southeast-2.amazonaws
18
14
  const stagingPublicApiUrl = 'https://gyzw7rpbq3.execute-api.ap-southeast-2.amazonaws.com/staging';
19
15
  const prodPublicApiUrl = 'https://vfcjuim1l3.execute-api.ap-southeast-2.amazonaws.com/prod';
20
16
 
21
- const devEmbedApiUrl = 'http://localhost:6060/v1';
22
- const stagingEmbedApiUrl = 'https://embed-staging.vouchfor.com/v1';
23
- const prodEmbedApiUrl = 'https://embed.vouchfor.com/v1';
24
-
25
- const devPublicRecorderUrl = 'https://dev.vouchfor.com';
26
- const stagingPublicRecorderUrl = 'https://staging.vouchfor.com';
27
- const prodPublicRecorderUrl = 'https://app.vouchfor.com';
17
+ const localEmbedApiUrl = 'http://localhost:6060/v2';
18
+ const devEmbedApiUrl = 'https://embed-dev.vouchfor.com/v2';
19
+ const stagingEmbedApiUrl = 'https://embed-staging.vouchfor.com/v2';
20
+ const prodEmbedApiUrl = 'https://embed.vouchfor.com/v2';
28
21
 
29
22
  // We are handling the case where env is an unknown string so the ts error is a lie
30
23
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31
24
  // @ts-ignore
32
25
  function getEnvUrls(env: Environment): GetEnvUrlsReturn {
33
- if (!['dev', 'staging', 'prod'].includes(env)) {
26
+ if (!['local', 'dev', 'staging', 'prod'].includes(env)) {
34
27
  throw new Error(`Unknown environment: ${env}`);
35
28
  }
36
29
 
30
+ if (env === 'local') {
31
+ return {
32
+ videoUrl: devVideoUrl,
33
+ publicApiUrl: devPublicApiUrl,
34
+ embedApiUrl: localEmbedApiUrl
35
+ };
36
+ }
37
+
37
38
  if (env === 'dev') {
38
39
  return {
39
- marketingUrl,
40
40
  videoUrl: devVideoUrl,
41
41
  publicApiUrl: devPublicApiUrl,
42
- embedApiUrl: devEmbedApiUrl,
43
- publicRecorderUrl: devPublicRecorderUrl
42
+ embedApiUrl: devEmbedApiUrl
44
43
  };
45
44
  }
46
45
 
47
46
  if (env === 'staging') {
48
47
  return {
49
- marketingUrl,
50
48
  videoUrl: stagingVideoUrl,
51
49
  publicApiUrl: stagingPublicApiUrl,
52
- embedApiUrl: stagingEmbedApiUrl,
53
- publicRecorderUrl: stagingPublicRecorderUrl
50
+ embedApiUrl: stagingEmbedApiUrl
54
51
  };
55
52
  }
56
53
 
57
54
  if (env === 'prod') {
58
55
  return {
59
- marketingUrl,
60
56
  videoUrl: prodVideoUrl,
61
57
  publicApiUrl: prodPublicApiUrl,
62
- embedApiUrl: prodEmbedApiUrl,
63
- publicRecorderUrl: prodPublicRecorderUrl
58
+ embedApiUrl: prodEmbedApiUrl
64
59
  };
65
60
  }
66
61
  }
67
62
 
68
- export {
69
- marketingUrl,
70
- devEmbedApiUrl,
71
- stagingEmbedApiUrl,
72
- prodEmbedApiUrl,
73
- devPublicRecorderUrl,
74
- stagingPublicRecorderUrl,
75
- prodPublicRecorderUrl,
76
- getEnvUrls
77
- };
63
+ export { devEmbedApiUrl, stagingEmbedApiUrl, prodEmbedApiUrl, getEnvUrls };
78
64
  export type { Environment };
@@ -1,14 +0,0 @@
1
- import type { Embed } from '..';
2
- import type { ReactiveController, ReactiveControllerHost } from 'lit';
3
- type EmbedHost = ReactiveControllerHost & Embed;
4
- declare class EventForwardController implements ReactiveController {
5
- host: EmbedHost;
6
- private _events;
7
- private _cleanup;
8
- private _forwardElementRef;
9
- constructor(host: EmbedHost, events: string[]);
10
- register(): import("lit-html/directive.js").DirectiveResult<typeof import("lit-html/directives/ref.js").RefDirective>;
11
- hostConnected(): void;
12
- hostDisconnected(): void;
13
- }
14
- export { EventForwardController };
@@ -1,20 +0,0 @@
1
- import type { Embed } from '..';
2
- import type { TemplateInstance } from '@vouchfor/canvas-video';
3
- import type { ReactiveControllerHost } from 'lit';
4
- type EmbedHost = ReactiveControllerHost & Embed;
5
- declare class FetcherController {
6
- host: EmbedHost;
7
- private _fetching;
8
- private _vouch;
9
- private _template;
10
- set fetching(value: boolean);
11
- get fetching(): boolean;
12
- set vouch(value: import("@vouchfor/media-player/dist/src/components/MediaPlayer/types").Vouch | null | undefined);
13
- get vouch(): import("@vouchfor/media-player/dist/src/components/MediaPlayer/types").Vouch | null | undefined;
14
- set template(value: TemplateInstance | null);
15
- get template(): TemplateInstance | null;
16
- private getVouch;
17
- private getTemplate;
18
- constructor(host: EmbedHost);
19
- }
20
- export { FetcherController };
@@ -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 };
File without changes
File without changes