toms intro to jshint
Showing
6 changed files
with
48 additions
and
41 deletions
... | @@ -3,8 +3,8 @@ | ... | @@ -3,8 +3,8 @@ |
3 | ManifestController = window.videojs.hls.ManifestController, | 3 | ManifestController = window.videojs.hls.ManifestController, |
4 | SegmentController = window.videojs.hls.SegmentController, | 4 | SegmentController = window.videojs.hls.SegmentController, |
5 | MediaSource = window.videojs.MediaSource, | 5 | MediaSource = window.videojs.MediaSource, |
6 | SegmentParser = window.videojs.hls.SegmentParser, | 6 | SegmentParser = window.videojs.hls.SegmentParser; |
7 | M3U8 = window.videojs.hls.M3U8; | 7 | |
8 | 8 | ||
9 | window.videojs.hls.HLSPlaybackController = function(player) { | 9 | window.videojs.hls.HLSPlaybackController = function(player) { |
10 | 10 | ||
... | @@ -23,14 +23,14 @@ | ... | @@ -23,14 +23,14 @@ |
23 | self.loadManifest(self.currentRendition.url, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update); | 23 | self.loadManifest(self.currentRendition.url, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update); |
24 | }; | 24 | }; |
25 | 25 | ||
26 | self.loadManifest = function(manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) { | 26 | self.loadManifest = function(manifestUrl, onDataCallback) { |
27 | self.mediaSource.addEventListener('sourceopen', function(event) { | 27 | self.mediaSource.addEventListener('sourceopen', function() { |
28 | // feed parsed bytes into the player | 28 | // feed parsed bytes into the player |
29 | self.sourceBuffer = self.mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"'); | 29 | self.sourceBuffer = self.mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"'); |
30 | 30 | ||
31 | self.parser = new SegmentParser(); | 31 | self.parser = new SegmentParser(); |
32 | 32 | ||
33 | self.sourceBuffer.appendBuffer(self.parser.getFlvHeader(), video); | 33 | self.sourceBuffer.appendBuffer(self.parser.getFlvHeader(), self.player); |
34 | 34 | ||
35 | if (onDataCallback) { | 35 | if (onDataCallback) { |
36 | self.manifestLoadCompleteCallback = onDataCallback; | 36 | self.manifestLoadCompleteCallback = onDataCallback; |
... | @@ -42,7 +42,7 @@ | ... | @@ -42,7 +42,7 @@ |
42 | }, false); | 42 | }, false); |
43 | 43 | ||
44 | self.player.src({ | 44 | self.player.src({ |
45 | src: videojs.URL.createObjectURL(self.mediaSource), | 45 | src: window.videojs.URL.createObjectURL(self.mediaSource), |
46 | type: "video/flv" | 46 | type: "video/flv" |
47 | }); | 47 | }); |
48 | }; | 48 | }; |
... | @@ -65,8 +65,18 @@ | ... | @@ -65,8 +65,18 @@ |
65 | } | 65 | } |
66 | }; | 66 | }; |
67 | 67 | ||
68 | self.onM3U8LoadError = function(error) {}; | 68 | self.onM3U8LoadError = function(error) { |
69 | self.onM3U8Update = function(m3u8) {}; | 69 | if(error) |
70 | { | ||
71 | console.log(error); | ||
72 | } | ||
73 | }; | ||
74 | self.onM3U8Update = function(m3u8) { | ||
75 | if(m3u8) | ||
76 | { | ||
77 | console.log(m3u8); | ||
78 | } | ||
79 | }; | ||
70 | 80 | ||
71 | self.loadSegment = function(segment) { | 81 | self.loadSegment = function(segment) { |
72 | self.segmentController = new SegmentController(); | 82 | self.segmentController = new SegmentController(); |
... | @@ -88,9 +98,14 @@ | ... | @@ -88,9 +98,14 @@ |
88 | self.loadNextSegment = function() { | 98 | self.loadNextSegment = function() { |
89 | self.currentSegment++; | 99 | self.currentSegment++; |
90 | self.loadSegment(self.currentManifest.mediaItems[self.currentSegment]); | 100 | self.loadSegment(self.currentManifest.mediaItems[self.currentSegment]); |
91 | } | 101 | }; |
92 | 102 | ||
93 | self.onSegmentLoadError = function(error) {}; | 103 | self.onSegmentLoadError = function(error) { |
104 | if(error) | ||
105 | { | ||
106 | console.log(error); | ||
107 | } | ||
108 | }; | ||
94 | 109 | ||
95 | }; | 110 | }; |
96 | })(this); | 111 | })(this); | ... | ... |
... | @@ -38,11 +38,11 @@ | ... | @@ -38,11 +38,11 @@ |
38 | lines = rawDataString.split('\n'); | 38 | lines = rawDataString.split('\n'); |
39 | 39 | ||
40 | lines.forEach(function(value,index) { | 40 | lines.forEach(function(value,index) { |
41 | var segment, rendition, attribute; | 41 | var segment, rendition, attributes; |
42 | 42 | ||
43 | switch (self.getTagType(value)) { | 43 | switch (self.getTagType(value)) { |
44 | case tagTypes.EXTM3U: | 44 | case tagTypes.EXTM3U: |
45 | data.hasValidM3UTag = (index == 0); | 45 | data.hasValidM3UTag = (index === 0); |
46 | if (!data.hasValidM3UTag) { | 46 | if (!data.hasValidM3UTag) { |
47 | data.invalidReasons.push("Invalid EXTM3U Tag"); | 47 | data.invalidReasons.push("Invalid EXTM3U Tag"); |
48 | } | 48 | } |
... | @@ -95,12 +95,12 @@ | ... | @@ -95,12 +95,12 @@ |
95 | 95 | ||
96 | if (rendition[attrValue.split('=')[0].toLowerCase()].split('x').length === 2) { | 96 | if (rendition[attrValue.split('=')[0].toLowerCase()].split('x').length === 2) { |
97 | rendition.resolution = { | 97 | rendition.resolution = { |
98 | width: parseInt(rendition[attrValue.split('=')[0].toLowerCase()].split('x')[0]), | 98 | width: parseInt(rendition[attrValue.split('=')[0].toLowerCase()].split('x')[0],10), |
99 | height: parseInt(rendition[attrValue.split('=')[0].toLowerCase()].split('x')[1]) | 99 | height: parseInt(rendition[attrValue.split('=')[0].toLowerCase()].split('x')[1],10) |
100 | } | 100 | }; |
101 | } | 101 | } |
102 | } else { | 102 | } else { |
103 | rendition[attrValue.split('=')[0].toLowerCase()] = parseInt(attrValue.split('=')[1]); | 103 | rendition[attrValue.split('=')[0].toLowerCase()] = parseInt(attrValue.split('=')[1],10); |
104 | } | 104 | } |
105 | }); | 105 | }); |
106 | 106 | ||
... | @@ -128,7 +128,7 @@ | ... | @@ -128,7 +128,7 @@ |
128 | break; | 128 | break; |
129 | 129 | ||
130 | case tagTypes.MEDIA_SEQUENCE: | 130 | case tagTypes.MEDIA_SEQUENCE: |
131 | data.mediaSequence = parseInt(self.getTagValue(value)); | 131 | data.mediaSequence = parseInt(self.getTagValue(value),10); |
132 | break; | 132 | break; |
133 | 133 | ||
134 | case tagTypes.ALLOW_CACHE: | 134 | case tagTypes.ALLOW_CACHE: | ... | ... |
1 | (function (window) { | 1 | (function (window) { |
2 | var | 2 | var |
3 | M3U8 = window.videojs.hls.M3U8, | ||
4 | M3U8Parser = window.videojs.hls.M3U8Parser; | 3 | M3U8Parser = window.videojs.hls.M3U8Parser; |
5 | 4 | ||
6 | window.videojs.hls.ManifestController = function() { | 5 | window.videojs.hls.ManifestController = function() { |
7 | var self = this; | 6 | var self = this; |
8 | 7 | ||
9 | self.parser; | ||
10 | self.data; | ||
11 | self.url; | ||
12 | |||
13 | self.onDataCallback; | ||
14 | self.onErrorCallback; | ||
15 | self.onUpdateCallback; | ||
16 | |||
17 | self.loadManifest = function(manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) { | 8 | self.loadManifest = function(manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) { |
18 | self.url = manifestUrl; | 9 | self.url = manifestUrl; |
19 | 10 | ||
... | @@ -28,7 +19,7 @@ | ... | @@ -28,7 +19,7 @@ |
28 | self.onUpdateCallback = onUpdateCallback; | 19 | self.onUpdateCallback = onUpdateCallback; |
29 | } | 20 | } |
30 | 21 | ||
31 | vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError); | 22 | window.vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError); |
32 | }; | 23 | }; |
33 | 24 | ||
34 | self.parseManifest = function(dataAsString) { | 25 | self.parseManifest = function(dataAsString) { |
... | @@ -42,15 +33,15 @@ | ... | @@ -42,15 +33,15 @@ |
42 | self.onManifestLoadComplete = function(response) { | 33 | self.onManifestLoadComplete = function(response) { |
43 | var output = self.parseManifest(response); | 34 | var output = self.parseManifest(response); |
44 | 35 | ||
45 | if (self.onDataCallback != undefined) { | 36 | if (self.onDataCallback !== undefined) { |
46 | self.onDataCallback(output); | 37 | self.onDataCallback(output); |
47 | } | 38 | } |
48 | }; | 39 | }; |
49 | 40 | ||
50 | self.onManifestLoadError = function(err) { | 41 | self.onManifestLoadError = function(err) { |
51 | if (self.onErrorCallback != undefined) { | 42 | if (self.onErrorCallback !== undefined) { |
52 | self.onErrorCallback((err != undefined) ? err : null); | 43 | self.onErrorCallback((err !== undefined) ? err : null); |
53 | } | 44 | } |
54 | }; | 45 | }; |
55 | } | 46 | }; |
56 | })(this); | 47 | })(this); | ... | ... |
... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
14 | 14 | ||
15 | request.open('GET', segmentUrl, true); | 15 | request.open('GET', segmentUrl, true); |
16 | request.responseType = 'arraybuffer'; | 16 | request.responseType = 'arraybuffer'; |
17 | request.onload = function(response) { | 17 | request.onload = function() { |
18 | self.onSegmentLoadComplete(new Uint8Array(request.response)); | 18 | self.onSegmentLoadComplete(new Uint8Array(request.response)); |
19 | }; | 19 | }; |
20 | 20 | ||
... | @@ -29,7 +29,7 @@ | ... | @@ -29,7 +29,7 @@ |
29 | self.data.requestTimestamp = self.requestTimestamp; | 29 | self.data.requestTimestamp = self.requestTimestamp; |
30 | self.data.responseTimestamp = self.responseTimestamp; | 30 | self.data.responseTimestamp = self.responseTimestamp; |
31 | self.data.byteLength = incomingData.byteLength; | 31 | self.data.byteLength = incomingData.byteLength; |
32 | self.data.isCached = parseInt(self.responseTimestamp - self.requestTimestamp) < 75; | 32 | self.data.isCached = parseInt(self.responseTimestamp - self.requestTimestamp,10) < 75; |
33 | self.data.throughput = self.calculateThroughput(self.data.byteLength, self.requestTimestamp ,self.responseTimestamp); | 33 | self.data.throughput = self.calculateThroughput(self.data.byteLength, self.requestTimestamp ,self.responseTimestamp); |
34 | 34 | ||
35 | return self.data; | 35 | return self.data; |
... | @@ -37,7 +37,7 @@ | ... | @@ -37,7 +37,7 @@ |
37 | 37 | ||
38 | self.calculateThroughput = function(dataAmount, startTime, endTime) { | 38 | self.calculateThroughput = function(dataAmount, startTime, endTime) { |
39 | return Math.round(dataAmount / (endTime - startTime) * 1000) * 8; | 39 | return Math.round(dataAmount / (endTime - startTime) * 1000) * 8; |
40 | } | 40 | }; |
41 | 41 | ||
42 | self.onSegmentLoadComplete = function(response) { | 42 | self.onSegmentLoadComplete = function(response) { |
43 | var output; | 43 | var output; |
... | @@ -57,8 +57,8 @@ | ... | @@ -57,8 +57,8 @@ |
57 | } | 57 | } |
58 | 58 | ||
59 | if (self.onErrorCallback !== undefined) { | 59 | if (self.onErrorCallback !== undefined) { |
60 | onErrorCallback(error); | 60 | self.onErrorCallback(error); |
61 | } | 61 | } |
62 | }; | 62 | }; |
63 | } | 63 | }; |
64 | })(this); | 64 | })(this); | ... | ... |
... | @@ -321,13 +321,14 @@ | ... | @@ -321,13 +321,14 @@ |
321 | 321 | ||
322 | test('should get a manifest from hermes', function () { | 322 | test('should get a manifest from hermes', function () { |
323 | manifestController.loadManifest('http://example.com/16x9-master.m3u8', | 323 | manifestController.loadManifest('http://example.com/16x9-master.m3u8', |
324 | function(responseData) { | 324 | function (responseData) { |
325 | ok(responseData); | 325 | ok(responseData); |
326 | }, | 326 | }, |
327 | function(errorData) { | 327 | function (errorData) { |
328 | ok(false, 'does not error'); | 328 | ok(false, 'does not error'); |
329 | }, | 329 | }, |
330 | function(updateData) {}); | 330 | function (updateData) { |
331 | }); | ||
331 | }); | 332 | }); |
332 | 333 | ||
333 | module('segment controller', { | 334 | module('segment controller', { | ... | ... |
-
Please register or sign in to post a comment