Merge pull request #534 from BrandonOCasey/browserify-p2
browserify-p2: m3u8, stream, and stub
Showing
19 changed files
with
141 additions
and
138 deletions
... | @@ -40,14 +40,17 @@ | ... | @@ -40,14 +40,17 @@ |
40 | </label> | 40 | </label> |
41 | <button type=submit>Load</button> | 41 | <button type=submit>Load</button> |
42 | </form> | 42 | </form> |
43 | <ul> | ||
44 | <li><a href="/test/">Run unit tests in browser.</a></li> | ||
45 | <li><a href="/docs/api/">Read generated docs.</a></li> | ||
46 | </ul> | ||
43 | 47 | ||
44 | <script src="/node_modules/video.js/dist/video.js"></script> | 48 | <script src="/node_modules/video.js/dist/video.js"></script> |
45 | <script src="/node_modules/videojs-contrib-media-sources/dist/videojs-media-sources.js"></script> | 49 | <script src="/node_modules/videojs-contrib-media-sources/dist/videojs-media-sources.js"></script> |
46 | <script src="/node_modules/pkcs7/dist/pkcs7.unpad.js"></script> | 50 | <script src="/node_modules/pkcs7/dist/pkcs7.unpad.js"></script> |
47 | <script src="/src/videojs-hls.js"></script> | 51 | <script src="/src/videojs-contrib-hls.js"></script> |
48 | <script src="/src/xhr.js"></script> | 52 | <script src="/src/xhr.js"></script> |
49 | <script src="/src/stream.js"></script> | 53 | <script src="/dist/videojs-contrib-hls.js"></script> |
50 | <script src="/src/m3u8/m3u8-parser.js"></script> | ||
51 | <script src="/src/playlist.js"></script> | 54 | <script src="/src/playlist.js"></script> |
52 | <script src="/src/playlist-loader.js"></script> | 55 | <script src="/src/playlist-loader.js"></script> |
53 | <script src="/src/decrypter.js"></script> | 56 | <script src="/src/decrypter.js"></script> | ... | ... |
... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
2 | "name": "videojs-contrib-hls", | 2 | "name": "videojs-contrib-hls", |
3 | "version": "1.3.5", | 3 | "version": "1.3.5", |
4 | "description": "Play back HLS with video.js, even where it's not natively supported", | 4 | "description": "Play back HLS with video.js, even where it's not natively supported", |
5 | "main": "es5/videojs-hls.js", | 5 | "main": "es5/stub.js", |
6 | "engines": { | 6 | "engines": { |
7 | "node": ">= 0.10.12" | 7 | "node": ">= 0.10.12" |
8 | }, | 8 | }, |
... | @@ -13,16 +13,17 @@ | ... | @@ -13,16 +13,17 @@ |
13 | "scripts": { | 13 | "scripts": { |
14 | "prebuild": "npm run clean", | 14 | "prebuild": "npm run clean", |
15 | "build": "npm-run-all -p build:*", | 15 | "build": "npm-run-all -p build:*", |
16 | "build:manifest": "node -e \"var b=require('./scripts/manifest-data.js'); b.build();\"", | ||
17 | "build:js": "npm-run-all build:js:babel build:js:browserify build:js:bannerize build:js:uglify", | 16 | "build:js": "npm-run-all build:js:babel build:js:browserify build:js:bannerize build:js:uglify", |
18 | "build:js:babel": "babel src -d es5", | 17 | "build:js:babel": "babel src -d es5", |
19 | "build:js:bannerize": "bannerize dist/videojs-contrib-hls.js --banner=scripts/banner.ejs", | 18 | "build:js:bannerize": "bannerize dist/videojs-contrib-hls.js --banner=scripts/banner.ejs", |
20 | "build:js:browserify": "browserify . -s src/videojs-hls.js -o dist/videojs-contrib-hls.js", | 19 | "build:js:browserify": "browserify . -s videojs-contrib-hls -o dist/videojs-contrib-hls.js", |
21 | "build:js:uglify": "uglifyjs dist/videojs-contrib-hls.js --comments --mangle --compress -o dist/videojs-contrib-hls.min.js", | 20 | "build:js:uglify": "uglifyjs dist/videojs-contrib-hls.js --comments --mangle --compress -o dist/videojs-contrib-hls.min.js", |
22 | "build:test": "node scripts/build-test.js", | 21 | "build:test": "npm-run-all build:test:manifest build:test:js", |
23 | "clean": "npm-run-all clean:*", | 22 | "build:test:js": "node scripts/build-test.js", |
23 | "build:test:manifest": "node -e \"var b=require('./scripts/manifest-data.js'); b.build();\"", | ||
24 | "clean": "npm-run-all -p clean:*", | ||
24 | "clean:build": "node -e \"var s=require('shelljs'),d=['dist','dist-test','es5'];s.rm('-rf',d);s.mkdir('-p',d);\"", | 25 | "clean:build": "node -e \"var s=require('shelljs'),d=['dist','dist-test','es5'];s.rm('-rf',d);s.mkdir('-p',d);\"", |
25 | "clean:manifest": "node -e \"var b=require('./scripts/manifest-data.js'); b.clean();\"", | 26 | "clean:test": "node -e \"var b=require('./scripts/manifest-data.js'); b.clean();\"", |
26 | "docs": "npm-run-all docs:*", | 27 | "docs": "npm-run-all docs:*", |
27 | "docs:api": "jsdoc src -r -d docs/api", | 28 | "docs:api": "jsdoc src -r -d docs/api", |
28 | "docs:toc": "doctoc README.md", | 29 | "docs:toc": "doctoc README.md", |
... | @@ -39,9 +40,10 @@ | ... | @@ -39,9 +40,10 @@ |
39 | "preversion": "npm test", | 40 | "preversion": "npm test", |
40 | "version": "npm run build", | 41 | "version": "npm run build", |
41 | "watch": "npm-run-all -p watch:*", | 42 | "watch": "npm-run-all -p watch:*", |
42 | "watch:manifest": "node -e \"var b=require('./scripts/manifest-data.js'); b.watch();\"", | 43 | "watch:js": "watchify src/stub.js -t babelify -v -o dist/videojs-contrib-hls.js", |
43 | "watch:js": "watchify src/videojs-hls.js -t babelify -v -o dist/videojs-contrib-hls.js", | 44 | "watch:test": "npm-run-all -p watch:test:*", |
44 | "watch:test": "node scripts/watch-test.js", | 45 | "watch:test:js": "node scripts/watch-test.js", |
46 | "watch:test:manifest": "node -e \"var b=require('./scripts/manifest-data.js'); b.watch();\"", | ||
45 | "prepublish": "npm run build" | 47 | "prepublish": "npm run build" |
46 | }, | 48 | }, |
47 | "keywords": [ | 49 | "keywords": [ |
... | @@ -69,7 +71,8 @@ | ... | @@ -69,7 +71,8 @@ |
69 | "test/karma", | 71 | "test/karma", |
70 | "scripts", | 72 | "scripts", |
71 | "utils", | 73 | "utils", |
72 | "test/data" | 74 | "test/test-manifests.js", |
75 | "test/test-expected.js" | ||
73 | ] | 76 | ] |
74 | }, | 77 | }, |
75 | "files": [ | 78 | "files": [ | ... | ... |
... | @@ -2,7 +2,7 @@ var browserify = require('browserify'); | ... | @@ -2,7 +2,7 @@ var browserify = require('browserify'); |
2 | var fs = require('fs'); | 2 | var fs = require('fs'); |
3 | var glob = require('glob'); | 3 | var glob = require('glob'); |
4 | 4 | ||
5 | glob('test/**/*.test.js', function(err, files) { | 5 | glob('test/{m3u8,stub}.test.js', function(err, files) { |
6 | browserify(files) | 6 | browserify(files) |
7 | .transform('babelify') | 7 | .transform('babelify') |
8 | .bundle() | 8 | .bundle() | ... | ... |
1 | var fs = require('fs'); | 1 | var fs = require('fs'); |
2 | var path = require('path'); | 2 | var path = require('path'); |
3 | 3 | ||
4 | var basePath = path.resolve(__dirname + '/..'); | 4 | var basePath = path.resolve(__dirname, '..'); |
5 | var testDataDir = basePath + '/test/data'; | 5 | var testDataDir = path.join(basePath,'test'); |
6 | var manifestDir = basePath + '/utils/manifest'; | 6 | var manifestDir = path.join(basePath, 'utils', 'manifest'); |
7 | var manifestFilepath = testDataDir + '/manifests.js'; | 7 | var manifestFilepath = path.join(testDataDir, 'test-manifests.js'); |
8 | var expectedFilepath = testDataDir + '/expected.js'; | 8 | var expectedFilepath = path.join(testDataDir, 'test-expected.js'); |
9 | |||
10 | 9 | ||
11 | var build = function() { | 10 | var build = function() { |
12 | var manifests = 'window.manifests = {\n'; | 11 | var manifests = 'export default {\n'; |
13 | var expected = 'window.expected = {\n'; | 12 | var expected = 'export default {\n'; |
14 | 13 | ||
15 | var files = fs.readdirSync(manifestDir); | 14 | var files = fs.readdirSync(manifestDir); |
16 | while (files.length > 0) { | 15 | while (files.length > 0) { | ... | ... |
... | @@ -3,7 +3,7 @@ var fs = require('fs'); | ... | @@ -3,7 +3,7 @@ var fs = require('fs'); |
3 | var glob = require('glob'); | 3 | var glob = require('glob'); |
4 | var watchify = require('watchify'); | 4 | var watchify = require('watchify'); |
5 | 5 | ||
6 | glob('test/**/*.test.js', function(err, files) { | 6 | glob('test/{m3u8,stub}.test.js', function(err, files) { |
7 | var b = browserify(files, { | 7 | var b = browserify(files, { |
8 | cache: {}, | 8 | cache: {}, |
9 | packageCache: {}, | 9 | packageCache: {}, | ... | ... |
src/.jshintrc
deleted
100644 → 0
This diff is collapsed.
Click to expand it.
... | @@ -2,73 +2,84 @@ | ... | @@ -2,73 +2,84 @@ |
2 | * A lightweight readable stream implemention that handles event dispatching. | 2 | * A lightweight readable stream implemention that handles event dispatching. |
3 | * Objects that inherit from streams should call init in their constructors. | 3 | * Objects that inherit from streams should call init in their constructors. |
4 | */ | 4 | */ |
5 | (function(videojs, undefined) { | 5 | export default class Stream { |
6 | var Stream = function() { | 6 | constructor() { |
7 | this.init = function() { | 7 | this.init(); |
8 | var listeners = {}; | 8 | } |
9 | /** | 9 | |
10 | * Add a listener for a specified event type. | 10 | init() { |
11 | * @param type {string} the event name | 11 | this.listeners = {}; |
12 | * @param listener {function} the callback to be invoked when an event of | 12 | } |
13 | * the specified type occurs | 13 | |
14 | */ | 14 | /** |
15 | this.on = function(type, listener) { | 15 | * Add a listener for a specified event type. |
16 | if (!listeners[type]) { | 16 | * @param type {string} the event name |
17 | listeners[type] = []; | 17 | * @param listener {function} the callback to be invoked when an event of |
18 | } | 18 | * the specified type occurs |
19 | listeners[type].push(listener); | 19 | */ |
20 | }; | 20 | on(type, listener) { |
21 | /** | 21 | if (!this.listeners[type]) { |
22 | * Remove a listener for a specified event type. | 22 | this.listeners[type] = []; |
23 | * @param type {string} the event name | 23 | } |
24 | * @param listener {function} a function previously registered for this | 24 | this.listeners[type].push(listener); |
25 | * type of event through `on` | 25 | } |
26 | */ | 26 | |
27 | this.off = function(type, listener) { | 27 | /** |
28 | var index; | 28 | * Remove a listener for a specified event type. |
29 | if (!listeners[type]) { | 29 | * @param type {string} the event name |
30 | return false; | 30 | * @param listener {function} a function previously registered for this |
31 | } | 31 | * type of event through `on` |
32 | index = listeners[type].indexOf(listener); | 32 | */ |
33 | listeners[type].splice(index, 1); | 33 | off(type, listener) { |
34 | return index > -1; | 34 | let index; |
35 | }; | 35 | |
36 | /** | 36 | if (!this.listeners[type]) { |
37 | * Trigger an event of the specified type on this stream. Any additional | 37 | return false; |
38 | * arguments to this function are passed as parameters to event listeners. | 38 | } |
39 | * @param type {string} the event name | 39 | index = this.listeners[type].indexOf(listener); |
40 | */ | 40 | this.listeners[type].splice(index, 1); |
41 | this.trigger = function(type) { | 41 | return index > -1; |
42 | var callbacks, i, length, args; | 42 | } |
43 | callbacks = listeners[type]; | 43 | |
44 | if (!callbacks) { | 44 | /** |
45 | return; | 45 | * Trigger an event of the specified type on this stream. Any additional |
46 | } | 46 | * arguments to this function are passed as parameters to event listeners. |
47 | // Slicing the arguments on every invocation of this method | 47 | * @param type {string} the event name |
48 | // can add a significant amount of overhead. Avoid the | 48 | */ |
49 | // intermediate object creation for the common case of a | 49 | trigger(type) { |
50 | // single callback argument | 50 | let callbacks; |
51 | if (arguments.length === 2) { | 51 | let i; |
52 | length = callbacks.length; | 52 | let length; |
53 | for (i = 0; i < length; ++i) { | 53 | let args; |
54 | callbacks[i].call(this, arguments[1]); | 54 | |
55 | } | 55 | callbacks = this.listeners[type]; |
56 | } else { | 56 | if (!callbacks) { |
57 | args = Array.prototype.slice.call(arguments, 1); | 57 | return; |
58 | length = callbacks.length; | 58 | } |
59 | for (i = 0; i < length; ++i) { | 59 | // Slicing the arguments on every invocation of this method |
60 | callbacks[i].apply(this, args); | 60 | // can add a significant amount of overhead. Avoid the |
61 | } | 61 | // intermediate object creation for the common case of a |
62 | } | 62 | // single callback argument |
63 | }; | 63 | if (arguments.length === 2) { |
64 | /** | 64 | length = callbacks.length; |
65 | * Destroys the stream and cleans up. | 65 | for (i = 0; i < length; ++i) { |
66 | */ | 66 | callbacks[i].call(this, arguments[1]); |
67 | this.dispose = function() { | 67 | } |
68 | listeners = {}; | 68 | } else { |
69 | }; | 69 | args = Array.prototype.slice.call(arguments, 1); |
70 | }; | 70 | length = callbacks.length; |
71 | }; | 71 | for (i = 0; i < length; ++i) { |
72 | callbacks[i].apply(this, args); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Destroys the stream and cleans up. | ||
79 | */ | ||
80 | dispose() { | ||
81 | this.listeners = {}; | ||
82 | } | ||
72 | /** | 83 | /** |
73 | * Forwards all `data` events on this stream to the destination stream. The | 84 | * Forwards all `data` events on this stream to the destination stream. The |
74 | * destination stream should provide a method `push` to receive the data | 85 | * destination stream should provide a method `push` to receive the data |
... | @@ -76,11 +87,9 @@ | ... | @@ -76,11 +87,9 @@ |
76 | * @param destination {stream} the stream that will receive all `data` events | 87 | * @param destination {stream} the stream that will receive all `data` events |
77 | * @see http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options | 88 | * @see http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options |
78 | */ | 89 | */ |
79 | Stream.prototype.pipe = function(destination) { | 90 | pipe(destination) { |
80 | this.on('data', function(data) { | 91 | this.on('data', function(data) { |
81 | destination.push(data); | 92 | destination.push(data); |
82 | }); | 93 | }); |
83 | }; | 94 | } |
84 | 95 | } | |
85 | videojs.Hls.Stream = Stream; | ||
86 | })(window.videojs); | ... | ... |
src/stub.js
0 → 100644
... | @@ -16,22 +16,16 @@ | ... | @@ -16,22 +16,16 @@ |
16 | <script src="/node_modules/video.js/dist/video.js"></script> | 16 | <script src="/node_modules/video.js/dist/video.js"></script> |
17 | <script src="/node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script> | 17 | <script src="/node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script> |
18 | 18 | ||
19 | <script src="/src/videojs-hls.js"></script> | 19 | <script src="/src/videojs-contrib-hls.js"></script> |
20 | <script src="/src/xhr.js"></script> | 20 | <script src="/src/xhr.js"></script> |
21 | <script src="/src/stream.js"></script> | 21 | <script src="/dist/videojs-contrib-hls.js"></script> |
22 | <script src="/src/m3u8/m3u8-parser.js"></script> | ||
23 | <script src="/src/playlist.js"></script> | 22 | <script src="/src/playlist.js"></script> |
24 | <script src="/src/playlist-loader.js"></script> | 23 | <script src="/src/playlist-loader.js"></script> |
25 | <script src="/src/decrypter.js"></script> | 24 | <script src="/src/decrypter.js"></script> |
26 | <script src="/src/bin-utils.js"></script> | 25 | <script src="/src/bin-utils.js"></script> |
27 | 26 | ||
28 | <script src="/test/data/manifests.js"></script> | 27 | <script src="/test/videojs-contrib-hls.test.js"></script> |
29 | <script src="/test/data/expected.js"></script> | 28 | <script src="/dist-test/videojs-contrib-hls.js"></script> |
30 | <script src="/test/data/ts-segment-bc.js"></script> | ||
31 | |||
32 | |||
33 | <script src="/test/videojs-hls.test.js"></script> | ||
34 | <script src="/test/m3u8.test.js"></script> | ||
35 | <script src="/test/playlist.test.js"></script> | 29 | <script src="/test/playlist.test.js"></script> |
36 | <script src="/test/playlist-loader.test.js"></script> | 30 | <script src="/test/playlist-loader.test.js"></script> |
37 | <script src="/test/decrypter.test.js"></script> | 31 | <script src="/test/decrypter.test.js"></script> | ... | ... |
... | @@ -2,8 +2,7 @@ var merge = require('lodash-compat/object/merge'); | ... | @@ -2,8 +2,7 @@ var merge = require('lodash-compat/object/merge'); |
2 | 2 | ||
3 | var DEFAULTS = { | 3 | var DEFAULTS = { |
4 | basePath: '../..', | 4 | basePath: '../..', |
5 | //frameworks: ['browserify', 'qunit'], | 5 | frameworks: ['browserify', 'qunit'], |
6 | frameworks: ['qunit'], | ||
7 | 6 | ||
8 | 7 | ||
9 | files: [ | 8 | files: [ |
... | @@ -16,20 +15,19 @@ var DEFAULTS = { | ... | @@ -16,20 +15,19 @@ var DEFAULTS = { |
16 | 'node_modules/pkcs7/dist/pkcs7.unpad.js', | 15 | 'node_modules/pkcs7/dist/pkcs7.unpad.js', |
17 | 'node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js', | 16 | 'node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js', |
18 | 17 | ||
19 | 'src/videojs-hls.js', | 18 | // these two stub old functionality |
19 | 'src/videojs-contrib-hls.js', | ||
20 | 'src/xhr.js', | 20 | 'src/xhr.js', |
21 | 'src/stream.js', | 21 | 'dist/videojs-contrib-hls.js', |
22 | 'src/m3u8/m3u8-parser.js', | 22 | |
23 | 'src/playlist.js', | 23 | 'src/playlist.js', |
24 | 'src/playlist-loader.js', | 24 | 'src/playlist-loader.js', |
25 | 'src/decrypter.js', | 25 | 'src/decrypter.js', |
26 | 'src/bin-utils.js', | 26 | 'src/bin-utils.js', |
27 | 27 | ||
28 | 'test/data/manifests.js', | 28 | 'test/stub.test.js', |
29 | 'test/data/expected.js', | ||
30 | 'test/data/ts-segment-bc.js', | ||
31 | 29 | ||
32 | 'test/videojs-hls.test.js', | 30 | 'test/videojs-contrib-hls.test.js', |
33 | 'test/m3u8.test.js', | 31 | 'test/m3u8.test.js', |
34 | 'test/playlist.test.js', | 32 | 'test/playlist.test.js', |
35 | 'test/playlist-loader.test.js', | 33 | 'test/playlist-loader.test.js', |
... | @@ -44,12 +42,12 @@ var DEFAULTS = { | ... | @@ -44,12 +42,12 @@ var DEFAULTS = { |
44 | ], | 42 | ], |
45 | 43 | ||
46 | plugins: [ | 44 | plugins: [ |
47 | // 'karma-browserify', | 45 | 'karma-browserify', |
48 | 'karma-qunit' | 46 | 'karma-qunit' |
49 | ], | 47 | ], |
50 | 48 | ||
51 | preprocessors: { | 49 | preprocessors: { |
52 | // 'test/**/*.js': ['browserify'] | 50 | 'test/{stub,m3u8}.test.js': ['browserify'] |
53 | }, | 51 | }, |
54 | 52 | ||
55 | reporters: ['dots'], | 53 | reporters: ['dots'], |
... | @@ -59,18 +57,16 @@ var DEFAULTS = { | ... | @@ -59,18 +57,16 @@ var DEFAULTS = { |
59 | singleRun: true, | 57 | singleRun: true, |
60 | concurrency: Infinity, | 58 | concurrency: Infinity, |
61 | 59 | ||
62 | /* | ||
63 | browserify: { | 60 | browserify: { |
64 | debug: true, | 61 | debug: true, |
65 | transform: [ | 62 | transform: [ |
66 | 'babelify', | 63 | 'babelify', |
67 | 'browserify-shim' | 64 | 'browserify-shim' |
68 | ], | 65 | ], |
69 | noparse: [ | 66 | noParse: [ |
70 | 'test/data/**', | 67 | 'test/data/**', |
71 | ] | 68 | ] |
72 | } | 69 | } |
73 | */ | ||
74 | }; | 70 | }; |
75 | 71 | ||
76 | /** | 72 | /** | ... | ... |
... | @@ -29,6 +29,7 @@ module.exports = function(config) { | ... | @@ -29,6 +29,7 @@ module.exports = function(config) { |
29 | postDetection: function(availableBrowsers) { | 29 | postDetection: function(availableBrowsers) { |
30 | var safariIndex = availableBrowsers.indexOf('Safari'); | 30 | var safariIndex = availableBrowsers.indexOf('Safari'); |
31 | if(safariIndex !== -1) { | 31 | if(safariIndex !== -1) { |
32 | console.log("Not running safari it is/was broken"); | ||
32 | availableBrowsers.splice(safariIndex, 1); | 33 | availableBrowsers.splice(safariIndex, 1); |
33 | } | 34 | } |
34 | return availableBrowsers; | 35 | return availableBrowsers; | ... | ... |
This diff is collapsed.
Click to expand it.
test/stub.test.js
0 → 100644
-
Please register or sign in to post a comment