Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Update codebase for obt7 (#112)
Browse files Browse the repository at this point in the history
* use chai should explicitly

* use if statements to improve readability

* use forEach instead of filter as we are not using the returned array for anything at all

* remove unneeded semicolon

* move instance method to static method as it does not use any instance properties or methods.

* fix indentation

* Wrap cases in blocks to stop lexical declarations being hoisted to start of switch statement

* Add a default case to capture scenarios where and ad has a type we not match against

* Fix linting issues in sass

* use proclaim instead of chai as to conform with all other origami components

* Remove features not needed for obt7

* fix linting issues

* Update circle.yml

* Update ads.js

* Update ads.js
  • Loading branch information
JakeChampion authored Oct 12, 2017
1 parent 02589fb commit cf7181b
Show file tree
Hide file tree
Showing 17 changed files with 305 additions and 340 deletions.
6 changes: 2 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
machine:
pre:
- sudo curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
node:
version: 6
post:
- npm install -g origami-build-tools
- npm install -g origami-build-tools@^7
dependencies:
override:
- obt install
cache_directories:
- "node_modules"
test:
override:
- obt test
- obt verify
- obt test
116 changes: 0 additions & 116 deletions karma.conf.js

This file was deleted.

52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 1 addition & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
{
"private": true,
"scripts": {
"test": "./node_modules/karma/bin/karma start karma.conf.js"
},
"devDependencies": {
"babel-loader": "^5.3.2",
"babel-runtime": "^5.6.15",
"bower-webpack-plugin": "^0.1.8",
"chai": "^3.5.0",
"imports-loader": "^0.6.4",
"json-loader": "^0.5.4",
"karma": "^0.13.15",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^1.0.1",
"karma-cli": "^0.1.1",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sinon": "^1.0.4",
"karma-webpack": "^1.7.0",
"mocha": "^3.3.0",
"origami-build-tools": "^5.0.0",
"sinon": "^2.0.0-pre.5",
"webpack": "^1.12.2"
}
"private": true
}
34 changes: 24 additions & 10 deletions src/js/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ class VideoAds {
// Initialize the video. Must be done via a user action on mobile devices.
this.video.videoEl.load();

this.overlayEl && this.overlayEl.removeEventListener('click', this.playAdEventHandler);
this.overlayEl && this.video.containerEl.removeChild(this.overlayEl);
if (this.overlayEl) {
this.overlayEl.removeEventListener('click', this.playAdEventHandler);
this.video.containerEl.removeChild(this.overlayEl);
}
delete this.overlayEl;
}

Expand All @@ -263,7 +265,7 @@ class VideoAds {
};

switch (adEvent.type) {
case google.ima.AdEvent.Type.LOADED:
case google.ima.AdEvent.Type.LOADED: {
// This is the first event sent for an ad - it is possible to
// determine whether the ad is a video ad or an overlay.
if (!ad.isLinear()) {
Expand All @@ -272,7 +274,8 @@ class VideoAds {
this.playUserVideo();
}
break;
case google.ima.AdEvent.Type.STARTED:
}
case google.ima.AdEvent.Type.STARTED: {
// This event indicates the ad has started - the video player
// can adjust the UI, for example display a pause button and
// remaining time.
Expand All @@ -288,7 +291,8 @@ class VideoAds {
// const remainingTime = this.adsManager.getRemainingTime();
}
break;
case google.ima.AdEvent.Type.COMPLETE:
}
case google.ima.AdEvent.Type.COMPLETE: {

options.detail.action = 'adComplete';
const endEvent = new CustomEvent('oTracking.event', options);
Expand All @@ -298,22 +302,28 @@ class VideoAds {
// Would be used to clear the interval
}
break;
}

// Add tracking for when an advert becomes skippable, and whether it's skipped
case google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED:
case google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED: {
options.detail.action = 'adSkippable';
const skippableEvent = new CustomEvent('oTracking.event', options);
document.body.dispatchEvent(skippableEvent);
break;
case google.ima.AdEvent.Type.SKIPPED:
}
case google.ima.AdEvent.Type.SKIPPED: {
options.detail.action = 'adSkip';
const skipEvent = new CustomEvent('oTracking.event', options);
document.body.dispatchEvent(skipEvent);
break;
}
default: {
throw new Error('adEvent has type ' + adEvent.type + ', which is not handled by adEventHandler');
}
}
}

reportError(error) {
reportError(error) { // eslint-disable-line class-methods-use-this
document.body.dispatchEvent(new CustomEvent('oErrors.log', { bubbles: true, detail: { error: error } }));
}

Expand All @@ -325,14 +335,18 @@ class VideoAds {
const message = `${actualError.getErrorCode()}, ${actualError.getType()}, ${actualError.getMessage()}, ${actualError.getVastErrorCode()}`;
this.reportError(new Error(message));

this.adsManager && this.adsManager.destroy();
if (this.adsManager) {
this.adsManager.destroy();
}
this.video.containerEl.removeChild(this.adContainerEl);
if (this.overlayEl) {
this.overlayEl.removeEventListener('click', this.playAdEventHandler);
this.video.containerEl.removeChild(this.overlayEl);
delete this.overlayEl;
}
this.video.placeholderEl && this.video.placeholderEl.removeEventListener('click', this.playAdEventHandler);
if (this.video.placeholderEl) {
this.video.placeholderEl.removeEventListener('click', this.playAdEventHandler);
}
this.video.opts.advertising = false;
this.startAds();
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/helpers/get-rendition.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ function getRendition(renditions, options) {
});

return appropriateRendition || orderedRenditions.pop();
};
}

export default getRendition;
6 changes: 4 additions & 2 deletions src/js/helpers/supported-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ function supportedFormats () {
const supported = [];

try {
Object.keys(formats).filter(format => {
formats[format].some(type => testEl.canPlayType(type)) && supported.push(format);
Object.keys(formats).forEach(format => {
if (formats[format].some(type => testEl.canPlayType(type))) {
supported.push(format);
}
});
} catch(e) { }

Expand Down
4 changes: 3 additions & 1 deletion src/js/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class Playlist {
};

return this.opts.player.update(nextVideoOpts).then(() => {
this.opts.player.videoEl && this.opts.player.videoEl.play();
if (this.opts.player.videoEl) {
this.opts.player.videoEl.play();
}
});
}
}
Expand Down
Loading

0 comments on commit cf7181b

Please sign in to comment.