@vouchfor/embeds 0.0.0-experiment.5d16720 → 0.0.0-experiment.62328c8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/embeds",
3
- "version": "0.0.0-experiment.5d16720",
3
+ "version": "0.0.0-experiment.62328c8",
4
4
  "license": "MIT",
5
5
  "author": "Aaron Williams",
6
6
  "main": "dist/es/embeds.js",
@@ -26,7 +26,7 @@
26
26
  "lint:staged": "lint-staged",
27
27
  "prepublishOnly": "yarn build",
28
28
  "size": "size-limit",
29
- "storybook": "yarn prebuild && storybook dev -p 6006",
29
+ "storybook": "yarn prebuild && storybook dev -p 6007",
30
30
  "prebuild": "yarn build:deps && yarn generate:manifest",
31
31
  "test": "true"
32
32
  },
@@ -35,8 +35,8 @@
35
35
  "**/*.{md,json,yml}": "prettier --write"
36
36
  },
37
37
  "dependencies": {
38
- "@lit/task": "1.0.0",
39
- "@vouchfor/media-player": "0.0.0-experiment.5d16720",
38
+ "@lit/task": "^1.0.0",
39
+ "@vouchfor/media-player": "0.0.0-experiment.62328c8",
40
40
  "uuid": "^9.0.1"
41
41
  },
