Skip to content

Commit

Permalink
Merge pull request #20 from voxmedia/remove-hls-hacks
Browse files Browse the repository at this point in the history
Removes Unused HLS test code
  • Loading branch information
Brian Anderson authored Mar 21, 2019
2 parents 4f2ff08 + 3e27f1d commit c9e0d32
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 70 deletions.
4 changes: 0 additions & 4 deletions src/lib/vast.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ export default class Vast {
return this.loadedElements['MediaFiles'].videos();
}

asHLSUrl() {
return this.loadedElements['MediaFiles'].asHLSUrl();
}

clickthroughUrl() {
return this.loadedElements['Clickthrough'].clickthroughUrl();
}
Expand Down
42 changes: 0 additions & 42 deletions src/lib/vast_elements/media_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,11 @@ class MediaFile {
return NodeValue.fromElement(this.element);
}

codec() {
switch (this.mimeType()) {
case 'video/mp4':
case 'video/3gpp':
return 'mp4v';
break;
case 'video/webm':
return 'vp8';
break;
default:
throw TypeError('Unknown mime type ' + this.mimeType());
}
}

isVideoType() {
return this.mimeType().match(/^video\//);
}
}

//
class HlsMasterPlaylistFile {
constructor(videos = []) {
this.videos = videos;
}

contents() {
let contents = [];
contents.push('#EXTM3U');

contents = [
contents,
...this.videos.map(v => {
return `#EXT-X-STREAM-INF:BANDWIDTH=${v.bitrate() *
1024},RESOLUTION=${v.width()}x${v.height()},CODEC=${v.codec()}\n${v.url()}`;
}),
];

return contents.join('\n');
}
// ----
}

export default class MediaFiles extends VastElementBase {
// Think of this as the constructor
setup() {
Expand All @@ -93,9 +56,4 @@ export default class MediaFiles extends VastElementBase {
return v.isVideoType();
});
}

asHLSUrl() {
const hlsMaker = new HlsMasterPlaylistFile(this.videos());
return 'data:application/x-mpegURL;base64,' + btoa(hlsMaker.contents());
}
}
24 changes: 0 additions & 24 deletions test/vast_elements/media_files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,3 @@ describe('Media Files extension', () => {
expect(video.width()).toBe(640);
});
});

describe('MediaFile to HLS Url', () => {
let xmlString;
let vast;

beforeAll(() => {
xmlString = fs.readFileSync('./test/fixtures/vast.xml');
vast = new Vast({ xml: xmlString });
});

it('should return a data url', () => {
expect(vast.asHLSUrl()).toBeDefined();
expect(vast.asHLSUrl()).toMatch(/^data:application\/x-mpegURL/);
});

it('should conform to m3u8 headers', () => {
const dataUrl = vast.asHLSUrl();
const contents = atob(dataUrl.split(',')[1]);
expect(contents).toMatch(/^#EXTM3U/);
const contentArrayAsLines = contents.split('\n');
expect(contentArrayAsLines[1]).toBe('#EXT-X-STREAM-INF:BANDWIDTH=268288,RESOLUTION=640x360,CODEC=mp4v');
expect(contentArrayAsLines[2]).toBe(vast.videos()[0].url());
});
});

0 comments on commit c9e0d32

Please sign in to comment.