From b0970162152e40ecc0f761d5fba45b96c59fbc79 Mon Sep 17 00:00:00 2001 From: David LaPalomento Date: Tue, 21 Jul 2015 18:58:55 -0400 Subject: [PATCH] @dmlap expose the xhr helper utility. closes #2321 --- CHANGELOG.md | 1 + src/js/video.js | 32 ++++++++++++++++++++++++++++++++ src/js/xhr.js | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffdfee08b..3b1b2baca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) -------------------- diff --git a/src/js/video.js b/src/js/video.js index 285ec27b3..d9bfe6083 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -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'; @@ -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){ diff --git a/src/js/xhr.js b/src/js/xhr.js index 7aac4897d..7b0e654d3 100644 --- a/src/js/xhr.js +++ b/src/js/xhr.js @@ -45,7 +45,7 @@ var xhr = function(options, callback){ } // Merge with default options - mergeOptions({ + options = mergeOptions({ method: 'GET', timeout: 45 * 1000 }, options);