42
42
  "peerDependencies": {
@@ -10,30 +10,18 @@ type EmbedArgs = EmbedProps & {
10
10
  showVouch?: boolean;
11
11
  };
12
12
 
13
- const _Embed = ({
14
- vouchId,
15
- templateId,
16
- preload,
17
- autoplay,
18
- env,
19
- apiKey,
20
- controls,
21
-
22
- resolution,
23
- aspectRatio
24
- }: EmbedArgs) => {
13
+ const _Embed = ({ vouchId, templateId, preload, autoplay, env, apiKey, controls, aspectRatio }: EmbedArgs) => {
25
14
  return html`
26
15
  <div style="height: 100vh">
27
16
  <vouch-embed
28
17
  env=${ifDefined(env)}
29
18
  apiKey=${ifDefined(apiKey)}
30
- ?autoplay=${autoplay}
31
19
  vouchId=${ifDefined(vouchId)}
32
20
  templateId=${ifDefined(templateId)}
33
- resolution=${ifDefined(resolution)}
34
- aspectRatio=${ifDefined(aspectRatio)}
35
- preload=${ifDefined(preload)}
36
21
  .controls=${controls}
22
+ ?autoplay=${autoplay}
23
+ preload=${ifDefined(preload)}
24
+ aspectRatio=${ifDefined(aspectRatio)}
37
25
  ></vouch-embed>
38
26
  </div>
39
27
  `;
@@ -55,7 +43,6 @@ const Embed: Story = {
55
43
  apiKey: 'TVik9uTMgE-PD25UTHIS6gyl0hMBWC7AT4dkpdlLBT4VIfDWZJrQiCk6Ak7m1',
56
44
  vouchId: '6JQEIPeStt',
57
45
  templateId: '7d0113f7-3f9a-4bdd-97e3-07ee6eec5730',
58
- resolution: 1080,
59
46
  aspectRatio: 0,
60
47
  preload: 'none',
61
48
  autoplay: false
@@ -1,7 +1,6 @@
1
1
  import { Task } from '@lit/task';
2
2
 
3
3
  import type { Embed, EmbedProps } from '..';
4
- import type { TemplateInstance } from '@vouchfor/canvas-video';
5
4
  import type { ReactiveControllerHost } from 'lit';
6
5
  import type { Environment } from '~/utils/env';
7
6
 
@@ -21,8 +20,6 @@ class FetcherController {
21
20
  host: EmbedHost;
22
21
 
23
22
  private _fetching = false;
24
- private _vouch: EmbedProps['data'] | null = null;
25
- private _template: TemplateInstance | null = null;
26
23
 
27
24
  set fetching(value) {
28
25
  if (this._fetching !== value) {
@@ -34,50 +31,22 @@ class FetcherController {
34
31
  return this._fetching;
35
32
  }
36
33
 
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) {
34
+ private async getVouch(env: Environment, apiKey: string, vouchId: string) {
58
35
  const { embedApiUrl } = getEnvUrls(env);
59
36
 
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;
37
+ return fetch(`${embedApiUrl}/vouches/${vouchId}`, {
38
+ method: 'GET',
39
+ headers: [['X-Api-Key', apiKey]]
40
+ }).then((response) => response.json());
68
41
  }
69
42
 
70
- private async getTemplate(env: Environment, apiKey: string, templateId?: string) {
43
+ private async getTemplate(env: Environment, apiKey: string, templateId: string) {
71
44
  const { embedApiUrl } = getEnvUrls(env);
72
45
 
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;
46
+ return fetch(`${embedApiUrl}/templates/${templateId}`, {
47
+ method: 'GET',
48
+ headers: [['X-Api-Key', apiKey]]
49
+ }).then((response) => response.json());
81
50
  }
82
51
 
83
52
  constructor(host: EmbedHost) {
@@ -86,22 +55,26 @@ class FetcherController {
86
55
  this.host,
87
56
  async ([env, apiKey, data, vouchId, templateId]: TaskDeps) => {
88
57
  try {
89
- this.vouch = null;
90
- this.template = null;
58
+ host.vouch = undefined;
59
+ host.template = undefined;
91
60
 
92
61
  if (data) {
93
- const template = await this.getTemplate(env, apiKey, templateId);
94
- this.vouch = data;
95
- this.template = data?.settings?.template?.instance ?? template;
62
+ let template;
63
+ if (templateId) {
64
+ this.fetching = true;
65
+ template = await this.getTemplate(env, apiKey, templateId);
66
+ }
67
+ host.vouch = data;
68
+ host.template = template ?? data?.settings?.template?.instance;
96
69
  } else if (vouchId) {
97
70
  this.fetching = true;
98
71
 
99
72
  const [vouch, template] = await Promise.all([
100
73
  this.getVouch(env, apiKey, vouchId),
101
- this.getTemplate(env, apiKey, templateId)
74
+ templateId ? this.getTemplate(env, apiKey, templateId) : null
102
75
  ]);
103
- this.vouch = vouch;
104
- this.template = vouch?.settings?.template?.instance ?? template;
76
+ host.vouch = vouch;
77
+ host.template = template ?? vouch?.settings?.template?.instance;
105
78
  }
106
79
  } finally {
107
80
  this.fetching = false;
@@ -1,9 +1,9 @@
1
1
  import { html, LitElement } from 'lit';
2
- import { customElement, property } from 'lit/decorators.js';
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 } from '@vouchfor/canvas-video';
6
+ import type { Scene, 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,10 +14,7 @@ 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;
23
20
  vouchId?: string;
@@ -35,12 +32,10 @@ class Embed extends LitElement {
35
32
  @property({ type: String }) env: EmbedProps['env'] = 'prod';
36
33
  @property({ type: String }) apiKey: EmbedProps['apiKey'] = '';
37
34
 
35
+ @property({ type: Array }) controls: EmbedProps['controls'];
38
36
  @property({ type: String }) preload: EmbedProps['preload'] = 'auto';
39
37
  @property({ type: Boolean }) autoplay: EmbedProps['autoplay'] = false;
40
-
41
- @property({ type: Number }) resolution: EmbedProps['resolution'] = 1080;
42
38
  @property({ type: Number }) aspectRatio: EmbedProps['aspectRatio'] = 0;
43
- @property({ type: Array }) controls: EmbedProps['controls'];
44
39
 
45
40
  private eventController = new EventForwardController(this, [
46
41
  'durationchange',
@@ -74,13 +69,8 @@ class Embed extends LitElement {
74
69
  // @ts-ignore
75
70
  private _trackingController = new TrackingController(this);
76
71
 
77
- get vouch() {
78
- return this._fetcherController.vouch;
79
- }
80
-
81
- get template() {
82
- return this._fetcherController.template;
83
- }
72
+ @state() vouch: EmbedProps['data'];
73
+ @state() template: TemplateInstance | undefined;
84
74
 
85
75
  get fetching() {
86
76
  return this._fetcherController.fetching;
@@ -176,18 +166,17 @@ class Embed extends LitElement {
176
166
 
177
167
  render() {
178
168
  return html`
179
- <vmp-media-player
169
+ <vmp-new-media-player
180
170
  ${ref(this._mediaPlayerRef)}
181
171
  ${this.eventController.register()}
182
172
  ?autoplay=${this.autoplay}
183
173
  ?loading=${this.fetching}
184
174
  .data=${this.vouch}
185
175
  .template=${this.template}
186
- resolution=${ifDefined(this.resolution)}
187
176
  aspectRatio=${ifDefined(this.aspectRatio)}
188
177
  preload=${ifDefined(this.preload)}
189
178
  .controls=${this.controls}
190
- ></vmp-media-player>
179
+ ></vmp-new-media-player>
191
180
  `;
192
181
  }
193
182
  }
package/src/utils/env.ts CHANGED
@@ -18,7 +18,7 @@ const devPublicApiUrl = 'https://bshyfw4h5a.execute-api.ap-southeast-2.amazonaws
18
18
  const stagingPublicApiUrl = 'https://gyzw7rpbq3.execute-api.ap-southeast-2.amazonaws.com/staging';
19
19
  const prodPublicApiUrl = 'https://vfcjuim1l3.execute-api.ap-southeast-2.amazonaws.com/prod';
20
20
 
21
- const devEmbedApiUrl = 'http://localhost:6060/v1';
21
+ const devEmbedApiUrl = 'https://embed-dev.vouchfor.com/v1';
22
22
  const stagingEmbedApiUrl = 'https://embed-staging.vouchfor.com/v1';
23
23
  const prodEmbedApiUrl = 'https://embed.vouchfor.com/v1';
24
24