Browse Source
Update to vjs-MSE 0.2.0
Update to vjs-MSE 0.2.0
Remove async tag queueing from HLS since that is now happening in the media sources plugin itself. Update the location of MSE source files. Bump the dependency in package.json. Two tests are still failing with this commit but will be fixed shortly.pull/80/head

8 changed files with 14 additions and 131 deletions
-
3example.html
-
2package.json
-
37src/async-queue.js
-
19src/videojs-hls.js
-
72test/async-queue_test.js
-
2test/karma.conf.js
-
4test/localkarma.conf.js
-
6test/videojs-hls.html
@ -1,37 +0,0 @@ |
|||
(function(window, videojs, undefined) { |
|||
'use strict'; |
|||
/** |
|||
* A queue object that manages tasks that should be processed |
|||
* serially but asynchronously. Loosely adapted from |
|||
* https://github.com/caolan/async#queue.
|
|||
* @param worker {function} the callback to invoke with each value |
|||
* pushed onto the queue |
|||
* @return {object} an object with an array of `tasks` that remain to |
|||
* be processed and function `push` to add new tasks |
|||
*/ |
|||
videojs.hls.queue = function(worker) { |
|||
var |
|||
q = { |
|||
tasks: [], |
|||
running: false, |
|||
push: function(task) { |
|||
q.tasks.push(task); |
|||
if (!q.running) { |
|||
window.setTimeout(process, 0); |
|||
q.running = true; |
|||
} |
|||
} |
|||
}, |
|||
process = function() { |
|||
var task; |
|||
if (q.tasks.length) { |
|||
task = q.tasks.shift(); |
|||
worker.call(this, task); |
|||
window.setTimeout(process, 0); |
|||
} else { |
|||
q.running = false; |
|||
} |
|||
}; |
|||
return q; |
|||
}; |
|||
})(window, window.videojs); |
@ -1,72 +0,0 @@ |
|||
(function(window, queue, undefined) { |
|||
var |
|||
oldSetTimeout, |
|||
callbacks; |
|||
module('async queue', { |
|||
setup: function() { |
|||
oldSetTimeout = window.setTimeout; |
|||
callbacks = []; |
|||
window.setTimeout = function(callback) { |
|||
callbacks.push(callback); |
|||
}; |
|||
}, |
|||
teardown: function() { |
|||
window.setTimeout = oldSetTimeout; |
|||
} |
|||
}); |
|||
|
|||
test('runs tasks asynchronously', function() { |
|||
var |
|||
run = false, |
|||
q = queue(function() { |
|||
run = true; |
|||
}); |
|||
q.push(1); |
|||
|
|||
ok(!run, 'tasks are not run immediately'); |
|||
|
|||
callbacks[0](); |
|||
ok(run, 'tasks are run asynchronously'); |
|||
}); |
|||
|
|||
test('runs one task at a time', function() { |
|||
var q = queue(function() {}); |
|||
q.push(1); |
|||
q.push(2); |
|||
q.push(3); |
|||
q.push(4); |
|||
q.push(5); |
|||
|
|||
strictEqual(q.tasks.length, 5, 'all tasks are queued'); |
|||
strictEqual(1, callbacks.length, 'one callback is registered'); |
|||
}); |
|||
|
|||
test('tasks are scheduled until the queue is empty', function() { |
|||
var q = queue(function() {}); |
|||
q.push(1); |
|||
q.push(2); |
|||
|
|||
callbacks.shift()(); |
|||
strictEqual(1, callbacks.length, 'the next task is scheduled'); |
|||
|
|||
callbacks.shift()(); |
|||
strictEqual(1, callbacks.length, 'nothing is scheduled on an empty queue'); |
|||
}); |
|||
|
|||
test('can be emptied at any time', function() { |
|||
var |
|||
runs = 0, |
|||
q = queue(function() { |
|||
runs++; |
|||
}); |
|||
q.push(1); |
|||
q.push(2); |
|||
|
|||
callbacks.shift()(); |
|||
strictEqual(1, runs, 'task one is run'); |
|||
|
|||
q.tasks = []; |
|||
callbacks.shift()(); |
|||
strictEqual(1, runs, 'the remaining tasks are cancelled'); |
|||
}); |
|||
})(window, window.videojs.hls.queue); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue