1
0
mirror of https://github.com/videojs/video.js.git synced 2024-11-28 08:58:46 +02:00

@gkatsev added a sensible toJSON function. closes #2114

This commit is contained in:
Gary Katsevman 2015-05-01 14:16:19 -07:00 committed by heff
parent aa7f7709b1
commit 102c6fb197
4 changed files with 54 additions and 2 deletions

View File

@ -25,6 +25,7 @@ CHANGELOG
* @mmcc added back the captions settings styles ([view](https://github.com/videojs/video.js/pull/2112))
* @gkatsev updated the component.js styles to match the new style guide ([view](https://github.com/videojs/video.js/pull/2105))
* @gkatsev added error logging for bad JSON formatting ([view](https://github.com/videojs/video.js/pull/2113))
* @gkatsev added a sensible toJSON function ([view](https://github.com/videojs/video.js/pull/2114))
--------------------

View File

@ -319,13 +319,16 @@ module.exports = function(grunt) {
},
watch: {
files: {
'build/temp/video.js': ['src/js/video.js']
'build/temp/video.js': ['src/js/video.js'],
'build/temp/tests.js': [
'test/globals-shim.js',
'test/unit/**/*.js'
]
},
options: {
watch: true,
keepAlive: true,
browserifyOptions: {
debug: true,
standalone: 'videojs'
},
banner: license,

View File

@ -1659,6 +1659,24 @@ class Player extends Component {
return this.languages_;
}
toJSON() {
let options = Lib.obj.deepMerge({}, this.options());
let tracks = options.tracks;
options.tracks = [];
for (let i = 0; i < tracks.length; i++) {
let track = tracks[i];
// deep merge tracks and null out player so no circular references
track = Lib.obj.deepMerge({}, track);
track.player = undefined;
options.tracks[i] = track;
}
return options;
}
static getTagSettings(tag) {
let baseOptions = {
'sources': [],

View File

@ -728,3 +728,33 @@ test('should throw on startup no techs are specified', function() {
Options.techOrder = techOrder;
});
test('should have a sensible toJSON that is equivalent to player.options', function() {
const playerOptions = {
html5: {
nativeTextTracks: false
}
};
const player = TestHelpers.makePlayer(playerOptions);
deepEqual(player.toJSON(), player.options(), 'simple player options toJSON produces output equivalent to player.options()');
const playerOptions2 = {
tracks: [{
label: 'English',
srclang: 'en',
src: '../docs/examples/shared/example-captions.vtt',
kind: 'captions'
}]
};
const player2 = TestHelpers.makePlayer(playerOptions2);
playerOptions2.tracks[0].player = player2;
const popts = player2.options();
popts.tracks[0].player = undefined;
deepEqual(player2.toJSON(), popts, 'no circular references');
});