mirror of
https://github.com/videojs/video.js.git
synced 2024-12-04 10:34:51 +02:00
feat(cors): add crossOrigin option to enable cookies on requests (#6533)
Co-authored-by: Abraham Cruz Sustaita <abraham.sustaita@gmail.com> Co-authored-by: Gary Katsevman <git@gkatsev.com>
This commit is contained in:
parent
6d18c40e1f
commit
ea20edcd99
@ -744,6 +744,7 @@ class Player extends Component {
|
||||
this.fill(this.options_.fill);
|
||||
this.fluid(this.options_.fluid);
|
||||
this.aspectRatio(this.options_.aspectRatio);
|
||||
this.crossOrigin(this.options_.crossOrigin);
|
||||
|
||||
// Hide any links within the video/audio tag,
|
||||
// because IE doesn't hide them completely from screen readers.
|
||||
@ -782,6 +783,36 @@ class Player extends Component {
|
||||
return el;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or set the `Player`'s crossOrigin option. For the HTML5 player, this
|
||||
* sets the `crossOrigin` property on the `<video>` tag to control the CORS
|
||||
* behavior.
|
||||
*
|
||||
* @see [Video Element Attributes]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin}
|
||||
*
|
||||
* @param {string} [value]
|
||||
* The value to set the `Player`'s crossOrigin to. If an argument is
|
||||
* given, must be one of `anonymous` or `use-credentials`.
|
||||
*
|
||||
* @return {string|undefined}
|
||||
* - The current crossOrigin value of the `Player` when getting.
|
||||
* - undefined when setting
|
||||
*/
|
||||
crossOrigin(value) {
|
||||
if (!value) {
|
||||
return this.techGet_('crossOrigin');
|
||||
}
|
||||
|
||||
if (value !== 'anonymous' || value !== 'use-credentials') {
|
||||
log.warn(`crossOrigin must be "anonymous" or "use-credentials", given "${value}"`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.techCall_('setCrossOrigin', value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* A getter/setter for the `Player`'s width. Returns the player's configured value.
|
||||
* To get the current width use `currentWidth()`.
|
||||
@ -929,7 +960,7 @@ class Player extends Component {
|
||||
* A getter/setter for the `Player`'s aspect ratio.
|
||||
*
|
||||
* @param {string} [ratio]
|
||||
* The value to set the `Player's aspect ratio to.
|
||||
* The value to set the `Player`'s aspect ratio to.
|
||||
*
|
||||
* @return {string|undefined}
|
||||
* - The current aspect ratio of the `Player` when getting.
|
||||
|
@ -1519,7 +1519,7 @@ Html5.resetMediaElement = function(el) {
|
||||
// The list is as followed
|
||||
// paused, currentTime, buffered, volume, poster, preload, error, seeking
|
||||
// seekable, ended, playbackRate, defaultPlaybackRate, played, networkState
|
||||
// readyState, videoWidth, videoHeight
|
||||
// readyState, videoWidth, videoHeight, crossOrigin
|
||||
[
|
||||
/**
|
||||
* Get the value of `paused` from the media element. `paused` indicates whether the media element
|
||||
@ -1764,7 +1764,21 @@ Html5.resetMediaElement = function(el) {
|
||||
*
|
||||
* @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
|
||||
*/
|
||||
'videoHeight'
|
||||
'videoHeight',
|
||||
|
||||
/**
|
||||
* Get the value of `crossOrigin` from the media element. `crossOrigin` indicates
|
||||
* to the browser that should sent the cookies along with the requests for the
|
||||
* different assets/playlists
|
||||
*
|
||||
* @method Html5#crossOrigin
|
||||
* @return {string}
|
||||
* - anonymous indicates that the media should not sent cookies.
|
||||
* - use-credentials indicates that the media should sent cookies along the requests.
|
||||
*
|
||||
* @see [Spec]{@link https://html.spec.whatwg.org/#attr-media-crossorigin}
|
||||
*/
|
||||
'crossOrigin'
|
||||
].forEach(function(prop) {
|
||||
Html5.prototype[prop] = function() {
|
||||
return this.el_[prop];
|
||||
@ -1774,7 +1788,7 @@ Html5.resetMediaElement = function(el) {
|
||||
// Wrap native properties with a setter in this format:
|
||||
// set + toTitleCase(name)
|
||||
// The list is as follows:
|
||||
// setVolume, setSrc, setPoster, setPreload, setPlaybackRate, setDefaultPlaybackRate
|
||||
// setVolume, setSrc, setPoster, setPreload, setPlaybackRate, setDefaultPlaybackRate, setCrossOrigin
|
||||
[
|
||||
/**
|
||||
* Set the value of `volume` on the media element. `volume` indicates the current
|
||||
@ -1864,8 +1878,21 @@ Html5.resetMediaElement = function(el) {
|
||||
*
|
||||
* @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultplaybackrate}
|
||||
*/
|
||||
'defaultPlaybackRate'
|
||||
'defaultPlaybackRate',
|
||||
|
||||
/**
|
||||
* Set the value of `crossOrigin` from the media element. `crossOrigin` indicates
|
||||
* to the browser that should sent the cookies along with the requests for the
|
||||
* different assets/playlists
|
||||
*
|
||||
* @method Html5#setCrossOrigin
|
||||
* @param {string} crossOrigin
|
||||
* - anonymous indicates that the media should not sent cookies.
|
||||
* - use-credentials indicates that the media should sent cookies along the requests.
|
||||
*
|
||||
* @see [Spec]{@link https://html.spec.whatwg.org/#attr-media-crossorigin}
|
||||
*/
|
||||
'crossOrigin'
|
||||
].forEach(function(prop) {
|
||||
Html5.prototype['set' + toTitleCase(prop)] = function(v) {
|
||||
this.el_[prop] = v;
|
||||
|
Loading…
Reference in New Issue
Block a user