From a4ab2859e9d2026d7bfc125a1f3576717ba1e08b Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Fri, 17 Jul 2020 12:56:03 -0400 Subject: [PATCH] feat: expose canChangeType on the VHS property (#911) --- src/source-updater.js | 13 ++++++++++++- src/videojs-http-streaming.js | 5 +++++ test/videojs-http-streaming.test.js | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/source-updater.js b/src/source-updater.js index 312c0d87..35d0a7f0 100644 --- a/src/source-updater.js +++ b/src/source-updater.js @@ -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() { + return this.constructor.canChangeType(); + } + /** * Call the changeType function on a source buffer, given the code and type. * diff --git a/src/videojs-http-streaming.js b/src/videojs-http-streaming.js index e5de9105..4bc38617 100644 --- a/src/videojs-http-streaming.js +++ b/src/videojs-http-streaming.js @@ -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, @@ -902,6 +903,10 @@ class VhsHandler extends Component { return this.constructor.version(); } + canChangeType() { + return SourceUpdater.canChangeType(); + } + /** * Begin playing the video. */ diff --git a/test/videojs-http-streaming.test.js b/test/videojs-http-streaming.test.js index e924b0c7..dd6e64cd 100644 --- a/test/videojs-http-streaming.test.js +++ b/test/videojs-http-streaming.test.js @@ -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 = '';