Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / node_modules / video.js / es5 / tracks / text-track-list-converter.js
1 'use strict';
2
3 exports.__esModule = true;
4 /**
5  * @file text-track-list-converter.js Utilities for capturing text track state and
6  * re-creating tracks based on a capture.
7  *
8  * @module text-track-list-converter
9  */
10
11 /**
12  * Examine a single {@link TextTrack} and return a JSON-compatible javascript object that
13  * represents the {@link TextTrack}'s state.
14  *
15  * @param {TextTrack} track
16  *        The text track to query.
17  *
18  * @return {Object}
19  *         A serializable javascript representation of the TextTrack.
20  * @private
21  */
22 var trackToJson_ = function trackToJson_(track) {
23   var ret = ['kind', 'label', 'language', 'id', 'inBandMetadataTrackDispatchType', 'mode', 'src'].reduce(function (acc, prop, i) {
24
25     if (track[prop]) {
26       acc[prop] = track[prop];
27     }
28
29     return acc;
30   }, {
31     cues: track.cues && Array.prototype.map.call(track.cues, function (cue) {
32       return {
33         startTime: cue.startTime,
34         endTime: cue.endTime,
35         text: cue.text,
36         id: cue.id
37       };
38     })
39   });
40
41   return ret;
42 };
43
44 /**
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}.
48  *
49  * @param {Tech} tech
50  *        The tech object to query
51  *
52  * @return {Array}
53  *         A serializable javascript representation of the {@link Tech}s
54  *         {@link TextTrackList}.
55  */
56 var textTracksToJson = function textTracksToJson(tech) {
57
58   var trackEls = tech.$$('track');
59
60   var trackObjs = Array.prototype.map.call(trackEls, function (t) {
61     return t.track;
62   });
63   var tracks = Array.prototype.map.call(trackEls, function (trackEl) {
64     var json = trackToJson_(trackEl.track);
65
66     if (trackEl.src) {
67       json.src = trackEl.src;
68     }
69     return json;
70   });
71
72   return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function (track) {
73     return trackObjs.indexOf(track) === -1;
74   }).map(trackToJson_));
75 };
76
77 /**
78  * Create a set of remote {@link TextTrack}s on a {@link Tech} based on an array of javascript
79  * object {@link TextTrack} representations.
80  *
81  * @param {Array} json
82  *        An array of `TextTrack` representation objects, like those that would be
83  *        produced by `textTracksToJson`.
84  *
85  * @param {Tech} tech
86  *        The `Tech` to create the `TextTrack`s on.
87  */
88 var jsonToTextTracks = function jsonToTextTracks(json, tech) {
89   json.forEach(function (track) {
90     var addedTrack = tech.addRemoteTextTrack(track).track;
91
92     if (!track.src && track.cues) {
93       track.cues.forEach(function (cue) {
94         return addedTrack.addCue(cue);
95       });
96     }
97   });
98
99   return tech.textTracks();
100 };
101
102 exports['default'] = { textTracksToJson: textTracksToJson, jsonToTextTracks: jsonToTextTracks, trackToJson_: trackToJson_ };