@@ -6,7 +6,12 @@ interface Props {
66 moreVideosLink: string ;
77}
88
9- const { videoId, videoTitle, thumbnailTimeOrURL, moreVideosLink= " true" } = Astro .props ;
9+ const {
10+ videoId,
11+ videoTitle,
12+ thumbnailTimeOrURL,
13+ moreVideosLink = " true" ,
14+ } = Astro .props ;
1015
1116const customerId = " 1mwganm1ma0xgnmj" ;
1217const baseUrl = ` https://customer-${customerId }.cloudflarestream.com/ ` ;
@@ -32,25 +37,46 @@ if (thumbnailTimeOrURL !== undefined) {
3237}
3338---
3439
35- <div style =" position: relative; padding-top: 56.25%" >
36- <iframe
37- src ={ url .toString ()}
38- style =" border: none; position: absolute; top: 0; left: 0; height: 100%; width: 100%;"
39- allow =" accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
40- allowfullscreen =" true"
41- title ={ videoTitle }
42- id ={ videoId } ></iframe >
43- </div >
44-
45- { moreVideosLink == " true" &&
46- <a href = " https://www.youtube.com/@CloudflareDevelopers" target = " _blank" >Watch more videos on our Developer Channel</a >
47- }
40+ <stream-player data-id ={ videoId } data-title ={ videoTitle } >
41+ <div style =" position: relative; padding-top: 56.25%" >
42+ <iframe
43+ src ={ url .toString ()}
44+ style =" border: none; position: absolute; top: 0; left: 0; height: 100%; width: 100%;"
45+ allow =" accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
46+ allowfullscreen =" true"
47+ title ={ videoTitle }
48+ id ={ videoId } ></iframe >
49+ </div >
50+
51+ {
52+ moreVideosLink == " true" && (
53+ <a href = " https://www.youtube.com/@CloudflareDevelopers" target = " _blank" >
54+ Watch more videos on our Developer Channel
55+ </a >
56+ )
57+ }
58+ </stream-player>
4859
4960<script is:inline src =" https://embed.cloudflarestream.com/embed/sdk.latest.js"
5061></script >
51- <script is:inline define:vars ={ { vidId: videoId , videoTitle }} >
52- const video = document.getElementById(vidId);
53- Stream(video).addEventListener("play", () => {
54- zaraz.track("play docs video", { title: videoTitle });
55- });
62+
63+ <script >
64+ import { track } from "~/util/zaraz";
65+
66+ declare function Stream(player: HTMLIFrameElement): HTMLVideoElement;
67+
68+ class StreamPlayer extends HTMLElement {
69+ connectedCallback() {
70+ const id = CSS.escape(this.dataset.id as string);
71+ const title = this.dataset.title as string;
72+
73+ const player = this.querySelector(`#${id}`) as HTMLIFrameElement;
74+
75+ Stream(player).addEventListener("play", () => {
76+ track("play docs video", { title: title });
77+ });
78+ }
79+ }
80+
81+ customElements.define("stream-player", StreamPlayer);
5682</script >
0 commit comments