Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add otherParams + forceHttpsApi options #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions examples/src/force-https/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<script src='/youtube-player.js'></script>
</head>
<body>
<div id='player-1'></div>

<script>
var player1,
firstStateChange;

player1 = YouTubePlayer('player-1', {
videoId: 'M7lc1UVf-VE',
otherParams: {
forceHttpsApi: true
}
});

player1
// Play video is a Promise.
// 'playVideo' is queued and will execute as soon as player is ready.
.playVideo()
.then(function () {
console.log('Starting to play player1. It will take some time to buffer video before it starts playing.');
});
</script>
</body>
</html>
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type OptionsType = {|
playerVars?: Object,
videoId?: string,
width?: number,
otherParams?: {|
forceHttpsApi?: boolean,
|},
|};

/**
Expand All @@ -39,7 +42,7 @@ export default (maybeElementId: string | HTMLElement | YouTubePlayerType, option
const emitter = Sister();

if (!youtubeIframeAPI) {
youtubeIframeAPI = loadYouTubeIframeApi(emitter);
youtubeIframeAPI = loadYouTubeIframeApi(emitter, options);
}

if (options.events) {
Expand Down
11 changes: 9 additions & 2 deletions src/loadYouTubeIframeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
IframeApiType,
} from './types';

export default (emitter: EmitterType): Promise<IframeApiType> => {
export default (emitter: EmitterType, options = undefined): Promise<IframeApiType> => {
/**
* A promise that is resolved when window.onYouTubeIframeAPIReady is called.
* The promise is resolved with a reference to window.YT object.
Expand All @@ -17,7 +17,14 @@ export default (emitter: EmitterType): Promise<IframeApiType> => {

return;
} else {
const protocol = window.location.protocol === 'http:' ? 'http:' : 'https:';
let protocol;

const forceHttpsApi = options && options.otherParams && options.otherParams.forceHttpsApi;
if (forceHttpsApi) {
protocol = 'https:';
} else {
protocol = window.location.protocol === 'http:' ? 'http:' : 'https:';
}

load(protocol + '//www.youtube.com/iframe_api', (error) => {
if (error) {
Expand Down