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

Add Player#tech. #2883

Closed
wants to merge 2 commits into from
Closed
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
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;
});