@vouchfor/embeds 0.0.0-experiment.9fa9330 → 0.0.0-experiment.a210804

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/embeds",
3
- "version": "0.0.0-experiment.9fa9330",
3
+ "version": "0.0.0-experiment.a210804",
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.9fa9330",
39
+ "@vouchfor/media-player": "0.0.0-experiment.a210804",
40
40
  "uuid": "^9.0.1"
41
41
  },
42
42
  "peerDependencies": {
@@ -10,7 +10,17 @@ type EmbedArgs = EmbedProps & {
10
10
  showVouch?: boolean;
11
11
  };
12
12
 
13
- const _Embed = ({ vouchId, templateId, preload, autoplay, env, apiKey, controls, aspectRatio }: EmbedArgs) => {
13
+ const _Embed = ({
14
+ vouchId,
15
+ templateId,
16
+ questions,
17
+ preload,
18
+ autoplay,
19
+ env,
20
+ apiKey,
21
+ controls,
22
+ aspectRatio
23
+ }: EmbedArgs) => {
14
24
  return html`
15
25
  <div style="height: 100vh">
16
26
  <vouch-embed
@@ -18,10 +28,12 @@ const _Embed = ({ vouchId, templateId, preload, autoplay, env, apiKey, controls,
18
28
  apiKey=${ifDefined(apiKey)}
19
29
  vouchId=${ifDefined(vouchId)}
20
30
  templateId=${ifDefined(templateId)}
31
+ .questions=${questions}
21
32
  .controls=${controls}
22
33
  ?autoplay=${autoplay}
23
34
  preload=${ifDefined(preload)}
24
35
  aspectRatio=${ifDefined(aspectRatio)}
36
+ @error=${console.log}
25
37
  ></vouch-embed>
26
38
  </div>
27
39
  `;
@@ -43,6 +55,7 @@ const Embed: Story = {
43
55
  apiKey: 'TVik9uTMgE-PD25UTHIS6gyl0hMBWC7AT4dkpdlLBT4VIfDWZJrQiCk6Ak7m1',
44
56
  vouchId: '6JQEIPeStt',
45
57
  templateId: '357fc118-e179-4171-9446-ff2b8e9d1b29',
58
+ questions: [],
46
59
  aspectRatio: 0,
47
60
  preload: 'none',
48
61
  autoplay: false
@@ -9,7 +9,7 @@ import { getEnvUrls } from '~/utils/env';
9
9
 
10
10
  type EmbedHost = ReactiveControllerHost & Embed;
11
11
 
12
- type TaskDeps = [
12
+ type FetchTaskDeps = [
13
13
  EmbedProps['env'],
14
14
  EmbedProps['apiKey'],
15
15
  EmbedProps['data'],
@@ -17,10 +17,13 @@ type TaskDeps = [
17
17
  EmbedProps['templateId']
18
18
  ];
19
19
 
20
+ type FilterTaskDeps = [EmbedProps['data'], EmbedProps['questions']];
21
+
20
22
  class FetcherController {
21
23
  host: EmbedHost;
22
24
 
23
25
  private _fetching = false;
26
+ private _vouch: EmbedProps['data'];
24
27
 
25
28
  set fetching(value) {
26
29
  if (this._fetching !== value) {
@@ -96,9 +99,9 @@ class FetcherController {
96
99
 
97
100
  constructor(host: EmbedHost) {
98
101
  this.host = host;
99
- new Task<TaskDeps, void>(
102
+ new Task<FetchTaskDeps, void>(
100
103
  this.host,
101
- async ([env, apiKey, data, vouchId, templateId]: TaskDeps) => {
104
+ async ([env, apiKey, data, vouchId, templateId]: FetchTaskDeps) => {
102
105
  try {
103
106
  host.vouch = undefined;
104
107
  host.template = undefined;
@@ -109,7 +112,7 @@ class FetcherController {
109
112
  this.fetching = true;
110
113
  template = await this.getTemplate(env, apiKey, templateId);
111
114
  }
112
- host.vouch = data;
115
+ this._vouch = data;
113
116
  host.template = template ?? data?.settings?.template?.instance;
114
117
  } else if (vouchId) {
115
118
  this.fetching = true;
@@ -118,7 +121,7 @@ class FetcherController {
118
121
  this.getVouch(env, apiKey, vouchId),
119
122
  templateId ? this.getTemplate(env, apiKey, templateId) : null
120
123
  ]);
121
- host.vouch = vouch;
124
+ this._vouch = vouch;
122
125
  host.template = template ?? vouch?.settings?.template?.instance;
123
126
  }
124
127
  } finally {
@@ -127,6 +130,22 @@ class FetcherController {
127
130
  },
128
131
  () => [host.env, host.apiKey, host.data, host.vouchId, host.templateId]
129
132
  );
133
+
134
+ // This second task is to be able to filter the vouch without fetching it again if only the questions changed
135
+ new Task<FilterTaskDeps, void>(
136
+ this.host,
137
+ ([vouch, questions]: FilterTaskDeps) => {
138
+ host.vouch = vouch
139
+ ? {
140
+ ...vouch,
141
+ questions: {
142
+ items: vouch?.questions.items.filter((_, index) => !questions?.length || questions?.includes(index + 1))
143
+ }
144
+ }
145
+ : undefined;
146
+ },
147
+ () => [this._vouch, host.questions]
148
+ );
130
149
  }
131
150
  }
132
151
 
@@ -1,3 +1,4 @@
1
+ import { TEMPLATE_VERSION } from '@vouchfor/canvas-video';
1
2
  import { v4 as uuidv4 } from 'uuid';
2
3
 
3
4
  import type { Embed } from '..';
@@ -127,6 +128,9 @@ class TrackingController implements ReactiveController {
127
128
  screenWidth: window.screen.width,
128
129
  referrer: document.referrer,
129
130
  currentUrl: location.href,
131
+ embedType: 'media-player-embed',
132
+ embedVersion: packageJson.version,
133
+ templateVersion: TEMPLATE_VERSION,
130
134
  ...utmParams
131
135
  };
132
136
  };
@@ -154,8 +158,7 @@ class TrackingController implements ReactiveController {
154
158
  'x-uid-tab': tab,
155
159
  'x-uid-request': request,
156
160
  'x-uid-visitor': visitor,
157
- 'x-reporting-metadata': this._getReportingMetadata(),
158
- 'x-embeds-version': packageJson.version
161
+ 'x-reporting-metadata': this._getReportingMetadata()
159
162
  }
160
163
  })
161
164
  );
@@ -1,4 +1,4 @@
1
- import { html, LitElement } from 'lit';
1
+ import { css, html, LitElement } from 'lit';
2
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';
@@ -21,20 +21,31 @@ type EmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload' | 'a
21
21
  trackingSource?: string;
22
22
  vouchId?: string;
23
23
  templateId?: string;
24
+ // Index of the questions to include starting from 1
25
+ questions?: number[];
24
26
  };
25
27
 
26
28
  @customElement('vouch-embed')
27
29
  class Embed extends LitElement {
30
+ static styles = [
31
+ css`
32
+ :host {
33
+ display: flex;
34
+ }
35
+ `
36
+ ];
37
+
28
38
  private _mediaPlayerRef: Ref<MediaPlayer> = createRef();
29
39
 
30
- @property({ type: Object, attribute: 'data' }) data: EmbedProps['data'];
40
+ @property({ type: Object }) data: EmbedProps['data'];
31
41
  @property({ type: String }) vouchId: EmbedProps['vouchId'];
32
42
  @property({ type: String }) templateId: EmbedProps['templateId'];
43
+ @property({ type: Array }) questions: EmbedProps['questions'];
33
44
 
34
45
  @property({ type: String }) env: EmbedProps['env'] = 'prod';
35
46
  @property({ type: String }) apiKey: EmbedProps['apiKey'] = '';
36
47
  @property({ type: Boolean }) disableTracking: EmbedProps['disableTracking'] = false;
37
- @property({ type: String }) trackingSource: EmbedProps['trackingSource'] = 'embed';
48
+ @property({ type: String }) trackingSource: EmbedProps['trackingSource'] = 'embedded_player';
38
49
 
39
50
  @property({ type: Array }) controls: EmbedProps['controls'];
40
51
  @property({ type: String }) preload: EmbedProps['preload'] = 'auto';
@@ -175,7 +186,7 @@ class Embed extends LitElement {
175
186
 
176
187
  render() {
177
188
  return html`
178
- <vmp-new-media-player
189
+ <vmp-media-player
179
190
  ${ref(this._mediaPlayerRef)}
180
191
  ${this.eventController.register()}
181
192
  ?autoplay=${this.autoplay}
@@ -185,7 +196,7 @@ class Embed extends LitElement {
185
196
  aspectRatio=${ifDefined(this.aspectRatio)}
186
197
  preload=${ifDefined(this.preload)}
187
198
  .controls=${this.controls}
188
- ></vmp-new-media-player>
199
+ ></vmp-media-player>
189
200
  `;
190
201
  }
191
202
  }