
committed by
Jon-Carlos Rivera

3 changed files with 0 additions and 207 deletions
@ -1,98 +0,0 @@ |
|||
/** |
|||
* @file hls-audio-track.js |
|||
*/ |
|||
import {AudioTrack} from 'video.js'; |
|||
import PlaylistLoader from './playlist-loader'; |
|||
|
|||
/** |
|||
* HlsAudioTrack extends video.js audio tracks but adds HLS |
|||
* specific data storage such as playlist loaders, mediaGroups |
|||
* and default/autoselect |
|||
* |
|||
* @param {Object} options options to create HlsAudioTrack with |
|||
* @class HlsAudioTrack |
|||
* @extends AudioTrack |
|||
*/ |
|||
export default class HlsAudioTrack extends AudioTrack { |
|||
constructor(options) { |
|||
super({ |
|||
kind: options.default ? 'main' : 'alternative', |
|||
enabled: options.default || false, |
|||
language: options.language, |
|||
label: options.label |
|||
}); |
|||
|
|||
this.hls = options.hls; |
|||
this.autoselect = options.autoselect || false; |
|||
this.default = options.default || false; |
|||
this.withCredentials = options.withCredentials || false; |
|||
this.mediaGroups_ = []; |
|||
this.addLoader(options.mediaGroup, options.resolvedUri); |
|||
} |
|||
|
|||
/** |
|||
* get a PlaylistLoader from this track given a mediaGroup name |
|||
* |
|||
* @param {String} mediaGroup the mediaGroup to get the loader for |
|||
* @return {PlaylistLoader|Null} the PlaylistLoader or null |
|||
*/ |
|||
getLoader(mediaGroup) { |
|||
for (let i = 0; i < this.mediaGroups_.length; i++) { |
|||
let mgl = this.mediaGroups_[i]; |
|||
|
|||
if (mgl.mediaGroup === mediaGroup) { |
|||
return mgl.loader; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* add a PlaylistLoader given a mediaGroup, and a uri. for a combined track |
|||
* we store null for the playlistloader |
|||
* |
|||
* @param {String} mediaGroup the mediaGroup to get the loader for |
|||
* @param {String} uri the uri to get the audio track/mediaGroup from |
|||
*/ |
|||
addLoader(mediaGroup, uri = null) { |
|||
let loader = null; |
|||
|
|||
if (uri) { |
|||
// TODO: this should probably happen upstream in Master Playlist
|
|||
// Controller when we can switch PlaylistLoader sources
|
|||
// then we can just store the uri here instead
|
|||
loader = new PlaylistLoader(uri, this.hls, this.withCredentials); |
|||
} |
|||
this.mediaGroups_.push({mediaGroup, loader}); |
|||
} |
|||
|
|||
/** |
|||
* remove a playlist loader from a track given the mediaGroup |
|||
* |
|||
* @param {String} mediaGroup the mediaGroup to remove |
|||
*/ |
|||
removeLoader(mediaGroup) { |
|||
for (let i = 0; i < this.mediaGroups_.length; i++) { |
|||
let mgl = this.mediaGroups_[i]; |
|||
|
|||
if (mgl.mediaGroup === mediaGroup) { |
|||
if (mgl.loader) { |
|||
mgl.loader.dispose(); |
|||
} |
|||
this.mediaGroups_.splice(i, 1); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Dispose of this audio track and |
|||
* the playlist loader that it holds inside |
|||
*/ |
|||
dispose() { |
|||
let i = this.mediaGroups_.length; |
|||
|
|||
while (i--) { |
|||
this.removeLoader(this.mediaGroups_[i].mediaGroup); |
|||
} |
|||
} |
|||
} |
@ -1,108 +0,0 @@ |
|||
import HlsAudioTrack from '../src/hls-audio-track'; |
|||
import QUnit from 'qunit'; |
|||
|
|||
// Most of these tests will be done in video.js.AudioTrack unit tests
|
|||
QUnit.module('HlsAudioTrack - Props'); |
|||
|
|||
QUnit.test('verify that props are readonly and can be set', function(assert) { |
|||
let props = { |
|||
default: true, |
|||
language: 'en', |
|||
label: 'English', |
|||
autoselect: true, |
|||
withCredentials: true, |
|||
// below props won't be used, its used for checking
|
|||
kind: 'main' |
|||
}; |
|||
|
|||
let track = new HlsAudioTrack(props); |
|||
|
|||
for (let k in props) { |
|||
assert.equal(track[k], props[k], `${k} should be stored in track`); |
|||
} |
|||
}); |
|||
|
|||
QUnit.test('can start with a mediaGroup that has a uri', function(assert) { |
|||
let props = { |
|||
default: true, |
|||
language: 'en', |
|||
label: 'English', |
|||
autoselect: true, |
|||
mediaGroup: 'foo', |
|||
withCredentials: true, |
|||
resolvedUri: 'http://some.test.url/playlist.m3u8', |
|||
// below props won't be used, its used for checking
|
|||
enabled: true, |
|||
kind: 'main' |
|||
}; |
|||
let track = new HlsAudioTrack(props); |
|||
|
|||
assert.equal(track.mediaGroups_.length, 1, 'loader was created'); |
|||
let loader = track.getLoader('foo'); |
|||
|
|||
assert.ok(loader, 'can getLoader on foo'); |
|||
|
|||
track.dispose(); |
|||
assert.equal(track.mediaGroups_.length, 0, 'loader disposed'); |
|||
}); |
|||
|
|||
QUnit.test('can start with a mediaGroup that has no uri', function(assert) { |
|||
let props = { |
|||
default: true, |
|||
language: 'en', |
|||
label: 'English', |
|||
autoselect: true, |
|||
mediaGroup: 'foo', |
|||
withCredentials: true, |
|||
// below props won't be used, its used for checking
|
|||
enabled: true, |
|||
kind: 'main' |
|||
}; |
|||
let track = new HlsAudioTrack(props); |
|||
|
|||
assert.equal(track.mediaGroups_.length, 1, 'mediaGroupLoader was created for foo'); |
|||
assert.ok(!track.getLoader('foo'), 'can getLoader on foo, but it is undefined'); |
|||
|
|||
track.dispose(); |
|||
assert.equal(track.mediaGroups_.length, 0, 'loaders disposed'); |
|||
}); |
|||
|
|||
QUnit.module('HlsAudioTrack - Loader', { |
|||
beforeEach() { |
|||
this.track = new HlsAudioTrack({ |
|||
mediaGroup: 'default', |
|||
default: true, |
|||
language: 'en', |
|||
label: 'English', |
|||
autoselect: true, |
|||
withCredentials: true |
|||
}); |
|||
}, |
|||
afterEach(assert) { |
|||
this.track.dispose(); |
|||
assert.equal(this.track.mediaGroups_.length, 0, 'zero loaders after dispose'); |
|||
} |
|||
}); |
|||
|
|||
QUnit.test('can add a playlist loader', function(assert) { |
|||
assert.equal(this.track.mediaGroups_.length, 1, '1 loader to start'); |
|||
|
|||
this.track.addLoader('foo', 'someurl'); |
|||
this.track.addLoader('bar', 'someurl'); |
|||
this.track.addLoader('baz', 'someurl'); |
|||
|
|||
assert.equal(this.track.mediaGroups_.length, 4, 'now has four loaders'); |
|||
}); |
|||
|
|||
QUnit.test('can remove playlist loader', function(assert) { |
|||
assert.equal(this.track.mediaGroups_.length, 1, 'one loaders to start'); |
|||
|
|||
this.track.addLoader('foo', 'someurl'); |
|||
this.track.addLoader('baz', 'someurl'); |
|||
|
|||
assert.equal(this.track.mediaGroups_.length, 3, 'now has three loaders'); |
|||
|
|||
this.track.removeLoader('baz'); |
|||
assert.equal(this.track.mediaGroups_.length, 2, 'now has two loaders'); |
|||
|
|||
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue