Skip to content

Commit

Permalink
Expose SUBTITLE & ALT_AUDIO env-var to customise light dists
Browse files Browse the repository at this point in the history
By default SUBTITLE & ALT_AUDIO env-vars are set to:
- true for "main" dists (hls.js and hls.min.js)
- false for "light" dists (hls.light.js and hls.light.min.js)
  • Loading branch information
dighan authored and mangui committed Jul 18, 2017
1 parent c7fe66e commit dc74ced
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Headers" : true,
"escape" : true,
"__VERSION__" : true,
"__BUILD_VERSION__" : true
"__SUBTITLE__" : true,
"__ALT_AUDIO__" : true
}
}
21 changes: 12 additions & 9 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@ export var hlsDefaultConfig = {
minAutoBitrate: 0 // used by hls
};

if (typeof __BUILD_VERSION__ === 'undefined' || __BUILD_VERSION__ === 'full') {
hlsDefaultConfig.audioStreamController = AudioStreamController;
hlsDefaultConfig.audioTrackController = AudioTrackController;
if (typeof __SUBTITLE__ !== 'undefined' && __SUBTITLE__) {
hlsDefaultConfig.subtitleStreamController = SubtitleStreamController;
hlsDefaultConfig.subtitleTrackController = SubtitleTrackController;
hlsDefaultConfig.timelineController = TimelineController;
hlsDefaultConfig.cueHandler = Cues;
hlsDefaultConfig.enableCEA708Captions = true; // used by timeline-controller
hlsDefaultConfig.enableWebVTT = true; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack1Label = 'English'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack1LanguageCode = 'en'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack2Label = 'Spanish'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack2LanguageCode = 'es'; // used by timeline-controller
hlsDefaultConfig.enableCEA708Captions = true; // used by timeline-controller
hlsDefaultConfig.enableWebVTT = true; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack1Label = 'English'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack1LanguageCode = 'en'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack2Label = 'Spanish'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack2LanguageCode = 'es'; // used by timeline-controller
}

if (typeof __ALT_AUDIO__ !== 'undefined' && __ALT_AUDIO__) {
hlsDefaultConfig.audioStreamController = AudioStreamController;
hlsDefaultConfig.audioTrackController = AudioTrackController;
}
99 changes: 62 additions & 37 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ const pkgJson = require('./package.json');
const path = require('path');
const webpack = require('webpack');

const buildConstants = {
__VERSION__: JSON.stringify(pkgJson.version),
__BUILD_VERSION__: process.env.BUILD_VERSION || 'full'
};

const uglifyJsOptions = {
screwIE8: true,
stats: true,
Expand Down Expand Up @@ -36,19 +31,63 @@ const commonConfig = {
}
};

const commonPlugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin(buildConstants)
];
// Allow to customise light dists through env-vars.
const env = process.env;
const addSubtitleSupport = (typeof env.SUBTITLE !== 'undefined' && env.SUBTITLE);
const addAltAudioSupport = (typeof env.ALT_AUDIO !== 'undefined' && env.ALT_AUDIO);

function getPluginsForConfig(type, minify = false) {
// common plugins.
const plugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin(getConstantsForConfig(type))
];

if (minify) {
// minification plugins.
return plugins.concat([
new webpack.optimize.UglifyJsPlugin(uglifyJsOptions),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})
]);
}

return plugins;
}

function getConstantsForConfig(type) {
// By default the "main" dists (hls.js & hls.min.js) are full-featured.
return {
__VERSION__: JSON.stringify(pkgJson.version),
__SUBTITLE__: JSON.stringify(type === 'main' ? true: addSubtitleSupport),
__ALT_AUDIO__: JSON.stringify(type === 'main' ? true : addAltAudioSupport)
};
}

const distPlugins = commonPlugins.concat([
new webpack.optimize.UglifyJsPlugin(uglifyJsOptions),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})
]);
function getAliasesForLightDist() {
let aliases = {};

if (!addSubtitleSupport) {
aliases = Object.assign({}, aliases, {
'./utils/cues': './empty.js',
'./controller/timeline-controller': './empty.js',
'./controller/subtitle-track-controller': './empty.js',
'./controller/subtitle-stream-controller': './empty.js'
});
}

if (!addAltAudioSupport) {
aliases = Object.assign({}, aliases, {
'./controller/audio-track-controller': './empty.js',
'./controller/audio-stream-controller': './empty.js'
});
}

return aliases;
}

const multiConfig = [
{
Expand All @@ -63,7 +102,7 @@ const multiConfig = [
libraryTarget: 'umd',
libraryExport: 'default'
},
plugins: commonPlugins,
plugins: getPluginsForConfig('main'),
devtool: 'source-map',
},
{
Expand All @@ -77,7 +116,7 @@ const multiConfig = [
libraryTarget: 'umd',
libraryExport: 'default'
},
plugins: distPlugins
plugins: getPluginsForConfig('main', true)
},
{
name: 'light',
Expand All @@ -92,16 +131,9 @@ const multiConfig = [
libraryExport: 'default'
},
resolve: {
alias: {
'./controller/audio-track-controller': './empty.js',
'./controller/audio-stream-controller': './empty.js',
'./utils/cues': './empty.js',
'./controller/timeline-controller': './empty.js',
'./controller/subtitle-track-controller': './empty.js',
'./controller/subtitle-stream-controller': './empty.js'
}
alias: getAliasesForLightDist()
},
plugins: commonPlugins,
plugins: getPluginsForConfig('light'),
devtool: 'source-map'
},
{
Expand All @@ -116,16 +148,9 @@ const multiConfig = [
libraryExport: 'default'
},
resolve: {
alias: {
'./controller/audio-track-controller': './empty.js',
'./controller/audio-stream-controller': './empty.js',
'./utils/cues': './empty.js',
'./controller/timeline-controller': './empty.js',
'./controller/subtitle-track-controller': './empty.js',
'./controller/subtitle-stream-controller': './empty.js'
}
alias: getAliasesForLightDist()
},
plugins: distPlugins
plugins: getPluginsForConfig('light', true)
}
].map(fragment => Object.assign({}, commonConfig, fragment));

Expand Down

0 comments on commit dc74ced

Please sign in to comment.