@vouchfor/embeds 0.0.0-experiment.cf82dbe → 0.0.0-experiment.d0b05c2
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/embeds.js +1039 -7
- package/dist/es/embeds.js.map +1 -1
- package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +20 -0
- package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +36 -0
- package/dist/es/src/components/DialogEmbed/index.d.ts +37 -0
- package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +16 -0
- package/dist/es/src/components/PlayerEmbed/controllers/fetcher.d.ts +3 -2
- package/dist/es/src/components/PlayerEmbed/controllers/tracking/index.d.ts +4 -2
- package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +4 -3
- package/dist/es/src/components/PlayerEmbed/index.d.ts +18 -13
- package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +4 -2
- package/dist/es/src/components/PlayerEmbed/tests/media-data.d.ts +19 -0
- package/dist/es/src/index.d.ts +1 -0
- package/dist/iife/dialog-embed/embed.iife.js +4079 -0
- package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
- package/dist/iife/embeds.iife.js +2890 -383
- package/dist/iife/embeds.iife.js.map +1 -1
- package/dist/iife/player-embed/embed.iife.js +3941 -0
- package/dist/iife/player-embed/embed.iife.js.map +1 -0
- package/package.json +49 -38
- package/src/components/DialogEmbed/Dialog.stories.ts +91 -0
- package/src/components/DialogEmbed/DialogOverlay.ts +131 -0
- package/src/components/DialogEmbed/DialogPortal.ts +126 -0
- package/src/components/DialogEmbed/index.ts +97 -0
- package/src/components/PlayerEmbed/MultiEmbed.stories.ts +135 -0
- package/src/components/PlayerEmbed/PlayerEmbed.stories.ts +18 -2
- package/src/components/PlayerEmbed/controllers/event-forwarder.ts +2 -1
- package/src/components/PlayerEmbed/controllers/tracking/index.ts +10 -10
- package/src/components/PlayerEmbed/controllers/tracking/utils.ts +1 -1
- package/src/components/PlayerEmbed/index.ts +42 -20
- package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +14 -7
- package/src/components/PlayerEmbed/tests/data.ts +121 -77
- package/src/components/PlayerEmbed/tests/media-data.ts +22 -0
- package/src/index.ts +1 -0
- package/dist/es/browser-ff061c90.js +0 -433
- package/dist/es/browser-ff061c90.js.map +0 -1
- package/dist/es/index-b238c0dc.js +0 -9980
- package/dist/es/index-b238c0dc.js.map +0 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
|
|
4
|
+
import type { PlayerEmbedProps } from '.';
|
|
5
|
+
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
6
|
+
|
|
7
|
+
import '.';
|
|
8
|
+
|
|
9
|
+
type MultiEmbedArgs = PlayerEmbedProps & {
|
|
10
|
+
apiKey1?: string;
|
|
11
|
+
apiKey2?: string;
|
|
12
|
+
apiKey3?: string;
|
|
13
|
+
vouchId1?: string;
|
|
14
|
+
vouchId2?: string;
|
|
15
|
+
vouchId3?: string;
|
|
16
|
+
showVouch?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const _MultiEmbed = ({
|
|
20
|
+
vouchId1,
|
|
21
|
+
vouchId2,
|
|
22
|
+
vouchId3,
|
|
23
|
+
templateId,
|
|
24
|
+
questions,
|
|
25
|
+
preload,
|
|
26
|
+
autoplay,
|
|
27
|
+
env,
|
|
28
|
+
apiKey1,
|
|
29
|
+
apiKey2,
|
|
30
|
+
apiKey3,
|
|
31
|
+
controls,
|
|
32
|
+
aspectRatio
|
|
33
|
+
}: MultiEmbedArgs) => {
|
|
34
|
+
return html`
|
|
35
|
+
<div style="height: 33vh">
|
|
36
|
+
<vouch-embed-player
|
|
37
|
+
env=${ifDefined(env)}
|
|
38
|
+
apiKey=${ifDefined(apiKey1)}
|
|
39
|
+
vouchId=${ifDefined(vouchId1)}
|
|
40
|
+
templateId=${ifDefined(templateId)}
|
|
41
|
+
.questions=${questions}
|
|
42
|
+
.controls=${controls}
|
|
43
|
+
?autoplay=${autoplay}
|
|
44
|
+
preload=${ifDefined(preload)}
|
|
45
|
+
aspectRatio=${ifDefined(aspectRatio)}
|
|
46
|
+
@error=${console.log}
|
|
47
|
+
></vouch-embed-player>
|
|
48
|
+
</div>
|
|
49
|
+
<div style="height: 33vh">
|
|
50
|
+
<vouch-embed-player
|
|
51
|
+
env=${ifDefined(env)}
|
|
52
|
+
apiKey=${ifDefined(apiKey2)}
|
|
53
|
+
vouchId=${ifDefined(vouchId2)}
|
|
54
|
+
templateId=${ifDefined(templateId)}
|
|
55
|
+
.questions=${questions}
|
|
56
|
+
.controls=${controls}
|
|
57
|
+
?autoplay=${autoplay}
|
|
58
|
+
preload=${ifDefined(preload)}
|
|
59
|
+
aspectRatio=${ifDefined(aspectRatio)}
|
|
60
|
+
@error=${console.log}
|
|
61
|
+
></vouch-embed-player>
|
|
62
|
+
</div>
|
|
63
|
+
<div style="height: 33vh">
|
|
64
|
+
<vouch-embed-player
|
|
65
|
+
env=${ifDefined(env)}
|
|
66
|
+
apiKey=${ifDefined(apiKey3)}
|
|
67
|
+
vouchId=${ifDefined(vouchId3)}
|
|
68
|
+
templateId=${ifDefined(templateId)}
|
|
69
|
+
.questions=${questions}
|
|
70
|
+
.controls=${controls}
|
|
71
|
+
?autoplay=${autoplay}
|
|
72
|
+
preload=${ifDefined(preload)}
|
|
73
|
+
aspectRatio=${ifDefined(aspectRatio)}
|
|
74
|
+
@error=${console.log}
|
|
75
|
+
></vouch-embed-player>
|
|
76
|
+
</div>
|
|
77
|
+
`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// More on how to set up stories at: https://storybook.js.org/docs/web-components/writing-stories/introduction
|
|
81
|
+
const meta = {
|
|
82
|
+
title: 'Embeds',
|
|
83
|
+
tags: ['autodocs'],
|
|
84
|
+
render: (args) => _MultiEmbed(args),
|
|
85
|
+
component: 'vouch-embed-player'
|
|
86
|
+
} satisfies Meta<PlayerEmbedProps>;
|
|
87
|
+
|
|
88
|
+
type Story = StoryObj<MultiEmbedArgs>;
|
|
89
|
+
|
|
90
|
+
const MultiPlayer: Story = {
|
|
91
|
+
args: {
|
|
92
|
+
env: 'dev',
|
|
93
|
+
apiKey1: 'TVik9uTMgE-PD25UTHIS6gyl0hMBWC7AT4dkpdlLBT4VIfDWZJrQiCk6Ak7m1',
|
|
94
|
+
vouchId1: '6JQEIPeStt',
|
|
95
|
+
apiKey2: 'TVik9uTMgE-PD25UTHIS6gyl0hMBWC7AT4dkpdlLBT4VIfDWZJrQiCk6Ak7m1',
|
|
96
|
+
vouchId2: '6JQEIPeStt',
|
|
97
|
+
apiKey3: 'TVik9uTMgE-PD25UTHIS6gyl0hMBWC7AT4dkpdlLBT4VIfDWZJrQiCk6Ak7m1',
|
|
98
|
+
vouchId3: '6JQEIPeStt',
|
|
99
|
+
templateId: '357fc118-e179-4171-9446-ff2b8e9d1b29',
|
|
100
|
+
questions: [],
|
|
101
|
+
aspectRatio: 0,
|
|
102
|
+
preload: 'none',
|
|
103
|
+
autoplay: false,
|
|
104
|
+
controls: [
|
|
105
|
+
'progress',
|
|
106
|
+
'play-large',
|
|
107
|
+
'navigation',
|
|
108
|
+
'play',
|
|
109
|
+
'volume',
|
|
110
|
+
'current-time',
|
|
111
|
+
'duration',
|
|
112
|
+
'speed',
|
|
113
|
+
'captions',
|
|
114
|
+
'fullscreen',
|
|
115
|
+
'preview',
|
|
116
|
+
'languages'
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
argTypes: {
|
|
120
|
+
env: {
|
|
121
|
+
control: 'radio',
|
|
122
|
+
options: ['local', 'dev', 'staging', 'prod']
|
|
123
|
+
},
|
|
124
|
+
preload: {
|
|
125
|
+
control: 'radio',
|
|
126
|
+
options: ['auto', 'none']
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
parameters: {
|
|
130
|
+
layout: 'fullscreen'
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default meta;
|
|
135
|
+
export { MultiPlayer };
|
|
@@ -19,7 +19,8 @@ const _PlayerEmbed = ({
|
|
|
19
19
|
env,
|
|
20
20
|
apiKey,
|
|
21
21
|
controls,
|
|
22
|
-
aspectRatio
|
|
22
|
+
aspectRatio,
|
|
23
|
+
senderId
|
|
23
24
|
}: PlayerEmbedArgs) => {
|
|
24
25
|
return html`
|
|
25
26
|
<div style="height: 100vh">
|
|
@@ -33,6 +34,7 @@ const _PlayerEmbed = ({
|
|
|
33
34
|
?autoplay=${autoplay}
|
|
34
35
|
preload=${ifDefined(preload)}
|
|
35
36
|
aspectRatio=${ifDefined(aspectRatio)}
|
|
37
|
+
senderId=${ifDefined(senderId)}
|
|
36
38
|
@error=${console.log}
|
|
37
39
|
></vouch-embed-player>
|
|
38
40
|
</div>
|
|
@@ -58,7 +60,21 @@ const Player: Story = {
|
|
|
58
60
|
questions: [],
|
|
59
61
|
aspectRatio: 0,
|
|
60
62
|
preload: 'none',
|
|
61
|
-
autoplay: false
|
|
63
|
+
autoplay: false,
|
|
64
|
+
controls: [
|
|
65
|
+
'progress',
|
|
66
|
+
'play-large',
|
|
67
|
+
'navigation',
|
|
68
|
+
'play',
|
|
69
|
+
'volume',
|
|
70
|
+
'current-time',
|
|
71
|
+
'duration',
|
|
72
|
+
'speed',
|
|
73
|
+
'captions',
|
|
74
|
+
'fullscreen',
|
|
75
|
+
'preview',
|
|
76
|
+
'languages'
|
|
77
|
+
]
|
|
62
78
|
},
|
|
63
79
|
argTypes: {
|
|
64
80
|
env: {
|
|
@@ -2,6 +2,7 @@ import { createRef, ref } from 'lit/directives/ref.js';
|
|
|
2
2
|
|
|
3
3
|
import type { PlayerEmbed } from '..';
|
|
4
4
|
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
5
|
+
import type { DirectiveResult } from 'lit/directive.js';
|
|
5
6
|
import type { Ref } from 'lit/directives/ref.js';
|
|
6
7
|
|
|
7
8
|
import { forwardEvent } from '~/utils/events';
|
|
@@ -21,7 +22,7 @@ class EventForwardController implements ReactiveController {
|
|
|
21
22
|
host.addController(this);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
register() {
|
|
25
|
+
register(): DirectiveResult {
|
|
25
26
|
return ref(this._forwardElementRef);
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PlayerEmbed } from '../..';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MediaEventDetail } from '@vouchfor/media-player';
|
|
3
3
|
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
4
4
|
|
|
5
5
|
import { findVouchId, getReportingMetadata, getUids } from './utils';
|
|
@@ -15,6 +15,7 @@ type TrackingPayload = {
|
|
|
15
15
|
answerId?: string;
|
|
16
16
|
streamStart?: number;
|
|
17
17
|
streamEnd?: number;
|
|
18
|
+
senderId?: string;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
type BatchEvent = {
|
|
@@ -41,7 +42,7 @@ class TrackingController implements ReactiveController {
|
|
|
41
42
|
private _answersViewed: BooleanMap = {};
|
|
42
43
|
private _streamStartTime: TimeMap = {};
|
|
43
44
|
private _streamLatestTime: TimeMap = {};
|
|
44
|
-
private _currentlyPlayingVideo:
|
|
45
|
+
private _currentlyPlayingVideo: MediaEventDetail | null = null;
|
|
45
46
|
|
|
46
47
|
constructor(host: PlayerEmbedHost) {
|
|
47
48
|
this.host = host;
|
|
@@ -59,6 +60,7 @@ class TrackingController implements ReactiveController {
|
|
|
59
60
|
event,
|
|
60
61
|
payload: {
|
|
61
62
|
...payload,
|
|
63
|
+
senderId: this.host.senderId,
|
|
62
64
|
vouchId,
|
|
63
65
|
time: new Date().toISOString()
|
|
64
66
|
}
|
|
@@ -127,14 +129,12 @@ class TrackingController implements ReactiveController {
|
|
|
127
129
|
private _handlePlay = () => {
|
|
128
130
|
// Only send the video played event once per session
|
|
129
131
|
if (!this._hasPlayed) {
|
|
130
|
-
this._createTrackingEvent('VIDEO_PLAYED', {
|
|
131
|
-
streamStart: this.host.currentTime
|
|
132
|
-
});
|
|
132
|
+
this._createTrackingEvent('VIDEO_PLAYED', { streamStart: this.host.currentTime });
|
|
133
133
|
this._hasPlayed = true;
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
|
137
|
-
private _handleVideoPlay = ({ detail: { id, key } }: CustomEvent<
|
|
137
|
+
private _handleVideoPlay = ({ detail: { id, key } }: CustomEvent<MediaEventDetail>) => {
|
|
138
138
|
// Only increment play count once per session
|
|
139
139
|
if (!this._answersViewed[key]) {
|
|
140
140
|
this._createTrackingEvent('VOUCH_RESPONSE_VIEWED', {
|
|
@@ -144,12 +144,12 @@ class TrackingController implements ReactiveController {
|
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
private _handleVideoTimeUpdate = ({ detail: { id, key, node } }: CustomEvent<
|
|
147
|
+
private _handleVideoTimeUpdate = ({ detail: { id, key, node } }: CustomEvent<MediaEventDetail>) => {
|
|
148
148
|
if (
|
|
149
149
|
// We only want to count any time that the video is actually playing
|
|
150
|
-
!this.host.paused
|
|
150
|
+
!this.host.paused
|
|
151
151
|
// Only update the latest time if this event fires for the currently active video
|
|
152
|
-
id === this.host.scene?.video?.id
|
|
152
|
+
// id === this.host.scene?.video?.id
|
|
153
153
|
) {
|
|
154
154
|
this._currentlyPlayingVideo = { id, key, node };
|
|
155
155
|
this._streamLatestTime[key] = node.currentTime;
|
|
@@ -161,7 +161,7 @@ class TrackingController implements ReactiveController {
|
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
-
private _handleVideoPause = ({ detail: { id, key } }: CustomEvent<
|
|
164
|
+
private _handleVideoPause = ({ detail: { id, key } }: CustomEvent<MediaEventDetail>) => {
|
|
165
165
|
if (this._streamLatestTime[key] > this._streamStartTime[key] + MINIMUM_SEND_THRESHOLD) {
|
|
166
166
|
this._createTrackingEvent('VIDEO_STREAMED', {
|
|
167
167
|
answerId: id,
|
|
@@ -2,7 +2,7 @@ import { TEMPLATE_VERSION } from '@vouchfor/canvas-video';
|
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
|
|
4
4
|
import type { TrackingPayload } from '.';
|
|
5
|
-
import type { Vouch } from '@vouchfor/
|
|
5
|
+
import type { Vouch } from '@vouchfor/video-utils';
|
|
6
6
|
import type { Environment } from '~/utils/env';
|
|
7
7
|
|
|
8
8
|
import packageJson from '~/../package.json';
|
|
@@ -3,9 +3,10 @@ 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 {
|
|
6
|
+
import type { TemplateInstance } from '@vouchfor/canvas-video';
|
|
7
7
|
import type { MediaPlayer, MediaPlayerProps } from '@vouchfor/media-player';
|
|
8
|
-
import type {
|
|
8
|
+
import type { Vouch } from '@vouchfor/video-utils';
|
|
9
|
+
import type { PropertyValueMap } from 'lit';
|
|
9
10
|
import type { Environment } from '~/utils/env';
|
|
10
11
|
|
|
11
12
|
import { EventForwardController } from './controllers/event-forwarder';
|
|
@@ -14,7 +15,8 @@ import { TrackingController } from './controllers/tracking';
|
|
|
14
15
|
|
|
15
16
|
import '@vouchfor/media-player';
|
|
16
17
|
|
|
17
|
-
type PlayerEmbedProps = Pick<MediaPlayerProps, '
|
|
18
|
+
type PlayerEmbedProps = Pick<MediaPlayerProps, 'aspectRatio' | 'language' | 'preload' | 'autoplay' | 'controls'> & {
|
|
19
|
+
data?: Vouch;
|
|
18
20
|
env: Environment;
|
|
19
21
|
apiKey: string;
|
|
20
22
|
disableTracking?: boolean;
|
|
@@ -23,6 +25,7 @@ type PlayerEmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload
|
|
|
23
25
|
templateId?: string;
|
|
24
26
|
// Index of the questions to include starting from 1
|
|
25
27
|
questions?: number[];
|
|
28
|
+
senderId?: string;
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
@customElement('vouch-embed-player')
|
|
@@ -35,8 +38,6 @@ class PlayerEmbed extends LitElement {
|
|
|
35
38
|
`
|
|
36
39
|
];
|
|
37
40
|
|
|
38
|
-
private _mediaPlayerRef: Ref<MediaPlayer> = createRef();
|
|
39
|
-
|
|
40
41
|
@property({ type: Object }) data: PlayerEmbedProps['data'];
|
|
41
42
|
@property({ type: String }) vouchId: PlayerEmbedProps['vouchId'];
|
|
42
43
|
@property({ type: String }) templateId: PlayerEmbedProps['templateId'];
|
|
@@ -51,6 +52,8 @@ class PlayerEmbed extends LitElement {
|
|
|
51
52
|
@property({ type: String }) preload: PlayerEmbedProps['preload'] = 'auto';
|
|
52
53
|
@property({ type: Boolean }) autoplay: PlayerEmbedProps['autoplay'] = false;
|
|
53
54
|
@property({ type: Number }) aspectRatio: PlayerEmbedProps['aspectRatio'] = 0;
|
|
55
|
+
@property({ type: String }) language?: MediaPlayerProps['language'];
|
|
56
|
+
@property({ type: String }) senderId?: PlayerEmbedProps['senderId'];
|
|
54
57
|
|
|
55
58
|
private eventController = new EventForwardController(this, [
|
|
56
59
|
'durationchange',
|
|
@@ -63,10 +66,12 @@ class PlayerEmbed extends LitElement {
|
|
|
63
66
|
'playing',
|
|
64
67
|
'ratechange',
|
|
65
68
|
'scenechange',
|
|
69
|
+
'scenesupdate',
|
|
66
70
|
'seeking',
|
|
67
71
|
'seeked',
|
|
68
72
|
'timeupdate',
|
|
69
73
|
'volumechange',
|
|
74
|
+
'processing',
|
|
70
75
|
'waiting',
|
|
71
76
|
|
|
72
77
|
'video:loadeddata',
|
|
@@ -75,6 +80,7 @@ class PlayerEmbed extends LitElement {
|
|
|
75
80
|
'video:play',
|
|
76
81
|
'video:playing',
|
|
77
82
|
'video:pause',
|
|
83
|
+
'video:waiting',
|
|
78
84
|
'video:stalled',
|
|
79
85
|
'video:timeupdate',
|
|
80
86
|
'video:ended',
|
|
@@ -92,10 +98,16 @@ class PlayerEmbed extends LitElement {
|
|
|
92
98
|
return this._fetcherController.fetching;
|
|
93
99
|
}
|
|
94
100
|
|
|
101
|
+
private _mediaPlayerRef = createRef<MediaPlayer>();
|
|
102
|
+
|
|
95
103
|
get waiting() {
|
|
96
104
|
return this._mediaPlayerRef.value?.waiting;
|
|
97
105
|
}
|
|
98
106
|
|
|
107
|
+
get initialised() {
|
|
108
|
+
return this._mediaPlayerRef.value?.initialised;
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
get seeking() {
|
|
100
112
|
return this._mediaPlayerRef.value?.seeking;
|
|
101
113
|
}
|
|
@@ -152,20 +164,20 @@ class PlayerEmbed extends LitElement {
|
|
|
152
164
|
return this._mediaPlayerRef.value?.muted ?? false;
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
get scene(): Scene | null {
|
|
156
|
-
|
|
157
|
-
}
|
|
167
|
+
// get scene(): Scene | null {
|
|
168
|
+
// return this._mediaPlayerRef.value?.scene ?? null;
|
|
169
|
+
// }
|
|
158
170
|
|
|
159
|
-
get scenes(): Scene[] {
|
|
160
|
-
|
|
161
|
-
}
|
|
171
|
+
// get scenes(): Scene[] {
|
|
172
|
+
// return this._mediaPlayerRef.value?.scenes ?? [];
|
|
173
|
+
// }
|
|
162
174
|
|
|
163
|
-
get sceneConfig(): Scenes | null {
|
|
164
|
-
|
|
165
|
-
}
|
|
175
|
+
// get sceneConfig(): Scenes | null {
|
|
176
|
+
// return this._mediaPlayerRef.value?.sceneConfig ?? null;
|
|
177
|
+
// }
|
|
166
178
|
|
|
167
|
-
get
|
|
168
|
-
return this._mediaPlayerRef.value?.
|
|
179
|
+
get mediaState() {
|
|
180
|
+
return this._mediaPlayerRef.value?.mediaState;
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
get mediaPlayer() {
|
|
@@ -180,10 +192,14 @@ class PlayerEmbed extends LitElement {
|
|
|
180
192
|
this._mediaPlayerRef.value?.pause();
|
|
181
193
|
}
|
|
182
194
|
|
|
183
|
-
|
|
184
|
-
this._mediaPlayerRef.value?.
|
|
195
|
+
reset(time = 0, play = false) {
|
|
196
|
+
this._mediaPlayerRef.value?.reset(time, play);
|
|
185
197
|
}
|
|
186
198
|
|
|
199
|
+
// setScene(index: number) {
|
|
200
|
+
// this._mediaPlayerRef.value?.setScene(index);
|
|
201
|
+
// }
|
|
202
|
+
|
|
187
203
|
private _renderStyles() {
|
|
188
204
|
if (!this.aspectRatio) {
|
|
189
205
|
return html`
|
|
@@ -209,6 +225,13 @@ class PlayerEmbed extends LitElement {
|
|
|
209
225
|
return null;
|
|
210
226
|
}
|
|
211
227
|
|
|
228
|
+
protected willUpdate(changedProperties: PropertyValueMap<PlayerEmbedProps>) {
|
|
229
|
+
// If the vouch this embed is pointing to changes then reset the player
|
|
230
|
+
if (changedProperties.has('vouchId') && this.vouchId !== changedProperties.get('vouchId')) {
|
|
231
|
+
this.reset(0, false);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
212
235
|
render() {
|
|
213
236
|
return html`
|
|
214
237
|
${this._renderStyles()}
|
|
@@ -217,10 +240,9 @@ class PlayerEmbed extends LitElement {
|
|
|
217
240
|
${this.eventController.register()}
|
|
218
241
|
?autoplay=${this.autoplay}
|
|
219
242
|
?loading=${this.fetching}
|
|
220
|
-
.data=${this.vouch}
|
|
221
|
-
.template=${this.template}
|
|
222
243
|
aspectRatio=${ifDefined(this.aspectRatio)}
|
|
223
244
|
preload=${ifDefined(this.preload)}
|
|
245
|
+
language=${ifDefined(this.language)}
|
|
224
246
|
.controls=${this.controls}
|
|
225
247
|
></vmp-media-player>
|
|
226
248
|
`;
|
|
@@ -4,7 +4,7 @@ import { html } from 'lit';
|
|
|
4
4
|
import sinon from 'sinon';
|
|
5
5
|
|
|
6
6
|
import type { PlayerEmbed } from '../index.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { MediaMap } from '@vouchfor/media-player';
|
|
8
8
|
|
|
9
9
|
import { data } from './data.js';
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ import { data } from './data.js';
|
|
|
13
13
|
// https://modern-web.dev/guides/test-runner/typescript/
|
|
14
14
|
import '../../../test/lib/embeds.js';
|
|
15
15
|
|
|
16
|
-
function getVideo(videos:
|
|
16
|
+
function getVideo(videos: MediaMap) {
|
|
17
17
|
return Object.values(videos)[0];
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -27,8 +27,8 @@ function playerLoaded(player: PlayerEmbed) {
|
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
describe('Embeds', () => {
|
|
31
|
-
it('
|
|
30
|
+
describe.skip('Embeds', () => {
|
|
31
|
+
it('Sends correct tracking events', async () => {
|
|
32
32
|
const player = await fixture<PlayerEmbed>(
|
|
33
33
|
html`<vouch-embed-player env="dev" .data=${data} aspectratio=${1}></vouch-embed-player>`
|
|
34
34
|
);
|
|
@@ -45,17 +45,24 @@ describe('Embeds', () => {
|
|
|
45
45
|
await waitUntil(
|
|
46
46
|
() => {
|
|
47
47
|
// Video plays for 3 seconds
|
|
48
|
-
return (getVideo(player.mediaPlayer!.
|
|
48
|
+
return (getVideo(player.mediaPlayer!.media)?.node?.currentTime ?? 0) > 3;
|
|
49
49
|
},
|
|
50
50
|
'Video did not play for 3 seconds',
|
|
51
51
|
{ timeout: 20000 }
|
|
52
52
|
);
|
|
53
|
-
expect(getVideo(player.mediaPlayer!.
|
|
53
|
+
expect(getVideo(player.mediaPlayer!.media)?.node?.paused).eq(false);
|
|
54
54
|
player.pause();
|
|
55
|
-
expect(getVideo(player.mediaPlayer!.
|
|
55
|
+
expect(getVideo(player.mediaPlayer!.media)?.node?.paused).eq(true);
|
|
56
56
|
expect(sendTrackingSpy.callCount).to.be.eq(0);
|
|
57
57
|
// Destroy node because events are sent when node is removed from the document
|
|
58
58
|
player.remove();
|
|
59
|
+
await waitUntil(
|
|
60
|
+
() => {
|
|
61
|
+
return createTrackingSpy.args[2];
|
|
62
|
+
},
|
|
63
|
+
'Cleanup event has not fired',
|
|
64
|
+
{ timeout: 5000 }
|
|
65
|
+
);
|
|
59
66
|
expect(sendTrackingSpy.callCount).to.be.eq(1);
|
|
60
67
|
expect(createTrackingSpy.args[0]).to.eql([
|
|
61
68
|
'VIDEO_PLAYED',
|