3 exports.__esModule = true;
5 * @file text-track-list-converter.js Utilities for capturing text track state and
6 * re-creating tracks based on a capture.
8 * @module text-track-list-converter
12 * Examine a single {@link TextTrack} and return a JSON-compatible javascript object that
13 * represents the {@link TextTrack}'s state.
15 * @param {TextTrack} track
16 * The text track to query.
19 * A serializable javascript representation of the TextTrack.
22 var trackToJson_ = function trackToJson_(track) {
23 var ret = ['kind', 'label', 'language', 'id', 'inBandMetadataTrackDispatchType', 'mode', 'src'].reduce(function (acc, prop, i) {
26 acc[prop] = track[prop];
31 cues: track.cues && Array.prototype.map.call(track.cues, function (cue) {
33 startTime: cue.startTime,
45 * Examine a {@link Tech} and return a JSON-compatible javascript array that represents the
46 * state of all {@link TextTrack}s currently configured. The return array is compatible with
47 * {@link text-track-list-converter:jsonToTextTracks}.
50 * The tech object to query
53 * A serializable javascript representation of the {@link Tech}s
54 * {@link TextTrackList}.
56 var textTracksToJson = function textTracksToJson(tech) {
58 var trackEls = tech.$$('track');
60 var trackObjs = Array.prototype.map.call(trackEls, function (t) {
63 var tracks = Array.prototype.map.call(trackEls, function (trackEl) {
64 var json = trackToJson_(trackEl.track);
67 json.src = trackEl.src;
72 return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function (track) {
73 return trackObjs.indexOf(track) === -1;
74 }).map(trackToJson_));
78 * Create a set of remote {@link TextTrack}s on a {@link Tech} based on an array of javascript
79 * object {@link TextTrack} representations.
82 * An array of `TextTrack` representation objects, like those that would be
83 * produced by `textTracksToJson`.
86 * The `Tech` to create the `TextTrack`s on.
88 var jsonToTextTracks = function jsonToTextTracks(json, tech) {
89 json.forEach(function (track) {
90 var addedTrack = tech.addRemoteTextTrack(track).track;
92 if (!track.src && track.cues) {
93 track.cues.forEach(function (cue) {
94 return addedTrack.addCue(cue);
99 return tech.textTracks();
102 exports['default'] = { textTracksToJson: textTracksToJson, jsonToTextTracks: jsonToTextTracks, trackToJson_: trackToJson_ };