Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: export corrections #68

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/ad-cue-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import window from 'global/window';
/**
* Searches for an ad cue that overlaps with the given mediaTime
*/
const findAdCue = function(track, mediaTime) {
export const findAdCue = function(track, mediaTime) {
let cues = track.cues;

for (let i = 0; i < cues.length; i++) {
Expand All @@ -19,7 +19,7 @@ const findAdCue = function(track, mediaTime) {
return null;
};

const updateAdCues = function(media, track, offset = 0) {
export const updateAdCues = function(media, track, offset = 0) {
if (!media.segments) {
return;
}
Expand Down Expand Up @@ -89,9 +89,3 @@ const updateAdCues = function(media, track, offset = 0) {
mediaTime += segment.duration;
}
};

export default {
updateAdCues,
findAdCue
};

55 changes: 25 additions & 30 deletions src/bin-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const formatAsciiString = function(e) {
* Modified message with TypedArray values expanded
* @function createTransferableMessage
*/
const createTransferableMessage = function(message) {
export const createTransferableMessage = function(message) {
const transferable = {};

Object.keys(message).forEach((key) => {
Expand All @@ -64,7 +64,7 @@ const createTransferableMessage = function(message) {
* Returns a unique string identifier for a media initialization
* segment.
*/
const initSegmentId = function(initSegment) {
export const initSegmentId = function(initSegment) {
let byterange = initSegment.byterange || {
length: Infinity,
offset: 0
Expand All @@ -78,35 +78,30 @@ const initSegmentId = function(initSegment) {
/**
* utils to help dump binary data to the console
*/
const utils = {
hexDump(data) {
let bytes = Array.prototype.slice.call(data);
let step = 16;
let result = '';
let hex;
let ascii;
export const hexDump = (data) => {
let bytes = Array.prototype.slice.call(data);
let step = 16;
let result = '';
let hex;
let ascii;

for (let j = 0; j < bytes.length / step; j++) {
hex = bytes.slice(j * step, j * step + step).map(formatHexString).join('');
ascii = bytes.slice(j * step, j * step + step).map(formatAsciiString).join('');
result += hex + ' ' + ascii + '\n';
}
return result;
},
tagDump(tag) {
return utils.hexDump(tag.bytes);
},
textRanges(ranges) {
let result = '';
let i;
for (let j = 0; j < bytes.length / step; j++) {
hex = bytes.slice(j * step, j * step + step).map(formatHexString).join('');
ascii = bytes.slice(j * step, j * step + step).map(formatAsciiString).join('');
result += hex + ' ' + ascii + '\n';
}

for (i = 0; i < ranges.length; i++) {
result += textRange(ranges, i) + ' ';
}
return result;
},
createTransferableMessage,
initSegmentId
return result;
};

export default utils;
export const tagDump = ({ bytes }) => hexDump(bytes);

export const textRanges = (ranges) => {
let result = '';
let i;

for (i = 0; i < ranges.length; i++) {
result += textRange(ranges, i) + ' ';
}
return result;
};
6 changes: 2 additions & 4 deletions src/decrypter-worker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import window from 'global/window';
import {Decrypter} from 'aes-decrypter';
import BinUtils from './bin-utils';

const { createTransferableMessage } = BinUtils;
import { Decrypter } from 'aes-decrypter';
import { createTransferableMessage } from './bin-utils';

/**
* Our web worker interface so that things can talk to aes-decrypter
Expand Down
4 changes: 2 additions & 2 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SegmentLoader from './segment-loader';
import VTTSegmentLoader from './vtt-segment-loader';
import * as Ranges from './ranges';
import videojs from 'video.js';
import AdCueTags from './ad-cue-tags';
import { updateAdCues } from './ad-cue-tags';
import SyncController from './sync-controller';
import worker from 'webwackify';
import Decrypter from './decrypter-worker';
Expand Down Expand Up @@ -1098,7 +1098,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
offset = seekable.start(0);
}

AdCueTags.updateAdCues(media, this.cueTagsTrack_, offset);
updateAdCues(media, this.cueTagsTrack_, offset);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import videojs from 'video.js';
import BinUtils from './bin-utils';

const { createTransferableMessage } = BinUtils;
import { createTransferableMessage } from './bin-utils';

export const REQUEST_ERRORS = {
FAILURE: 2,
Expand Down
4 changes: 1 addition & 3 deletions src/mse/remove-cues-from-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param {Object} track the text track to remove the cues from
* @private
*/
const removeCuesFromTrack = function(start, end, track) {
export const removeCuesFromTrack = function(start, end, track) {
let i;
let cue;

Expand All @@ -33,5 +33,3 @@ const removeCuesFromTrack = function(start, end, track) {
}
}
};

export default removeCuesFromTrack;
6 changes: 3 additions & 3 deletions src/mse/virtual-source-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
import videojs from 'video.js';
import createTextTracksIfNecessary from './create-text-tracks-if-necessary';
import removeCuesFromTrack from './remove-cues-from-track';
import {addTextTrackData} from './add-text-track-data';
import { removeCuesFromTrack } from './remove-cues-from-track';
import { addTextTrackData } from './add-text-track-data';
import work from 'webwackify';
import transmuxWorker from './transmuxer-worker';
import {isAudioCodec, isVideoCodec} from './codec-utils';
import { isAudioCodec, isVideoCodec } from './codec-utils';

const workerResolve = () => {
let result;
Expand Down
8 changes: 3 additions & 5 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import videojs from 'video.js';
import SourceUpdater from './source-updater';
import Config from './config';
import window from 'global/window';
import removeCuesFromTrack from './mse/remove-cues-from-track';
import BinUtils from './bin-utils';
import {mediaSegmentRequest, REQUEST_ERRORS} from './media-segment-request';
import { removeCuesFromTrack } from './mse/remove-cues-from-track';
import { initSegmentId } from './bin-utils';
import { mediaSegmentRequest, REQUEST_ERRORS } from './media-segment-request';
import { TIME_FUDGE_FACTOR, timeUntilRebuffer as timeUntilRebuffer_ } from './ranges';
import { minRebufferMaxBandwidthSelector } from './playlist-selectors';
import logger from './util/logger';

const { initSegmentId } = BinUtils;

// in ms
const CHECK_BUFFER_DELAY = 500;

Expand Down
4 changes: 2 additions & 2 deletions src/sync-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

import mp4probe from 'mux.js/lib/mp4/probe';
import {inspect as tsprobe} from 'mux.js/lib/tools/ts-inspector.js';
import {sumDurations} from './playlist';
import { inspect as tsprobe } from 'mux.js/lib/tools/ts-inspector.js';
import { sumDurations } from './playlist';
import videojs from 'video.js';
import logger from './util/logger';

Expand Down
2 changes: 1 addition & 1 deletion src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PlaylistLoader from './playlist-loader';
import Playlist from './playlist';
import xhrFactory from './xhr';
import { Decrypter, AsyncStream, decrypt } from 'aes-decrypter';
import utils from './bin-utils';
import * as utils from './bin-utils';
import { timeRangesToArray } from './ranges';
import { MediaSource, URL } from './mse';
import videojs from 'video.js';
Expand Down
6 changes: 2 additions & 4 deletions src/vtt-segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import SegmentLoader from './segment-loader';
import videojs from 'video.js';
import window from 'global/window';
import removeCuesFromTrack from './mse/remove-cues-from-track';
import BinUtils from './bin-utils';

const { initSegmentId } = BinUtils;
import { removeCuesFromTrack } from './mse/remove-cues-from-track';
import { initSegmentId } from './bin-utils';

const VTT_LINE_TERMINATORS =
new Uint8Array('\n\n'.split('').map(char => char.charCodeAt(0)));
Expand Down
30 changes: 15 additions & 15 deletions test/ad-cue-tags.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QUnit from 'qunit';
import AdCueTags from '../src/ad-cue-tags';
import { updateAdCues, findAdCue } from '../src/ad-cue-tags';
import window from 'global/window';

QUnit.module('AdCueTags', {
Expand All @@ -22,7 +22,7 @@ QUnit.test('update tag cues', function(assert) {

this.track.addCue(testCue);

AdCueTags.updateAdCues({}, this.track);
updateAdCues({}, this.track);

assert.equal(this.track.cues.length,
1,
Expand All @@ -31,7 +31,7 @@ QUnit.test('update tag cues', function(assert) {
testCue,
'does not change cues if media does not have segment property');

AdCueTags.updateAdCues({
updateAdCues({
segments: []
}, this.track);

Expand All @@ -41,7 +41,7 @@ QUnit.test('update tag cues', function(assert) {

this.track.clearTrack();

AdCueTags.updateAdCues({
updateAdCues({
segments: [{
duration: 5.1,
cueOut: '11.5'
Expand All @@ -62,7 +62,7 @@ QUnit.test('update tag cues', function(assert) {

this.track.clearTrack();

AdCueTags.updateAdCues({
updateAdCues({
segments: [{
duration: 10,
cueOutCont: '10/30'
Expand All @@ -86,7 +86,7 @@ QUnit.test('update tag cues', function(assert) {
});

QUnit.test('update incomplete cue in live playlist situation', function(assert) {
AdCueTags.updateAdCues({
updateAdCues({
segments: [
{
duration: 10,
Expand All @@ -108,7 +108,7 @@ QUnit.test('update incomplete cue in live playlist situation', function(assert)
assert.equal(testCue.adStartTime, 10, 'cue ad starts at 10');
assert.equal(testCue.adEndTime, 40, 'cue ad ends at 40');

AdCueTags.updateAdCues({
updateAdCues({
segments: [
{
duration: 10,
Expand All @@ -128,7 +128,7 @@ QUnit.test('update incomplete cue in live playlist situation', function(assert)
assert.equal(testCue.adStartTime, 10, 'cue ad still starts at 10');
assert.equal(testCue.adEndTime, 40, 'cue ad still ends at 40');

AdCueTags.updateAdCues({
updateAdCues({
segments: [
{
duration: 10,
Expand All @@ -150,7 +150,7 @@ QUnit.test('update incomplete cue in live playlist situation', function(assert)
});

QUnit.test('adjust cue end time in event of early CUE-IN', function(assert) {
AdCueTags.updateAdCues({
updateAdCues({
segments: [
{
duration: 10,
Expand All @@ -176,7 +176,7 @@ QUnit.test('adjust cue end time in event of early CUE-IN', function(assert) {
assert.equal(testCue.adStartTime, 10, 'cue ad starts at 10');
assert.equal(testCue.adEndTime, 40, 'cue ad ends at 40');

AdCueTags.updateAdCues({
updateAdCues({
segments: [
{
duration: 10,
Expand All @@ -202,7 +202,7 @@ QUnit.test('adjust cue end time in event of early CUE-IN', function(assert) {
});

QUnit.test('correctly handle multiple ad cues', function(assert) {
AdCueTags.updateAdCues({
updateAdCues({
segments: [
{
duration: 10
Expand Down Expand Up @@ -285,15 +285,15 @@ QUnit.test('findAdCue returns correct cue', function(assert) {

let cue;

cue = AdCueTags.findAdCue(this.track, 15);
cue = findAdCue(this.track, 15);
assert.equal(cue.adStartTime, 0, 'returned correct cue');

cue = AdCueTags.findAdCue(this.track, 40);
cue = findAdCue(this.track, 40);
assert.equal(cue, null, 'cue not found, returned null');

cue = AdCueTags.findAdCue(this.track, 120);
cue = findAdCue(this.track, 120);
assert.equal(cue.adStartTime, 100, 'returned correct cue');

cue = AdCueTags.findAdCue(this.track, 45);
cue = findAdCue(this.track, 45);
assert.equal(cue.adStartTime, 45, 'returned correct cue');
});
2 changes: 1 addition & 1 deletion test/browserify-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-var */
/* eslint-env qunit */
var hls = require('../es5/videojs-http-streaming.js');
var hls = require('../');
var q = window.QUnit;

q.module('Browserify Require');
Expand Down
4 changes: 2 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="utf-8">
<title>video.js HLS Plugin Test Suite</title>
<link rel="stylesheet" href="/node_modules/qunitjs/qunit/qunit.css" media="screen">
<link rel="stylesheet" href="/node_modules/video.js/dist/video-js.css" media="screen">
<link rel="stylesheet" href="/node_modules/qunitjs/qunit/qunit.css">
<link rel="stylesheet" href="/node_modules/video.js/dist/video-js.css">
</head>
<body>
<div id="qunit"></div>
Expand Down
2 changes: 1 addition & 1 deletion test/webpack-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let hls = require('../es5/videojs-http-streaming.js');
let hls = require('../');
let q = window.QUnit;

q.module('Webpack Require');
Expand Down