Skip to content

Commit

Permalink
@dmlap expose the xhr helper utility. closes #2321
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlap committed Jul 21, 2015
1 parent 843a577 commit b097016
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ CHANGELOG
* @dmlap export a basic played() on techs ([view](https://github.com/videojs/video.js/pull/2384))
* @dmlap use seekable on source handlers when defined ([view](https://github.com/videojs/video.js/pull/2376))
* @dmlap fire seeking in the flash tech, not the SWF ([view](https://github.com/videojs/video.js/pull/2372))
* @dmlap expose the xhr helper utility ([view](https://github.com/videojs/video.js/pull/2321))

--------------------

Expand Down
32 changes: 32 additions & 0 deletions src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as Fn from './utils/fn.js';
import assign from 'object.assign';
import { createTimeRange } from './utils/time-ranges.js';
import log from './utils/log.js';
import xhr from './xhr.js';
import * as Dom from './utils/dom.js';
import * as browser from './utils/browser.js';
import extendsFn from './extends.js';
Expand Down Expand Up @@ -357,6 +358,37 @@ videojs.log = log;
*/
videojs.createTimeRange = createTimeRange;

/**
* Simple http request for retrieving external files (e.g. text tracks)
*
* ##### Example
*
* // using url string
* videojs.xhr('http://example.com/myfile.vtt', function(error, response, responseBody){});
*
* // or options block
* videojs.xhr({
* uri: 'http://example.com/myfile.vtt',
* method: 'GET',
* responseType: 'text'
* }, function(error, response, responseBody){
* if (error) {
* // log the error
* } else {
* // successful, do something with the response
* }
* });
*
*
* API is modeled after the Raynos/xhr.
* https://github.com/Raynos/xhr/blob/master/index.js
*
* @param {Object|String} options Options block or URL string
* @param {Function} callback The callback function
* @returns {Object} The request
*/
videojs.xhr = xhr;

// REMOVING: We probably should add this to the migration plugin
// // Expose but deprecate the window[componentName] method for accessing components
// Object.getOwnPropertyNames(Component.components).forEach(function(name){
Expand Down
2 changes: 1 addition & 1 deletion src/js/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var xhr = function(options, callback){
}

// Merge with default options
mergeOptions({
options = mergeOptions({
method: 'GET',
timeout: 45 * 1000
}, options);
Expand Down

0 comments on commit b097016

Please sign in to comment.