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

toJSON #2114

Closed
wants to merge 5 commits into from
Closed

toJSON #2114

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
7 changes: 5 additions & 2 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
Expand Down
30 changes: 30 additions & 0 deletions test/unit/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});