For a few days now, I have been struggling to create a single JavaScript file that contains all the necessary components to play videos with Google IMA ads. However, I keep encountering errors, particularly player.ads is not function
, which seem to be related to incorrectly registered plugins. Any suggestions would be greatly appreciated. Thank you.
UPDATE: This issue has already been reported here, but it's labeled as priority 3 and I can't afford to wait. I believe there must be another solution.
UPDATE2: It appears that the individual who reported the issue in the link above has come up with a suitable solution. Now I just need to test it out... if it works, I will share it as an answer.
Entryfile:
/*jshint esversion: 6 */
/*jshint -W030 */
let ima_script = document.createElement('script');
ima_script.type = "text/javascript";
ima_script.src = "https://imasdk.googleapis.com/js/sdkloader/ima3.js";
document.getElementsByTagName('head')[0].appendChild(ima_script);
videojs = require('video.js');
require('videojs-contrib-ads');
require('videojs-ima');
require('videojs-youtube');
require('videojs-contrib-hls');
Array.from(document.getElementsByTagName('video'))
.forEach(videojs);
ima_script.onload = function() {
google.ima.settings.setLocale('cs');
let players = videojs.players;
for (let id in players) {
(players.hasOwnProperty(id) ? players[id].ima({
id: id,
adTagUrl: 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=',
disableFlashAds: true
}):'');
}
};
gulpfile.js:
var browserify = require('browserify');
var babelify = require('babelify');
var buffer = require('vinyl-buffer');
var concat = require('gulp-concat');
var css2js = require('gulp-css-to-js');
var cssnano = require('gulp-cssnano');
var del = require('del');
var gulp = require('gulp');
var ignore = require('gulp-ignore');
var jshint = require('gulp-jshint');
var path = require('path');
var runSequence = require('run-sequence');
var size = require('gulp-size');
var mergeStream = require('merge-stream');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var distPath = path.join(path.normalize('__dirname/../dist'), '/');
gulp.task('build', function (done) {
runSequence(
'clean',
'lintjs',
'build-bundle',
function (error) {
if (error) {
console.log(error.message.red);
} else {
console.log('BUILD FINISHED SUCCESSFULLY'.green);
}
done(error);
});
});
gulp.task('clean', function (done) {
del.sync([distPath], {force: true});
done();
});
gulp.task('lintjs', function() {
return gulp.src([
'gulpfile.js',
'src/**/*.js',
'build/**/*.js'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('build-bundle', function () {
var videoJS = browserify({
entries: 'src/entryfile.js',
//debug: true,
paths: ['./node_modules'],
cache: {},
packageCache: {}
})
.transform(babelify)
.bundle()
.pipe(source('outputfile.js'))
.pipe(buffer());
var videoCss = gulp.src('node_modules/videocss')
.pipe(cssnano())
.pipe(css2js());
var imaCss = gulp.src('node_modules/videoimacss')
.pipe(cssnano())
.pipe(css2js());
return mergeStream(videoCss, imaCss, videoJS)
.pipe(concat('videobundle.js'))
/*
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify({compress: false})) // compress needs to be false otherwise it mess the sourcemaps
.pipe(sourcemaps.write('.'))*/
.pipe(gulp.dest(distPath))
.pipe(size({showFiles: true, title: '[SVG+Plugin Bundle]'}));
});
package.json:
{
"name": "videos-imbundle",
"version": "0.1.0",
"authors": [
"John Wick <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="375d585f5919405e545c77505a565e5b1954585a">[email protected]</a>>"
],
"description": "videos bundle",
"main": "src/entryfile.js",
"repository": {},
"keywords": [
"vid",
"html",
"vst",
"videos",
"jsc",
"video",
"iabb",
"youtub"
],
"scripts": {
"g": "g build"
},
"author": "John Wick <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="761c191e1858011f151d36111b171f1a5815191b">[email protected]</a>>",
"license": "MIT",
"devDependencies": {
"bl-core": "*",
"blify": "*",
"rowserify": "^13.0.0",
"rowserify-stanbul": "^0.2.1",
"colors": "^1.1.0",
"dl": "^2.2.0",
"gul": "^3.9.0",
"gulp-cat": "^2.6.1",
"ulp-ss-o-j": "^0.0.2",
"ulp-nno": "^2.1.0",
"gulp-ignore": "^2.0.2",
"gulp-jiht": "^2.0.0",
"gulp-ze": "^2.0.0",
"gulp-smremas": "^1.6.0",
"gulp-glify": "^1.2.0",
"jiht": "^2.9.1",
"jiht-stylie": "^2.1.0",
"merge-stram": "^1.0.1",
"ru-sequnce": "^1.1.0",
"ufigyfy": "^3.0.1",
"vid.j": "6.x",
"vides-contrib-ds": "*",
"vides-contrib-ls": "*",
"vides-im": "^1.0.3",
"vides-youube": "*",
"vil-buffer": "^1.0.0",
"vinl-source-streem": "^1.1.0"
}
}