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

feat: expose canChangeType on the VHS property #911

Merged
merged 1 commit into from
Jul 17, 2020
Merged
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
13 changes: 12 additions & 1 deletion src/source-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,23 @@ export default class SourceUpdater extends videojs.EventTarget {
* @return {boolean}
* if changeType can be called.
*/
canChangeType() {
static canChangeType() {
return window.SourceBuffer &&
window.SourceBuffer.prototype &&
typeof window.SourceBuffer.prototype.changeType === 'function';
}

/**
* Whether or not the changeType function is supported
* on our SourceBuffers.
*
* @return {boolean}
* if changeType can be called.
*/
canChangeType() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth having this too vs just using the static function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is used internally and makes its usage slightly easier.

return this.constructor.canChangeType();
}

/**
* Call the changeType function on a source buffer, given the code and type.
*
Expand Down
5 changes: 5 additions & 0 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MasterPlaylistController } from './master-playlist-controller';
import Config from './config';
import renditionSelectionMixin from './rendition-mixin';
import PlaybackWatcher from './playback-watcher';
import SourceUpdater from './source-updater';
import reloadSourceOnError from './reload-source-on-error';
import {
lastBandwidthSelector,
Expand Down Expand Up @@ -902,6 +903,10 @@ class VhsHandler extends Component {
return this.constructor.version();
}

canChangeType() {
return SourceUpdater.canChangeType();
}

/**
* Begin playing the video.
*/
Expand Down
18 changes: 18 additions & 0 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,24 @@ QUnit.test('version is exported', function(assert) {

});

QUnit.test('canChangeType is exported', function(assert) {
this.player.src({
src: 'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});

this.clock.tick(1);

assert.ok(this.player.tech(true).vhs.canChangeType, 'canChangeType function');

const canChangeType = window.SourceBuffer &&
window.SourceBuffer.prototype &&
typeof window.SourceBuffer.prototype.changeType === 'function';
const assertion = canChangeType ? 'ok' : 'notOk';

assert[assertion](this.player.tech(true).vhs.canChangeType(), 'canChangeType is correct');
});

QUnit.test('deprecation warning is show when using player.hls', function(assert) {
const oldWarn = videojs.log.warn;
let warning = '';
Expand Down