@vouchfor/embeds 0.0.0-experiment.3a2bb6b → 0.0.0-experiment.3a5b4f5
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/dist/es/browser-e53f0481.js +433 -0
- package/dist/es/browser-e53f0481.js.map +1 -0
- package/dist/es/embeds.js +7 -1499
- package/dist/es/embeds.js.map +1 -1
- package/dist/es/index-712b6543.js +9947 -0
- package/dist/es/index-712b6543.js.map +1 -0
- package/dist/es/{components → src/components}/Embed/controllers/fetcher.d.ts +1 -0
- package/dist/es/{components → src/components}/Embed/controllers/tracking.d.ts +7 -2
- package/dist/es/{components → src/components}/Embed/index.d.ts +7 -1
- package/dist/iife/embeds.iife.js +407 -268
- package/dist/iife/embeds.iife.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Embed/Embed.stories.ts +14 -1
- package/src/components/Embed/controllers/fetcher.ts +63 -24
- package/src/components/Embed/controllers/tracking.ts +97 -64
- package/src/components/Embed/index.ts +23 -5
- /package/dist/es/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/es/{utils → src/utils}/env.d.ts +0 -0
- /package/dist/es/{utils → src/utils}/events.d.ts +0 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vouchfor/embeds",
|
3
|
-
"version": "0.0.0-experiment.
|
3
|
+
"version": "0.0.0-experiment.3a5b4f5",
|
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.
|
39
|
+
"@vouchfor/media-player": "0.0.0-experiment.3a5b4f5",
|
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 = ({
|
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
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Task } from '@lit/task';
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
2
3
|
|
3
4
|
import type { Embed, EmbedProps } from '..';
|
4
5
|
import type { ReactiveControllerHost } from 'lit';
|
@@ -8,7 +9,7 @@ import { getEnvUrls } from '~/utils/env';
|
|
8
9
|
|
9
10
|
type EmbedHost = ReactiveControllerHost & Embed;
|
10
11
|
|
11
|
-
type
|
12
|
+
type FetchTaskDeps = [
|
12
13
|
EmbedProps['env'],
|
13
14
|
EmbedProps['apiKey'],
|
14
15
|
EmbedProps['data'],
|
@@ -16,10 +17,13 @@ type TaskDeps = [
|
|
16
17
|
EmbedProps['templateId']
|
17
18
|
];
|
18
19
|
|
20
|
+
type FilterTaskDeps = [EmbedProps['data'], EmbedProps['questions']];
|
21
|
+
|
19
22
|
class FetcherController {
|
20
23
|
host: EmbedHost;
|
21
24
|
|
22
25
|
private _fetching = false;
|
26
|
+
private _vouch: EmbedProps['data'];
|
23
27
|
|
24
28
|
set fetching(value) {
|
25
29
|
if (this._fetching !== value) {
|
@@ -34,51 +38,70 @@ class FetcherController {
|
|
34
38
|
private getVouch = async (env: Environment, apiKey: string, vouchId: string) => {
|
35
39
|
const { embedApiUrl } = getEnvUrls(env);
|
36
40
|
|
37
|
-
const
|
38
|
-
|
39
|
-
headers: [['X-Api-Key', apiKey]]
|
40
|
-
}).then((response) => {
|
41
|
-
this.host.dispatchEvent(new CustomEvent('vouch:loaded', { detail: vouchId }));
|
42
|
-
return response.json();
|
43
|
-
});
|
44
|
-
|
45
|
-
// HACK: trigger another fetch after we received the data to update the cache in the background
|
46
|
-
fetch(`${embedApiUrl}/vouches/${vouchId}`, {
|
41
|
+
const cacheCheck = uuidv4();
|
42
|
+
const res = await fetch(`${embedApiUrl}/vouches/${vouchId}`, {
|
47
43
|
method: 'GET',
|
48
44
|
headers: [
|
49
45
|
['X-Api-Key', apiKey],
|
50
|
-
['Cache-
|
46
|
+
['X-Cache-Check', cacheCheck]
|
51
47
|
]
|
52
48
|
});
|
53
49
|
|
50
|
+
const vouch = await res.json();
|
51
|
+
this.host.dispatchEvent(new CustomEvent('vouch:loaded', { detail: vouch?.id }));
|
52
|
+
|
53
|
+
// HACK: we're currently using API Gateway caching on the embed API without any invalidation logic,
|
54
|
+
// so to ensure that the cache stays up to date, whenever we detect a cache hit we trigger another
|
55
|
+
// API call with the `Cache-Control` header which will re-fill the cache
|
56
|
+
const resCacheCheck = res?.headers?.get('X-Cache-Check');
|
57
|
+
if (resCacheCheck !== cacheCheck) {
|
58
|
+
fetch(`${embedApiUrl}/vouches/${vouchId}`, {
|
59
|
+
method: 'GET',
|
60
|
+
headers: [
|
61
|
+
['X-Api-Key', apiKey],
|
62
|
+
['Cache-Control', 'max-age=0']
|
63
|
+
]
|
64
|
+
});
|
65
|
+
}
|
66
|
+
|
54
67
|
return vouch;
|
55
68
|
};
|
56
69
|
|
57
70
|
private getTemplate = async (env: Environment, apiKey: string, templateId: string) => {
|
58
71
|
const { embedApiUrl } = getEnvUrls(env);
|
59
72
|
|
60
|
-
const
|
61
|
-
|
62
|
-
headers: [['X-Api-Key', apiKey]]
|
63
|
-
}).then((response) => response.json());
|
64
|
-
|
65
|
-
// HACK: trigger another fetch after we received the data to update the cache in the background
|
66
|
-
fetch(`${embedApiUrl}/templates/${templateId}`, {
|
73
|
+
const cacheCheck = uuidv4();
|
74
|
+
const res = await fetch(`${embedApiUrl}/templates/${templateId}`, {
|
67
75
|
method: 'GET',
|
68
76
|
headers: [
|
69
77
|
['X-Api-Key', apiKey],
|
70
|
-
['Cache-
|
78
|
+
['X-Cache-Check', cacheCheck]
|
71
79
|
]
|
72
80
|
});
|
81
|
+
const template = await res.json();
|
82
|
+
|
83
|
+
// HACK: we're currently using API Gateway caching on the embed API without any invalidation logic,
|
84
|
+
// so to ensure that the cache stays up to date, whenever we detect a cache hit we trigger another
|
85
|
+
// API call with the `Cache-Control` header which will re-fill the cache
|
86
|
+
const resCacheCheck = res?.headers?.get('X-Cache-Check');
|
87
|
+
if (resCacheCheck !== cacheCheck) {
|
88
|
+
fetch(`${embedApiUrl}/templates/${templateId}`, {
|
89
|
+
method: 'GET',
|
90
|
+
headers: [
|
91
|
+
['X-Api-Key', apiKey],
|
92
|
+
['Cache-Control', 'max-age=0']
|
93
|
+
]
|
94
|
+
});
|
95
|
+
}
|
73
96
|
|
74
97
|
return template;
|
75
98
|
};
|
76
99
|
|
77
100
|
constructor(host: EmbedHost) {
|
78
101
|
this.host = host;
|
79
|
-
new Task<
|
102
|
+
new Task<FetchTaskDeps, void>(
|
80
103
|
this.host,
|
81
|
-
async ([env, apiKey, data, vouchId, templateId]:
|
104
|
+
async ([env, apiKey, data, vouchId, templateId]: FetchTaskDeps) => {
|
82
105
|
try {
|
83
106
|
host.vouch = undefined;
|
84
107
|
host.template = undefined;
|
@@ -89,7 +112,7 @@ class FetcherController {
|
|
89
112
|
this.fetching = true;
|
90
113
|
template = await this.getTemplate(env, apiKey, templateId);
|
91
114
|
}
|
92
|
-
|
115
|
+
this._vouch = data;
|
93
116
|
host.template = template ?? data?.settings?.template?.instance;
|
94
117
|
} else if (vouchId) {
|
95
118
|
this.fetching = true;
|
@@ -98,7 +121,7 @@ class FetcherController {
|
|
98
121
|
this.getVouch(env, apiKey, vouchId),
|
99
122
|
templateId ? this.getTemplate(env, apiKey, templateId) : null
|
100
123
|
]);
|
101
|
-
|
124
|
+
this._vouch = vouch;
|
102
125
|
host.template = template ?? vouch?.settings?.template?.instance;
|
103
126
|
}
|
104
127
|
} finally {
|
@@ -107,6 +130,22 @@ class FetcherController {
|
|
107
130
|
},
|
108
131
|
() => [host.env, host.apiKey, host.data, host.vouchId, host.templateId]
|
109
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
|
+
);
|
110
149
|
}
|
111
150
|
}
|
112
151
|
|
@@ -1,18 +1,20 @@
|
|
1
|
+
import { TEMPLATE_VERSION } from '@vouchfor/canvas-video';
|
1
2
|
import { v4 as uuidv4 } from 'uuid';
|
2
3
|
|
3
4
|
import type { Embed } from '..';
|
4
5
|
import type { VideoEventDetail } from '@vouchfor/media-player';
|
5
6
|
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
6
7
|
|
8
|
+
import packageJson from '../../../../package.json';
|
7
9
|
import { getEnvUrls } from '~/utils/env';
|
8
10
|
|
9
|
-
const
|
11
|
+
const MINIMUM_SEND_THRESHOLD = 1;
|
10
12
|
|
11
13
|
type EmbedHost = ReactiveControllerHost & Embed;
|
12
14
|
|
13
15
|
type TrackingEvent = 'VOUCH_LOADED' | 'VOUCH_RESPONSE_VIEWED' | 'VIDEO_PLAYED' | 'VIDEO_STREAMED';
|
14
16
|
type TrackingPayload = {
|
15
|
-
vouchId
|
17
|
+
vouchId?: string;
|
16
18
|
answerId?: string;
|
17
19
|
streamStart?: number;
|
18
20
|
streamEnd?: number;
|
@@ -36,21 +38,23 @@ class TrackingController implements ReactiveController {
|
|
36
38
|
private _hasPlayed = false;
|
37
39
|
private _hasLoaded: BooleanMap = {};
|
38
40
|
private _answersViewed: BooleanMap = {};
|
39
|
-
private
|
40
|
-
private
|
41
|
+
private _streamStartTime: TimeMap = {};
|
42
|
+
private _streamLatestTime: TimeMap = {};
|
43
|
+
private _currentlyPlayingVideo: VideoEventDetail | null = null;
|
41
44
|
|
42
45
|
constructor(host: EmbedHost) {
|
43
46
|
this.host = host;
|
44
47
|
host.addController(this);
|
45
48
|
}
|
46
49
|
|
47
|
-
private _findVouchId() {
|
48
|
-
if (
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
return this.host.
|
50
|
+
private _findVouchId(payload?: TrackingPayload) {
|
51
|
+
if (payload && 'vouchId' in payload) {
|
52
|
+
return payload.vouchId;
|
53
|
+
}
|
54
|
+
if (this.host.vouch) {
|
55
|
+
return this.host.vouch.id;
|
53
56
|
}
|
57
|
+
return null;
|
54
58
|
}
|
55
59
|
|
56
60
|
private _createVisitor = (visitorId: string) => {
|
@@ -124,20 +128,30 @@ class TrackingController implements ReactiveController {
|
|
124
128
|
screenWidth: window.screen.width,
|
125
129
|
referrer: document.referrer,
|
126
130
|
currentUrl: location.href,
|
131
|
+
embedVersion: packageJson.version,
|
132
|
+
templateVersion: TEMPLATE_VERSION,
|
127
133
|
...utmParams
|
128
134
|
};
|
129
135
|
};
|
130
136
|
|
131
|
-
private _sendTrackingEvent = (event: TrackingEvent, payload
|
137
|
+
private _sendTrackingEvent = (event: TrackingEvent, payload?: TrackingPayload) => {
|
138
|
+
const vouchId = this._findVouchId(payload);
|
139
|
+
|
140
|
+
if (!vouchId || this.host.disableTracking) {
|
141
|
+
return;
|
142
|
+
}
|
143
|
+
|
132
144
|
const { publicApiUrl } = getEnvUrls(this.host.env);
|
133
145
|
const { client, tab, request, visitor } = this._getUids();
|
134
146
|
|
135
|
-
// Don't send tracking if we don't have a source
|
136
147
|
navigator.sendBeacon(
|
137
|
-
`${publicApiUrl}/api/events`,
|
148
|
+
`${publicApiUrl}/api/v2/events`,
|
138
149
|
JSON.stringify({
|
139
150
|
event,
|
140
|
-
payload
|
151
|
+
payload: {
|
152
|
+
...payload,
|
153
|
+
vouchId
|
154
|
+
},
|
141
155
|
context: {
|
142
156
|
'x-uid-client': client,
|
143
157
|
'x-uid-tab': tab,
|
@@ -149,6 +163,26 @@ class TrackingController implements ReactiveController {
|
|
149
163
|
);
|
150
164
|
};
|
151
165
|
|
166
|
+
private _streamEnded = () => {
|
167
|
+
if (this._currentlyPlayingVideo) {
|
168
|
+
const { id, key } = this._currentlyPlayingVideo;
|
169
|
+
// Don't send a tracking event when seeking backwards
|
170
|
+
if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
|
171
|
+
// Send a video streamed event any time the stream ends to capture the time between starting
|
172
|
+
// the video and the video stopping for any reason (pausing, deleting the embed node or closing the browser)
|
173
|
+
this._sendTrackingEvent('VIDEO_STREAMED', {
|
174
|
+
answerId: id,
|
175
|
+
streamStart: this._streamStartTime[key],
|
176
|
+
streamEnd: this._streamLatestTime[key]
|
177
|
+
});
|
178
|
+
}
|
179
|
+
|
180
|
+
// Make sure these events are only sent once by deleting the start and latest times
|
181
|
+
delete this._streamStartTime[key];
|
182
|
+
delete this._streamLatestTime[key];
|
183
|
+
}
|
184
|
+
};
|
185
|
+
|
152
186
|
private _handleVouchLoaded = ({ detail: vouchId }: CustomEvent<string>) => {
|
153
187
|
if (!vouchId) {
|
154
188
|
return;
|
@@ -156,91 +190,84 @@ class TrackingController implements ReactiveController {
|
|
156
190
|
|
157
191
|
// Only send loaded event once per session
|
158
192
|
if (!this._hasLoaded[vouchId]) {
|
159
|
-
this._sendTrackingEvent('VOUCH_LOADED', {
|
160
|
-
vouchId
|
161
|
-
});
|
193
|
+
this._sendTrackingEvent('VOUCH_LOADED', { vouchId });
|
162
194
|
this._hasLoaded[vouchId] = true;
|
163
195
|
}
|
164
196
|
};
|
165
197
|
|
166
198
|
private _handlePlay = () => {
|
167
|
-
const vouchId = this._findVouchId();
|
168
|
-
|
169
|
-
if (!vouchId) {
|
170
|
-
return;
|
171
|
-
}
|
172
|
-
|
173
199
|
// Only send the video played event once per session
|
174
200
|
if (!this._hasPlayed) {
|
175
201
|
this._sendTrackingEvent('VIDEO_PLAYED', {
|
176
|
-
vouchId,
|
177
202
|
streamStart: this.host.currentTime
|
178
203
|
});
|
179
204
|
this._hasPlayed = true;
|
180
205
|
}
|
181
206
|
};
|
182
207
|
|
183
|
-
private _handleVideoPlay = ({ detail: { id, node } }: CustomEvent<VideoEventDetail>) => {
|
184
|
-
const vouchId = this._findVouchId();
|
185
|
-
if (!vouchId) {
|
186
|
-
return;
|
187
|
-
}
|
208
|
+
private _handleVideoPlay = ({ detail: { id, key, node } }: CustomEvent<VideoEventDetail>) => {
|
188
209
|
// Only increment play count once per session
|
189
|
-
if (!this._answersViewed[
|
210
|
+
if (!this._answersViewed[key]) {
|
190
211
|
this._sendTrackingEvent('VOUCH_RESPONSE_VIEWED', {
|
191
|
-
vouchId,
|
192
212
|
answerId: id
|
193
213
|
});
|
194
|
-
this._answersViewed[
|
214
|
+
this._answersViewed[key] = true;
|
195
215
|
}
|
196
|
-
this._streamedTime[id] = node.currentTime;
|
197
|
-
this._streamedPrevTimestamp[id] = Date.now();
|
198
|
-
};
|
199
216
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
return;
|
217
|
+
if (!this._streamStartTime[key]) {
|
218
|
+
this._streamStartTime[key] = node.currentTime;
|
219
|
+
this._streamLatestTime[key] = node.currentTime;
|
204
220
|
}
|
205
|
-
|
221
|
+
};
|
222
|
+
|
223
|
+
private _handleVideoTimeUpdate = ({ detail: { id, key, node } }: CustomEvent<VideoEventDetail>) => {
|
206
224
|
if (
|
225
|
+
// We only want to count any time that the video is actually playing
|
207
226
|
!this.host.paused &&
|
208
|
-
// Only
|
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
|
227
|
+
// Only update the latest time if this event fires for the currently active video
|
228
|
+
id === this.host.scene?.video?.id
|
212
229
|
) {
|
230
|
+
this._currentlyPlayingVideo = { id, key, node };
|
231
|
+
this._streamLatestTime[key] = node.currentTime;
|
232
|
+
}
|
233
|
+
};
|
234
|
+
|
235
|
+
private _handleVideoPause = ({ detail: { id, key } }: CustomEvent<VideoEventDetail>) => {
|
236
|
+
if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
|
213
237
|
this._sendTrackingEvent('VIDEO_STREAMED', {
|
214
|
-
vouchId,
|
215
238
|
answerId: id,
|
216
|
-
streamStart: this.
|
217
|
-
streamEnd:
|
239
|
+
streamStart: this._streamStartTime[key],
|
240
|
+
streamEnd: this._streamLatestTime[key]
|
218
241
|
});
|
219
|
-
this._streamedTime[id] = node.currentTime;
|
220
|
-
this._streamedPrevTimestamp[id] = currentTimestamp;
|
221
242
|
}
|
243
|
+
delete this._streamStartTime[key];
|
244
|
+
delete this._streamLatestTime[key];
|
222
245
|
};
|
223
246
|
|
224
|
-
private
|
225
|
-
|
226
|
-
|
227
|
-
|
247
|
+
private _pageUnloading = () => {
|
248
|
+
this._streamEnded();
|
249
|
+
// This will try to send the same stream event again so we delete the start and latest
|
250
|
+
// time in stream ended so that there is no times to send and the pause event does nothing
|
251
|
+
this.host.pause();
|
252
|
+
};
|
253
|
+
|
254
|
+
private _handleVisibilityChange = () => {
|
255
|
+
if (document.visibilityState === 'hidden') {
|
256
|
+
this._pageUnloading();
|
228
257
|
}
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
this.
|
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];
|
258
|
+
};
|
259
|
+
|
260
|
+
private _handlePageHide = () => {
|
261
|
+
this._pageUnloading();
|
240
262
|
};
|
241
263
|
|
242
264
|
hostConnected() {
|
243
265
|
requestAnimationFrame(() => {
|
266
|
+
if ('onvisibilitychange' in document) {
|
267
|
+
document.addEventListener('visibilitychange', this._handleVisibilityChange);
|
268
|
+
} else {
|
269
|
+
window.addEventListener('pagehide', this._handlePageHide);
|
270
|
+
}
|
244
271
|
this.host.addEventListener('vouch:loaded', this._handleVouchLoaded);
|
245
272
|
this.host.mediaPlayer?.addEventListener('play', this._handlePlay);
|
246
273
|
this.host.mediaPlayer?.addEventListener('video:play', this._handleVideoPlay);
|
@@ -250,6 +277,12 @@ class TrackingController implements ReactiveController {
|
|
250
277
|
}
|
251
278
|
|
252
279
|
hostDisconnected() {
|
280
|
+
this._streamEnded();
|
281
|
+
if ('onvisibilitychange' in document) {
|
282
|
+
document.removeEventListener('visibilitychange', this._handleVisibilityChange);
|
283
|
+
} else {
|
284
|
+
window.removeEventListener('pagehide', this._handlePageHide);
|
285
|
+
}
|
253
286
|
this.host.removeEventListener('vouch:loaded', this._handleVouchLoaded);
|
254
287
|
this.host.mediaPlayer?.removeEventListener('play', this._handlePlay);
|
255
288
|
this.host.mediaPlayer?.removeEventListener('video:play', this._handleVideoPlay);
|
@@ -1,9 +1,9 @@
|
|
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';
|
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';
|
@@ -17,21 +17,34 @@ import '@vouchfor/media-player';
|
|
17
17
|
type EmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload' | 'autoplay' | 'controls'> & {
|
18
18
|
env: Environment;
|
19
19
|
apiKey: string;
|
20
|
+
disableTracking?: boolean;
|
20
21
|
trackingSource?: string;
|
21
22
|
vouchId?: string;
|
22
23
|
templateId?: string;
|
24
|
+
// Index of the questions to include starting from 1
|
25
|
+
questions?: number[];
|
23
26
|
};
|
24
27
|
|
25
28
|
@customElement('vouch-embed')
|
26
29
|
class Embed extends LitElement {
|
30
|
+
static styles = [
|
31
|
+
css`
|
32
|
+
:host {
|
33
|
+
display: flex;
|
34
|
+
}
|
35
|
+
`
|
36
|
+
];
|
37
|
+
|
27
38
|
private _mediaPlayerRef: Ref<MediaPlayer> = createRef();
|
28
39
|
|
29
|
-
@property({ type: Object
|
40
|
+
@property({ type: Object }) data: EmbedProps['data'];
|
30
41
|
@property({ type: String }) vouchId: EmbedProps['vouchId'];
|
31
42
|
@property({ type: String }) templateId: EmbedProps['templateId'];
|
43
|
+
@property({ type: Array }) questions: EmbedProps['questions'];
|
32
44
|
|
33
45
|
@property({ type: String }) env: EmbedProps['env'] = 'prod';
|
34
46
|
@property({ type: String }) apiKey: EmbedProps['apiKey'] = '';
|
47
|
+
@property({ type: Boolean }) disableTracking: EmbedProps['disableTracking'] = false;
|
35
48
|
@property({ type: String }) trackingSource: EmbedProps['trackingSource'] = 'embed';
|
36
49
|
|
37
50
|
@property({ type: Array }) controls: EmbedProps['controls'];
|
@@ -57,6 +70,7 @@ class Embed extends LitElement {
|
|
57
70
|
'waiting',
|
58
71
|
|
59
72
|
'video:loadeddata',
|
73
|
+
'video:seeking',
|
60
74
|
'video:seeked',
|
61
75
|
'video:play',
|
62
76
|
'video:playing',
|
@@ -146,6 +160,10 @@ class Embed extends LitElement {
|
|
146
160
|
return this._mediaPlayerRef.value?.scenes ?? [];
|
147
161
|
}
|
148
162
|
|
163
|
+
get sceneConfig(): Scenes | null {
|
164
|
+
return this._mediaPlayerRef.value?.sceneConfig ?? null;
|
165
|
+
}
|
166
|
+
|
149
167
|
get videoState() {
|
150
168
|
return this._mediaPlayerRef.value?.videoState;
|
151
169
|
}
|
@@ -168,7 +186,7 @@ class Embed extends LitElement {
|
|
168
186
|
|
169
187
|
render() {
|
170
188
|
return html`
|
171
|
-
<vmp-
|
189
|
+
<vmp-media-player
|
172
190
|
${ref(this._mediaPlayerRef)}
|
173
191
|
${this.eventController.register()}
|
174
192
|
?autoplay=${this.autoplay}
|
@@ -178,7 +196,7 @@ class Embed extends LitElement {
|
|
178
196
|
aspectRatio=${ifDefined(this.aspectRatio)}
|
179
197
|
preload=${ifDefined(this.preload)}
|
180
198
|
.controls=${this.controls}
|
181
|
-
></vmp-
|
199
|
+
></vmp-media-player>
|
182
200
|
`;
|
183
201
|
}
|
184
202
|
}
|
File without changes
|
File without changes
|
File without changes
|