Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

feat: improve Youtube embed for play and pause #569

Merged
merged 3 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### New: Web Components
* social: v1.0.0-rc.1-3 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/social/CHANGELOG.md))
* youtube: v1.0.0-rc.1 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/youtube/CHANGELOG.md))
* youtube: v1.0.0-rc.1-1 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/youtube/CHANGELOG.md))

### Web Components
* slide-author: v1.0.0-rc.3-1 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/slides/author/CHANGELOG.md))
Expand Down
12 changes: 6 additions & 6 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@deckdeckgo/slide-video": "^1.0.0-rc.1-1",
"@deckdeckgo/slide-youtube": "^1.0.0-rc.3",
"@deckdeckgo/social": "^1.0.0-rc.1-3",
"@deckdeckgo/youtube": "^1.0.0-rc.1",
"@deckdeckgo/youtube": "^1.0.0-rc.1-1",
"@ionic/core": "^4.11.7",
"idb-keyval": "^3.2.0",
"rxjs": "^6.5.4"
Expand All @@ -47,7 +47,7 @@
"@stencil/sass": "^1.1.1",
"@types/glob": "^7.1.1",
"@types/marked": "^0.7.2",
"@types/node": "^13.1.4",
"@types/node": "^13.1.5",
"autoprefixer": "^9.7.3",
"glob": "^7.1.6",
"marked": "^0.8.0",
Expand Down
6 changes: 3 additions & 3 deletions remote/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@deckdeckgo/slide-youtube": "^1.0.0-rc.3",
"@deckdeckgo/social": "^1.0.0-rc.1-3",
"@deckdeckgo/utils": "^1.0.0-rc.1-2",
"@deckdeckgo/youtube": "^1.0.0-rc.1",
"@deckdeckgo/youtube": "^1.0.0-rc.1-1",
"@ionic/core": "^4.11.7",
"date-fns": "^2.9.0",
"idb-keyval": "^3.2.0",
Expand Down
6 changes: 3 additions & 3 deletions studio/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@deckdeckgo/slide-youtube": "^1.0.0-rc.3",
"@deckdeckgo/social": "^1.0.0-rc.1-3",
"@deckdeckgo/utils": "^1.0.0-rc.1-4",
"@deckdeckgo/youtube": "^1.0.0-rc.1",
"@deckdeckgo/youtube": "^1.0.0-rc.1-1",
"@ionic/core": "4.11.7",
"firebase": "^7.6.1",
"idb-keyval": "^3.2.0",
Expand Down
7 changes: 7 additions & 0 deletions webcomponents/youtube/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="1.0.0-rc.1-1"></a>
# 1.0.0-rc.1-1 (2020-01-09)

### Features

* if Youtube video is provided as embed link, add enablejsapi=1 to be able to play and pause the video

<a name="1.0.0-rc.1"></a>
# 1.0.0-rc.1 (2020-01-08)

Expand Down
2 changes: 1 addition & 1 deletion webcomponents/youtube/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webcomponents/youtube/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deckdeckgo/youtube",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.1-1",
"description": "A Youtube Web Component player",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
19 changes: 18 additions & 1 deletion webcomponents/youtube/src/components/deckdeckgo-youtube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,22 @@ export class DeckdeckgoYoutube {
resolve('https://www.youtube.com/embed/' + videoId + '?enablejsapi=1');
} else {
// Otherwise we try the provided url
resolve(this.src);

if (!this.src) {
resolve(this.src);
return;
}

// But first, if an embed link, like https://www.youtube.com/embed/PnSNT5WpauE, would be passed, a parameter to enable js should be added otherwise play and pause could not be triggered
// Therefore we add enablejsapi if needed in any case

const url: URL = new URL(this.src);

if (!url.searchParams.get('enablejsapi')) {
url.searchParams.append('enablejsapi', '1');
}

resolve(url.href);
}
});
}
Expand Down Expand Up @@ -207,6 +222,8 @@ export class DeckdeckgoYoutube {
return;
}

console.log('here', iframe);

iframe.contentWindow.postMessage(JSON.stringify({
event: 'command',
func: play ? 'playVideo' : 'pauseVideo',
Expand Down
16 changes: 16 additions & 0 deletions webcomponents/youtube/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<div slot="actions">
<button onclick="loadYoutube()">Load video</button>
<button onclick="play()">Play</button>
<button onclick="pause()">Pause</button>
</div>

<deckgo-youtube id="youtube" width="500" height="400" src="https://www.youtube.com/embed/PnSNT5WpauE" frameTitle="Interact with your presentation"></deckgo-youtube>
Expand All @@ -29,6 +31,20 @@
await elem.lazyLoadContent();
}
}

async function play() {
const elem = document.getElementById('youtube');
if (elem) {
await elem.play();
}
}

async function pause() {
const elem = document.getElementById('youtube');
if (elem) {
await elem.pause();
}
}
</script>
</body>
</html>