Skip to content

Commit

Permalink
@gkatsev added Player#tech. Fixes #2617. closes #2883
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev committed Dec 7, 2015
1 parent f225d4e commit 0b7a2e4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGELOG

## HEAD (Unreleased)
* @misteroneill updated videojs-ie8 to 1.1.1 ([view](https://github.com/videojs/video.js/pull/2869))
* @gkatsev added Player#tech. Fixes #2617 ([view](https://github.com/videojs/video.js/pull/2883))

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

Expand Down
24 changes: 24 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,30 @@ class Player extends Component {
this.tech_ = false;
}

/**
* Return a reference to the current tech.
* It will only return a reference to the tech if given an object with the
* `IWillNotUseThisInPlugins` property on it. This is try and prevent misuse
* of techs by plugins.
*
* @param {Object}
* @return {Object} The Tech
* @method tech
*/
tech(safety) {
if (safety && safety.IWillNotUseThisInPlugins) {
return this.tech_;
}
let errorText = `
Please make sure that you are not using this inside of a plugin.
To disable this alert and error, please pass in an object with
\`IWillNotUseThisInPlugins\` to the \`tech\` method. See
https://github.com/videojs/video.js/issues/2617 for more info.
`;
window.alert(errorText);
throw new Error(errorText);
}

/**
* Set up click and touch listeners for the playback element
*
Expand Down
23 changes: 23 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MediaError from '../../src/js/media-error.js';
import Html5 from '../../src/js/tech/html5.js';
import TestHelpers from './test-helpers.js';
import document from 'global/document';
import window from 'global/window';
import Tech from '../../src/js/tech/tech.js';
import TechFaker from './tech/tech-faker.js';

Expand Down Expand Up @@ -861,3 +862,25 @@ test('you can clear error in the error event', function() {

log.error.restore();
});

test('Player#tech will return tech given the appropriate input', function() {
let tech_ = {};
let returnedTech = Player.prototype.tech.call({tech_}, {IWillNotUseThisInPlugins: true});

equal(returnedTech, tech_, 'We got back the tech we wanted');
});

test('Player#tech alerts and throws without the appropriate input', function() {
let alertCalled;
let oldAlert = window.alert;
window.alert = () => alertCalled = true;

let tech_ = {};
throws(function() {
Player.prototype.tech.call({tech_});
}, new RegExp('https://github.com/videojs/video.js/issues/2617'),
'we threw an error');

ok(alertCalled, 'we called an alert');
window.alert = oldAlert;
});

0 comments on commit 0b7a2e4

Please sign in to comment.