New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

videojs-vast-vpaid

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

videojs-vast-vpaid - npm Package Compare versions

Comparing version 0.0.41 to 0.0.60

.publish/scripts/ie8fix.js

10

bower_components/VPAIDHTML5Client/.bower.json
{
"name": "VPAIDHTML5Client",
"version": "0.1.7",
"version": "0.1.9",
"homepage": "https://github.com/MailOnline/VPAIDHTML5Client",

@@ -26,11 +26,11 @@ "authors": [

],
"_release": "0.1.7",
"_release": "0.1.9",
"_resolution": {
"type": "version",
"tag": "0.1.7",
"commit": "e272158fba3f5cc35c04db8af8c5c92bac85b8f8"
"tag": "0.1.9",
"commit": "8ba64db9f937a7a28c646f345f652c8feaf6997e"
},
"_source": "git://github.com/MailOnline/VPAIDHTML5Client.git",
"_target": "0.1.7",
"_target": "0.1.9",
"_originalSource": "VPAIDHTML5Client"
}

@@ -133,3 +133,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

*/
IVPAIDAdUnit.prototype.resizeAd = function(callback) {};
IVPAIDAdUnit.prototype.resizeAd = function(width, height, viewMode, callback) {};

@@ -742,5 +742,8 @@ /**

Subscriber.prototype.trigger = function(eventName, data) {
this.get(eventName).forEach(function (subscriber) {
var that = this;
that.get(eventName).forEach(function (subscriber) {
setTimeout(function () {
subscriber.handler.call(subscriber.context, data);
if (that.get(eventName)) {
subscriber.handler.call(subscriber.context, data);
}
}, 0);

@@ -747,0 +750,0 @@ });

{
"name": "VPAIDHTML5Client",
"version": "0.1.7",
"version": "0.1.9",
"homepage": "https://github.com/MailOnline/VPAIDHTML5Client",

@@ -5,0 +5,0 @@ "authors": [

@@ -132,3 +132,3 @@ 'use strict';

*/
IVPAIDAdUnit.prototype.resizeAd = function(callback) {};
IVPAIDAdUnit.prototype.resizeAd = function(width, height, viewMode, callback) {};

@@ -135,0 +135,0 @@ /**

@@ -22,5 +22,8 @@ 'use strict';

Subscriber.prototype.trigger = function(eventName, data) {
this.get(eventName).forEach(function (subscriber) {
var that = this;
that.get(eventName).forEach(function (subscriber) {
setTimeout(function () {
subscriber.handler.call(subscriber.context, data);
if (that.get(eventName)) {
subscriber.handler.call(subscriber.context, data);
}
}, 0);

@@ -27,0 +30,0 @@ });

{
"name": "vpaid-html5-client",
"version": "0.1.7",
"version": "0.1.9",
"description": "VPAID HTML5",

@@ -5,0 +5,0 @@ "main": [

{
"name": "videojs-vast-vpaid",
"version": "0.0.41",
"version": "0.0.60",
"authors": [

@@ -37,4 +37,4 @@ "Carlos Serrano <carlos.pastor@mailonline.co.uk>"

"dependencies": {
"VPAIDFLASHClient": "0.1.5",
"VPAIDHTML5Client": "0.1.7"
"VPAIDFLASHClient": "0.1.7",
"VPAIDHTML5Client": "0.1.9"
},

@@ -41,0 +41,0 @@ "devDependencies": {

@@ -47,2 +47,3 @@ var path = require('path');

'node_modules/es5-shim/es5-shim.js', //Required for the player to work on old browsers
'lib/ie8fix.js', //Required for make the ad's work in ie8
'bower_components/swfobject/swfobject/src/swfobject.js'

@@ -49,0 +50,0 @@ ],

@@ -8,8 +8,8 @@ var dom = require('./miniDom');

var intercept_urls = Object.keys(custom_xhr);
var i,len, match, intercept_url;
var i, len, match, intercept_url;
for(i = 0, len = intercept_urls.length; i < len; i++) {
for (i = 0, len = intercept_urls.length; i < len; i++) {
intercept_url = intercept_urls[i];
match = new RegExp(intercept_url+"$","gi");
if(request.url.match(match)){
match = new RegExp(intercept_url + "$", "gi");
if (request.url.match(match)) {
return callback({

@@ -26,3 +26,3 @@ status: 200,

dom.onReady(function () {
dom.onReady(function() {
var vastForm = document.querySelector('form#vast-form');

@@ -35,3 +35,3 @@ var vpaidForm = document.querySelector('form#vpaid-form');

/*** Local functions ***/
function initForm(formEl){
function initForm(formEl) {
var tagTypeEl = formEl.querySelector('input.tag-type-radio');

@@ -41,2 +41,4 @@ var xmlTypeEl = formEl.querySelector('input.xml-type-radio');

var updateBtn = formEl.querySelector('.button.button-primary');
var pauseBtn = formEl.querySelector('.pause');
var resumeBtn = formEl.querySelector('.resume');
var tagEl = formEl.querySelector('input.tag-el');

@@ -46,2 +48,3 @@ var xmlEl = formEl.querySelector('select.xml-el');

var videoContainer = formEl.querySelector('div.vjs-video-container');
var player;

@@ -57,2 +60,15 @@ updateVisibility();

if (pauseBtn && resumeBtn) {
dom.addEventListener(pauseBtn, 'click', function() {
pauseAd();
messages.success("ad paused");
});
dom.addEventListener(resumeBtn, 'click', function() {
resumeAd();
messages.success("ad resumed");
});
}
updateDemo();

@@ -68,4 +84,28 @@

function updateDemo(){
createVideoEl(videoContainer, function(videoEl){
function pauseAd() {
if (player) {
player.vast.adUnit.pauseAd();
showResumeBtn();
}
}
function resumeAd() {
if (player) {
player.vast.adUnit.resumeAd();
showPauseBtn();
}
}
function showResumeBtn(){
pauseBtn.style.display = 'none';
resumeBtn.style.display = 'inline-block';
}
function showPauseBtn(){
pauseBtn.style.display = 'inline-block';
resumeBtn.style.display = 'none';
}
function updateDemo() {
createVideoEl(videoContainer, function(videoEl) {
var adsTag;

@@ -75,13 +115,13 @@ var mode = activeMode();

adsTag = tagEl.value;
} else if(mode ==='XML'){
} else if (mode === 'XML') {
adsTag = xmlEl.value;
} else {
adsTag = 'CUSTOM_AD_TAG'+ new Date().getTime();
adsTag = 'CUSTOM_AD_TAG' + new Date().getTime();
custom_xhr[adsTag] = customEl.value;
}
videojs(videoEl, {
player = videojs(videoEl, {
"plugins": {
"ads-setup":{
"adCancelTimeout": 10000,// Wait for ten seconds before canceling the ad.
"adCancelTimeout":20000,// Wait for ten seconds before canceling the ad.
"adsEnabled": true,

@@ -92,11 +132,33 @@ "adsTag": adsTag

});
//We hide the pause and resume btns every time we update
if (pauseBtn) {
pauseBtn.style.display = 'none';
resumeBtn.style.display = 'none';
}
if(player) {
player.on('vast.adStart', function() {
showPauseBtn();
player.on('play', showPauseBtn);
player.on('pause', showResumeBtn);
player.one('vast.adEnd', function() {
pauseBtn.style.display = 'none';
resumeBtn.style.display = 'none';
player.off('play', showPauseBtn);
player.off('pause', showResumeBtn);
});
});
}
});
}
function activeMode(){
if(tagTypeEl.checked){
function activeMode() {
if (tagTypeEl.checked) {
return 'TAG';
}
if(xmlTypeEl.checked){
if (xmlTypeEl.checked) {
return 'XML';

@@ -108,15 +170,15 @@ }

function createVideoEl(container, cb){
function createVideoEl(container, cb) {
var videoTag = '<video class="video-js vjs-default-skin" controls preload="auto" poster="http://video-js.zencoder.com/oceans-clip.png" >' +
'<source src="http://video-js.zencoder.com/oceans-clip.mp4" type="video/mp4"/>' +
'<source src="http://video-js.zencoder.com/oceans-clip.webm" type="video/webm"/>' +
'<source src="http://video-js.zencoder.com/oceans-clip.ogv" type="video/ogg"/>' +
'<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that ' +
'<a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>' +
'</p>' +
'</video>';
'<source src="http://video-js.zencoder.com/oceans-clip.mp4" type="video/mp4"/>' +
'<source src="http://video-js.zencoder.com/oceans-clip.webm" type="video/webm"/>' +
'<source src="http://video-js.zencoder.com/oceans-clip.ogv" type="video/ogg"/>' +
'<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that ' +
'<a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>' +
'</p>' +
'</video>';
container.innerHTML = videoTag;
//We do this asynchronously to give time for the dom to be updated
setTimeout(function () {
setTimeout(function() {
var videoEl = container.querySelector('.video-js');

@@ -123,0 +185,0 @@ cb(videoEl);

{
"name": "videojs-vast-vpaid",
"version": "0.0.41",
"version": "0.0.60",
"authors": [

@@ -5,0 +5,0 @@ "Carlos Serrano <carlos.pastor@mailonline.co.uk>"

@@ -17,3 +17,3 @@ # videojs-vast-plugin

To integrate the plugin with videoJs you need to:
1.- Add [all files from bin](https://github.com/MailOnline/videojs-vast-vpaid/tree/master/bin) to some path in your server

@@ -33,8 +33,12 @@

```
if you need to support older browsers add this to your page before the plugin script
if you need to support older browsers that don't support ES5 add this to your page before the plugin script
```
<script src="/path/to/es5-shim.js"></script>
```
if you need to support ie8 add this after the es5-shim.js script
```
<script src="/path/to/ie8fix.js"></script>
```
4.- Create you own ads plugin to pass an add media tag to the plugin

@@ -157,2 +161,14 @@

### adUnit
>If there is an ad playing (after the vast.adStart event) it will contain an obj like the one below:
```
player.vast.adUnit= {
type: {string} <== The possible types are 'VAST' or 'VPAID'
pauseAd: {function} <== Pauses the ad unit
resumeAd: {function} <== Resumes the ad unit
getSrc: {function} <== Returns the MediaFile instance used to play the ad
}
```
>Otherwise it will be null or undefined
## player.vast

@@ -179,3 +195,3 @@ The returned object described above it is also published as a player property so that you can use it anywhere as long as you have access to the player instance.

The plugin does trigger some events that can be used for tracking or debugging.
### 'vast.firstPlay' event

@@ -186,9 +202,9 @@ Fired when the user first plays a video or if the playAdAlways option is set to true every time the user replays the same video

Fired when the ad starts playing
### 'vast.adEnd' event
Fired when the ad end playing
### 'vast.adError' event
Fired whenever there is an error with the ad. The error itself gets added to the event object in the property 'error'.
### 'vast.adsCancel' event

@@ -199,8 +215,11 @@ Fired whenever the ads are canceled due to an error or because the plugin is not enabled.

Fired whenever the video content starts playing
### 'vast.contentEnded' event
Fired when the video content ends.
### 'vast.reset' event
Trigger the 'vast.reset' event whenever you want to reset the plugin. Beware that if an ad is playing it will be canceled.
## Running the plugin
If you want to run the plugin you need to clone the repo into your local environment
If you want to run the plugin you need to clone the repo into your local environment
```

@@ -210,3 +229,3 @@ git clone git@github.com:MailOnline/videojs-vast-vpaid.git

and install the dependencies
```

@@ -217,3 +236,3 @@ $ cd videojs-vast-vpaid

```
after installing the dependencies you are ready to go. If you want to see the available build tasks, run

@@ -227,6 +246,6 @@ ```

\ \ / /|__| __| _/ ____ ____ |__| ______ \ \ / /_____ _______/ |_ \ \ / /______ _____ |__| __| _/
\ Y / | | / __ | _/ __ \ / _ \ | | / ___/ \ Y / \__ \ / ___/\ __\ \ Y / \____ \ \__ \ | | / __ |
\ / | |/ /_/ | \ ___/ ( <_> ) | | \___ \ \ / / __ \_ \___ \ | | \ / | |_> > / __ \_| |/ /_/ |
\___/ |__|\____ | \___ > \____/ /\__| |/____ > \___/ (____ //____ > |__| \___/ | __/ (____ /|__|\____ |
\/ \/ \______| \/ \/ \/ |__| \/ \/
\ Y / | | / __ | _/ __ \ / _ \ | | / ___/ \ Y / \__ \ / ___/\ __\ \ Y / \____ \ \__ \ | | / __ |
\ / | |/ /_/ | \ ___/ ( <_> ) | | \___ \ \ / / __ \_ \___ \ | | \ / | |_> > / __ \_| |/ /_/ |
\___/ |__|\____ | \___ > \____/ /\__| |/____ > \___/ (____ //____ > |__| \___/ | __/ (____ /|__|\____ |
\/ \/ \______| \/ \/ \/ |__| \/ \/

@@ -255,7 +274,7 @@ ###### Below, you have the list of all the available build tasks ########

╚═════════════════════════╧════════════════════════════════════════════════════════════════════════════════╝
[12:27:22] Finished 'default' after 8.12 ms
```
Which will show you a table with the main build tasks. If you want start the demo locally just run:
```

@@ -266,3 +285,3 @@ $ gulp start-dev

http://localhost:8085
## License

@@ -269,0 +288,0 @@ videojs-vast-plugin is licensed under the MIT License, Version 2.0. [View the license file](LICENSE)

@@ -41,2 +41,24 @@ /**

});
this._adUnit = {
_src: null,
type: 'VAST',
pauseAd: function() {
that.player.pause(true);
},
resumeAd: function() {
that.player.play(true);
},
isPaused: function() {
return that.player.paused(true);
},
getSrc: function() {
return this._src;
}
};
return this._adUnit;
};

@@ -57,2 +79,5 @@

if (source) {
if(this._adUnit) {
this._adUnit._src = source;
}
return callback(null, source, response);

@@ -82,7 +107,3 @@ }

player.one('vast.adEnd', unbindEvents);
player.one('vast.adsCancel', unbindEvents);
//NOTE: Pending tracking events skip, close, closeLinear, expand, collapse and creativeView. See VAST implementation
playerUtils.only(player, ['vast.adEnd', 'vast.adsCancel', 'error'], unbindEvents);
return callback(null, adMediaFile, response);

@@ -152,4 +173,3 @@

player.one('ended', removeSkipButton);
player.one('error', removeSkipButton);
playerUtils.only(player, ['ended', 'error'], removeSkipButton);

@@ -203,4 +223,3 @@ function removeSkipButton() {

player.on('timeupdate', updateBlocker);
player.one('ended', removeBlocker);
player.one('error', removeBlocker);
playerUtils.only(player, ['ended', 'error'], removeBlocker);

@@ -264,6 +283,13 @@ return callback(null, mediaFile, tracker, response);

player.one('durationchange', playAd);
player.one('ended', finishPlayingAd);
player.one('error', handlePlayerError);
player.on('durationchange', playAd);
playerUtils.only(player, ['ended', 'error'], function (evt) {
if(evt.type === 'ended'){
callback(null, response);
} else {
callback(new VASTError("on VASTIntegrator, Player is unable to play the Ad", 400), response);
}
player.off('durationchange', playAd);
});
/**** local functions ******/

@@ -275,13 +301,3 @@ function playAd() {

});
}
function finishPlayingAd() {
player.off('error', handlePlayerError);
callback(null, response);
}
function handlePlayerError() {
player.off('durationchange', playAd);
player.off('ended', finishPlayingAd);
callback(new VASTError("on VASTIntegrator, Player is unable to play the Ad", 400), response);
}

@@ -288,0 +304,0 @@ };

@@ -60,2 +60,4 @@ vjs.plugin('vastClient', function VASTPlugin(options) {

player.on('vast.reset', cancelAds);
player.vast = {

@@ -81,2 +83,9 @@ isEnabled: function () {

playerUtils.removeNativePoster(player);
player.on('error', cancelAds);
playerUtils.only(player, ['vast.adsCancel', 'vast.adEnd'], function() {
player.off('error', cancelAds);
restoreVideoContent();
});
async.waterfall([

@@ -94,10 +103,19 @@ checkAdsEnabled,

triggerContentEvents();
});
/*** Local functions ***/
function restoreVideoContent(){
if(snapshot) {
snapshot.playing = false;
playerUtils.restorePlayerSnapshot(player, snapshot);
snapshot = null;
}
});
/*** Local functions ***/
if(player.vast && player.vast.adUnit) {
player.vast.adUnit = null; //We remove the adUnit
}
player.play();
}
function checkAdsEnabled(next) {

@@ -133,3 +151,3 @@ if(settings.adsEnabled) {

function canPlayPrerollAd() {
return !playerUtils.isIPhone() || player.currentTime() <= settings.iosPrerollCancelTimeout;
return !isIPhone() || player.currentTime() <= settings.iosPrerollCancelTimeout;
}

@@ -145,5 +163,3 @@

player.on('vast.adStart', clearAdCancelTimeout);
player.on('vast.adError', clearAdCancelTimeout);
player.on('vast.adsCancel', clearAdCancelTimeout);
playerUtils.only(player, ['vast.adStart', 'vast.adError', 'vast.adsCancel'], clearAdCancelTimeout);

@@ -155,5 +171,2 @@ /*** local functions ***/

adCancelTimeoutId = null;
player.off('vast.adStart', clearAdCancelTimeout);
player.off('vast.adError', clearAdCancelTimeout);
player.off('vast.adsCancel', clearAdCancelTimeout);
}

@@ -165,6 +178,3 @@ }

dom.addClass(player.el(), 'vjs-vast-ad-loading');
player.on('vast.adStart', removeSpinnerIcon);
player.on('vast.adError', removeSpinnerIcon);
player.on('vast.adsCancel', removeSpinnerIcon);
playerUtils.only(player, ['vast.adStart', 'vast.adError', 'vast.adsCancel'], removeSpinnerIcon);
}

@@ -177,6 +187,2 @@

dom.removeClass(player.el(), 'vjs-vast-ad-loading');
player.off('vast.adStart', removeSpinnerIcon);
player.off('vast.adError', removeSpinnerIcon);
player.off('vast.adsCancel', removeSpinnerIcon);
}, 100);

@@ -213,8 +219,8 @@ }

adIntegrator.playAd(vastResponse, callback);
player.vast.adUnit = adIntegrator.playAd(vastResponse, callback);
player.one('vast.adStart', adAdsLabel);
player.one('vast.adEnd', removeAdsLabel);
player.one('vast.adsCancel', removeAdsLabel);
playerUtils.only(player, ['vast.adEnd', 'vast.adsCancel', 'error'], removeAdsLabel);
if (isIDevice()) {

@@ -226,3 +232,3 @@ preventManualProgress();

function adAdsLabel() {
if (adFinished) {
if (adFinished || player.controlBar.getChild('AdsLabel')) {
return;

@@ -234,5 +240,2 @@ }

function removeAdsLabel() {
if (adFinished) {
return;
}
player.controlBar.removeChild('AdsLabel');

@@ -249,4 +252,3 @@ adFinished = true;

player.on('timeupdate', adTimeupdateHandler);
player.on('vast.adEnd', stopPreventManualProgress);
player.on('vast.adsCancel', stopPreventManualProgress);
playerUtils.only(player, ['vast.adEnd', 'vast.adsCancel'], stopPreventManualProgress);

@@ -271,4 +273,2 @@ /*** Local functions ***/

player.off('timeupdate', adTimeupdateHandler);
player.off('vast.adEnd', stopPreventManualProgress);
player.off('vast.adsCancel', stopPreventManualProgress);
}

@@ -275,0 +275,0 @@ }

@@ -6,2 +6,3 @@ function VPAIDFlashTech(mediaFile, settings) {

sanityCheck(mediaFile);
this.name = 'vpaid-flash';
this.mediaFile = mediaFile;

@@ -8,0 +9,0 @@ this.containerEl = null;

@@ -9,2 +9,3 @@ function VPAIDHTML5Tech(mediaFile) {

this.name = 'vpaid-html5';
this.containerEl = null;

@@ -24,3 +25,3 @@ this.videoEl = null;

VPAIDHTML5Tech.supports = function (type) {
return type === 'application/javascript';
return !isOldIE() && type === 'application/javascript';
};

@@ -27,0 +28,0 @@

@@ -50,9 +50,13 @@ function VPAIDIntegrator(player, settings) {

player.one('error', function () {
tech = this._findSupportedTech(vastResponse, this.settings);
dom.addClass(player.el(), 'vjs-vpaid-ad');
player.on('error', triggerVpaidAdEnd);
player.on('vast.adsCancel', triggerVpaidAdEnd);
player.one('vpaid.adEnd', function(){
player.off('error', triggerVpaidAdEnd);
player.off('vast.adsCancel', triggerVpaidAdEnd);
removeAdUnit();
});
tech = this._findSupportedTech(vastResponse, this.settings);
dom.addClass(player.el(), 'vjs-vpaid-ad');
if (tech) {

@@ -68,19 +72,40 @@ async.waterfall([

], function (error, adUnit, vastResponse) {
removeAdUnit(error);
if (error) {
that._trackError(vastResponse);
}
player.trigger('vpaid.adEnd');
callback(error, vastResponse);
});
} else {
callback(new VASTError('on VPAIDIntegrator.playAd, could not find a supported mediaFile'));
this._adUnit = {
_paused: true,
type: 'VPAID',
pauseAd: function() {
player.trigger('vpaid.pauseAd');
},
resumeAd: function() {
player.trigger('vpaid.resumeAd');
},
isPaused: function() {
return this._paused;
},
getSrc: function() {
return tech.mediaFile;
}
};
return this._adUnit;
}
callback(new VASTError('on VPAIDIntegrator.playAd, could not find a supported mediaFile'));
return null;
/*** Local functions ***/
function removeAdUnit(error) {
if (error) {
that._trackError(vastResponse);
player.trigger('vast.adError');
}
function triggerVpaidAdEnd(){
player.trigger('vpaid.adEnd');
}
function removeAdUnit() {
tech.unloadAdUnit();
dom.removeClass(player.el(), 'vjs-vpaid-ad');
player.trigger('VPAID.adEnd');
}

@@ -108,3 +133,2 @@ };

/*** Local functions ***/
function findSupportedTech(mediafile) {

@@ -125,5 +149,6 @@ var type = mediafile.type;

VPAIDIntegrator.prototype._loadAdUnit = function (tech, vastResponse, next) {
var vjsTechEl = this.player.el().querySelector('.vjs-tech');
var player = this.player;
var vjsTechEl = player.el().querySelector('.vjs-tech');
tech.loadAdUnit(this.containerEl, vjsTechEl, function (error, adUnit) {
if(error) {
if (error) {
return next(error, adUnit, vastResponse);

@@ -133,3 +158,9 @@ }

try {
next(error, new VPAIDAdUnitWrapper(adUnit, {src: tech.mediaFile.src}), vastResponse);
var WrappedAdUnit = new VPAIDAdUnitWrapper(adUnit, {src: tech.mediaFile.src});
var techClass = 'vjs-' + tech.name + '-ad';
dom.addClass(player.el(), techClass);
player.one('vpaid.adEnd', function() {
dom.removeClass(player.el(),techClass);
});
next(null, WrappedAdUnit, vastResponse);
} catch (e) {

@@ -180,3 +211,4 @@ next(e, adUnit, vastResponse);

VPAIDIntegrator.prototype._initAd = function (adUnit, vastResponse, next) {
var dimension = dom.getDimension(this.player.el());
var tech = this.player.el().querySelector('.vjs-tech');
var dimension = dom.getDimension(tech);
adUnit.initAd(dimension.width, dimension.height, this.VIEW_MODE.NORMAL, -1, vastResponse.adParameters || '', function (error) {

@@ -191,2 +223,3 @@ next(error, adUnit, vastResponse);

var player = this.player;
var that = this;

@@ -201,6 +234,36 @@ adUnit.on('AdSkipped', function () {

adUnit.on('AdStarted', function () {
notifyPlayToPlayer();
});
adUnit.on('AdVideoStart', function () {
tracker.trackStart();
notifyPlayToPlayer();
});
adUnit.on('AdPlaying', function () {
tracker.trackResume();
notifyPlayToPlayer();
});
adUnit.on('AdPaused', function () {
tracker.trackPause();
notifyPauseToPlayer();
});
function notifyPlayToPlayer(){
if(that._adUnit && that._adUnit.isPaused()){
that._adUnit._paused = false;
}
player.trigger('play');
}
function notifyPauseToPlayer() {
if(that._adUnit){
that._adUnit._paused = true;
}
player.trigger('pause');
}
adUnit.on('AdVideoFirstQuartile', function () {

@@ -223,3 +286,3 @@ tracker.trackFirstQuartile();

adUnit.on('AdClickThru', function (data) {
var url= data.url;
var url = data.url;
var playerHandles = data.playerHandles;

@@ -253,6 +316,2 @@ var clickThruUrl = isNotEmptyString(url) ? url : generateClickThroughURL(vastResponse.clickThrough);

adUnit.on('AdPaused', function () {
tracker.trackPause();
});
adUnit.on('AdUserMinimize', function () {

@@ -267,7 +326,2 @@ tracker.trackCollapse();

adUnit.on('AdPlaying', function () {
//NOTE: we track errors code 901, as noted in VAST 3.0
tracker.trackResume();
});
adUnit.on('AdVolumeChange', function () {

@@ -289,5 +343,6 @@ var lastVolume = player.volume();

var updateViewSize = resizeAd.bind(this, player, adUnit, this.VIEW_MODE);
var updateViewSizeThrottled = throttle(updateViewSize, 100);
var autoResize = this.settings.autoResize;
if (this.settings.autoResize) {
var updateViewSizeThrottled = throttle(updateViewSize, 100);
if (autoResize) {
dom.addEventListener(window, 'resize', updateViewSizeThrottled);

@@ -298,4 +353,26 @@ dom.addEventListener(window, 'orientationchange', updateViewSizeThrottled);

player.on('vast.resize', updateViewSize);
player.on('vpaid.pauseAd', pauseAdUnit);
player.on('vpaid.resumeAd', resumeAdUnit);
player.one('vpaid.adEnd', function () {
player.off('vast.resize', updateViewSize);
player.off('vpaid.pauseAd', pauseAdUnit);
player.off('vpaid.resumeAd', resumeAdUnit);
if (autoResize) {
dom.removeEventListener(window, 'resize', updateViewSizeThrottled);
dom.removeEventListener(window, 'orientationchange', updateViewSizeThrottled);
}
});
next(null, adUnit, vastResponse);
/*** Local Functions ***/
function pauseAdUnit() {
adUnit.pauseAd(noop);
}
function resumeAdUnit() {
adUnit.resumeAd(noop);
}
};

@@ -309,4 +386,3 @@

player.one('vast.adEnd', removeSkipButton);
player.one('vast.adError', removeSkipButton);
playerUtils.only(player, ['vast.adEnd', 'vast.adError'], removeSkipButton);

@@ -368,3 +444,3 @@ next(null, adUnit, vastResponse);

player.on('VPAID.adEnd', function () {
player.one('vpaid.adEnd', function () {
player.off('volumechange', updateAdUnitVolume);

@@ -396,3 +472,3 @@ });

player.on('VPAID.adEnd', function () {
player.one('vpaid.adEnd', function () {
player.off('fullscreenchange', updateViewSize);

@@ -416,8 +492,14 @@ });

adUnit.on('AdStopped', function () {
next(null, adUnit, vastResponse);
finishPlayingAd(null);
});
adUnit.on('AdError', function () {
next(new VASTError('on VPAIDIntegrator, error while waiting for the adUnit to finish playing'), adUnit, vastResponse);
adUnit.on('AdError', function (error) {
var errMsg = error? error.message : 'on VPAIDIntegrator, error while waiting for the adUnit to finish playing';
finishPlayingAd(new VASTError(errMsg));
});
/*** local functions ***/
function finishPlayingAd(error) {
next(error, adUnit, vastResponse);
}
};

@@ -430,3 +512,4 @@

function resizeAd(player, adUnit, VIEW_MODE) {
var dimension = dom.getDimension(player.el());
var tech = player.el().querySelector('.vjs-tech');
var dimension = dom.getDimension(tech);
var MODE = player.isFullscreen() ? VIEW_MODE.FULLSCREEN : VIEW_MODE.NORMAL;

@@ -433,0 +516,0 @@ adUnit.resizeAd(dimension.width, dimension.height, MODE, logError);

@@ -194,4 +194,2 @@ "use strict";

//Note: there is no getBoundingClientRect on iPad so we need a fallback

@@ -201,3 +199,4 @@ dom.getDimension = function getDimension(element) {

if(element.getBoundingClientRect) {
//On IE9 and below getBoundingClientRect does not work consistently
if(!isOldIE() && element.getBoundingClientRect) {
rect = element.getBoundingClientRect();

@@ -204,0 +203,0 @@ return {

@@ -22,3 +22,3 @@ "use strict";

options = options || {};
timeout = isNumber(options.timeout)? options.timeout : 0;
timeout = isNumber(options.timeout) ? options.timeout : 0;

@@ -38,3 +38,21 @@ xhr.open(method, urlParts(url).href, true);

if(isDefined(timeoutId)){
/**
* The only way to do a secure request on IE8 and IE9 is with the XDomainRequest object. Unfortunately, microsoft is
* so nice that decided that the status property and the 'getAllResponseHeaders' method where not needed so we have to
* fake them. If the request gets done with an XDomainRequest instance, we will assume that there are no headers and
* the status will always be 200. If you don't like it, DO NOT USE ANCIENT BROWSERS!!!
*
* For mor info go to: https://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx
*/
if (!xhr.getAllResponseHeaders) {
xhr.getAllResponseHeaders = function () {
return null;
};
}
if (!xhr.status) {
xhr.status = 200;
}
if (isDefined(timeoutId)) {
clearTimeout(timeoutId);

@@ -65,3 +83,3 @@ timeoutId = undefined;

if(timeout > 0){
if (timeout > 0) {
timeoutId = setTimeout(function () {

@@ -68,0 +86,0 @@ xhr && xhr.abort();

@@ -172,12 +172,3 @@ var playerUtils = {};

//TODO: SHOULDN'T WE USE isIDevice utility function??
/**
* Returns true if the player is in an iphone
*/
playerUtils.isIPhone = (function () {
var iPhone = /(iPhone|iPod)/.test(navigator.userAgent);
return echoFn(iPhone);
})();
/**
* This function prepares the player to display ads.

@@ -191,24 +182,8 @@ * Adding convenience events like the 'vast.firsPlay' that gets fired when the video is first played

var blackPoster = player.addChild('blackPoster');
var firstPlay = true;
var _firstPlay = true;
var volumeSnapshot;
/*
What I am doing below is ugly and horrible and I should think twice before calling myself a good developer. With that said,
it is the best solution I could find to mute the video until the 'play' event happens and the plugin can decide whether
to play the ad or not.
If you have a better solution please do tell me.
*/
var origPlay = player.play;
player.play = function () {
if (isFirstPlay()) {
if (!playerUtils.isIPhone()) {
volumeSnapshot = saveVolumeSnapshot();
player.muted(true);
}
}
return origPlay.apply(this, arguments);
};
monkeyPatchPlayerApi();
player.on('play', tryToTriggerFirstPlay);

@@ -226,7 +201,90 @@ player.on('loadStart', resetFirstPlay);//Every time we change the sources we reset the first play.

/*** Local Functions ***/
/**
What this function does is ugly and horrible and I should think twice before calling myself a good developer. With that said,
it is the best solution I could find to mute the video until the 'play' event happens (on mobile devices) and the plugin can decide whether
to play the ad or not.
We also need this monkeypatch to be able to pause and resume an ad using the player's API
If you have a better solution please do tell me.
*/
function monkeyPatchPlayerApi() {
/**
* Monkey patch needed to handle firstPlay and resume of playing ad.
*
* @param callOrigPlay necessary flag to prevent infinite loop when you are restoring a VAST ad.
* @returns {player}
*/
var origPlay = player.play;
player.play = function (callOrigPlay) {
if (isFirstPlay()) {
firstPlay.call(this);
} else {
resume.call(this, callOrigPlay);
}
return this;
/*** local functions ***/
function firstPlay() {
if (!isIPhone()) {
volumeSnapshot = saveVolumeSnapshot();
player.muted(true);
}
origPlay.apply(this, arguments);
}
function resume(callOrigPlay) {
if (isAdPlaying() && !callOrigPlay) {
player.vast.adUnit.resumeAd();
} else {
origPlay.apply(this, arguments);
}
}
};
/**
* Needed monkey patch to handle pause of playing ad.
*
* @param callOrigPlay necessary flag to prevent infinite loop when you are pausing a VAST ad.
* @returns {player}
*/
var origPause = player.pause;
player.pause = function (callOrigPause) {
if (isAdPlaying() && !callOrigPause) {
player.vast.adUnit.pauseAd();
} else {
origPause.apply(this, arguments);
}
return this;
};
/**
* Needed monkey patch to handle paused state of the player when ads are playing.
*
* @param callOrigPlay necessary flag to prevent infinite loop when you are pausing a VAST ad.
* @returns {player}
*/
var origPaused = player.paused;
player.paused = function (callOrigPaused) {
if (isAdPlaying() && !callOrigPaused) {
return player.vast.adUnit.isPaused();
}
return origPaused.apply(this, arguments);
};
}
function isAdPlaying() {
return player.vast && player.vast.adUnit;
}
function tryToTriggerFirstPlay() {
if (isFirstPlay()) {
firstPlay = false;
_firstPlay = false;
player.trigger('vast.firstPlay');
}

@@ -236,3 +294,3 @@ }

function resetFirstPlay() {
firstPlay = true;
_firstPlay = true;
blackPoster.show();

@@ -242,3 +300,3 @@ }

function isFirstPlay() {
return firstPlay;
return _firstPlay;
}

@@ -254,3 +312,3 @@

function restorePlayerToFirstPlay() {
if (!playerUtils.isIPhone()) {
if (volumeSnapshot) {
player.currentTime(0);

@@ -257,0 +315,0 @@ restoreVolumeSnapshot(volumeSnapshot);

@@ -238,5 +238,51 @@ /*jshint unused:false */

/**
* Checks if the Browser is IE9 and below
* @returns {boolean}
*/
function isOldIE() {
var version = getInternetExplorerVersion(navigator);
if (version === -1) {
return false;
}
return version < 10;
}
/**
* Returns the version of Internet Explorer or a -1 (indicating the use of another browser).
* Source: https://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx
* @returns {number} the version of Internet Explorer or a -1 (indicating the use of another browser).
*/
function getInternetExplorerVersion(navigator) {
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
var res = re.exec(ua);
if (res !== null) {
rv = parseFloat(res[1]);
}
}
return rv;
}
/*** Mobile Utility functions ***/
var _UA = navigator.userAgent;
function isIDevice() {
return /iP(hone|ad)/.test(_UA);
}
}
function isMobile() {
return /iP(hone|ad|od)|Android|Windows Phone/.test(_UA);
}
function isIPhone() {
return /iP(hone|od)/.test(_UA);
}
function isAndroid() {
return /Android/.test(_UA);
}

@@ -5,3 +5,3 @@ var xml = {};

//IE 8
if(!DOMParser){
if(typeof window.DOMParser === 'undefined'){
var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');

@@ -87,3 +87,5 @@ xmlDocument.async = false;

if (oXMLParent.hasAttributes()) {
//IE8 Stupid fix
var hasAttr = typeof oXMLParent.hasAttributes === 'undefined'? oXMLParent.attributes.length > 0: oXMLParent.hasAttributes();
if (hasAttr) {
var oAttrib;

@@ -90,0 +92,0 @@ for (var nAttrib = 0; nAttrib < oXMLParent.attributes.length; nAttrib++) {

@@ -109,2 +109,41 @@ describe("VASTIntegrator", function () {

});
describe("return obj", function(){
it("must contain the type 'VAST", function(){
var adUnit = vastIntegrator.playAd(new VASTResponse(), noop);
assert.equal(adUnit.type, 'VAST');
});
it("must be able to pause the adUnit", function(){
var adUnit = vastIntegrator.playAd(new VASTResponse(), noop);
sinon.spy(player, 'pause');
adUnit.pauseAd();
sinon.assert.calledOnce(player.pause);
});
it("must be able to resume the adUnit", function(){
var adUnit = vastIntegrator.playAd(new VASTResponse(), noop);
sinon.spy(player, 'play');
adUnit.resumeAd();
sinon.assert.calledOnce(player.play);
});
it("must be able to tell if the adUnit is paused", function(){
var adUnit = vastIntegrator.playAd(new VASTResponse(), noop);
sinon.stub(player, 'paused').returns(true);
assert.isTrue(adUnit.isPaused());
player.paused.returns(false);
assert.isFalse(adUnit.isPaused());
});
it("must be able to return the src of the ad playing", function(){
var response = new VASTResponse();
var mediaFile = createMediaFile('http://foo.video.url.mp4', 'video/mp4');
response._addMediaFiles([mediaFile]);
var adUnit = vastIntegrator.playAd(response, noop);
assert.isNull(adUnit.getSrc());//Must return null until a src have been selected
this.clock.tick(1);
assert.equal(adUnit.getSrc(), mediaFile);
});
});
});

@@ -111,0 +150,0 @@

@@ -39,3 +39,3 @@ describe("videojs.vast plugin", function () {

}
sinon.assert.calledOnce(adsCanceledSpy);
sinon.assert.called(adsCanceledSpy);
}

@@ -80,2 +80,11 @@

it("must cancel the ads on 'vast.reset' evt", function(){
var spy = sinon.spy();
var player = videojs(document.createElement('video'), {});
player.on('vast.adsCancel', spy);
player.vastClient({url: 'http://fake.ad.url'});
player.trigger('vast.reset');
sinon.assert.calledOnce(spy);
});
describe("playAdAlways option", function () {

@@ -276,2 +285,50 @@ var resetSpy;

});
it("must set the player.vast.adUnit to null once we finish playing", function(){
player.vast.adUnit = {
type: 'FAKE'
};
player.vast.disable();
player.trigger('vast.firstPlay');
clock.tick(1);
assert.isNull(player.vast.adUnit);
});
describe("", function(){
beforeEach(function(){
sinon.stub(playerUtils, 'restorePlayerSnapshot');
});
afterEach(function(){
playerUtils.restorePlayerSnapshot.restore();
});
it("must restore the video content on 'vast.adsCancel' evt", function(){
player.vast.adUnit = {
type: 'FAKE',
pauseAd: noop,
resumeAd: noop,
isPaused: noop
};
player.trigger('vast.firstPlay');
clock.tick(1);
player.trigger('vast.adsCancel');
assert.isNull(player.vast.adUnit);
sinon.assert.calledOnce(playerUtils.restorePlayerSnapshot);
});
it("must restore the video content on 'error' evt", function(){
player.vast.adUnit = {
type: 'FAKE',
pauseAd: noop,
resumeAd: noop,
isPaused: noop
};
player.trigger('vast.firstPlay');
clock.tick(1);
player.trigger('error');
assert.isNull(player.vast.adUnit);
sinon.assert.calledOnce(playerUtils.restorePlayerSnapshot);
});
});
});

@@ -378,6 +435,7 @@

this.clock.tick(1);
sinon.assert.calledOnce(player.pause);
sinon.assert.called(player.pause);
player.pause.reset();
player.trigger('timeupdate');
this.clock.tick(1);
sinon.assert.calledTwice(player.pause);
sinon.assert.called(player.pause);
});

@@ -520,2 +578,13 @@

});
it("must publish the adUnit on the player.vast obj on 'vast.adStart' evt", function(){
var response = new VASTResponse();
response._addMediaFiles([
createMediaFile('http://fakeVideoFile', 'video/mp4')
]);
callback(null, response);
this.clock.tick(1);
player.trigger('vast.adStart');
assert.equal(player.vast.adUnit.type, 'VAST');
});
});

@@ -526,7 +595,7 @@

this.clock = sinon.useFakeTimers();
sinon.stub(playerUtils, 'isIPhone').returns(true);
sinon.stub(window, 'isIPhone').returns(true);
});
afterEach(function(){
playerUtils.isIPhone.restore();
window.isIPhone.restore();
this.clock.restore();

@@ -533,0 +602,0 @@ });

describe("VPAIDFlashTech", function () {
it("must be a function", function () {
assert.isFunction(VPAIDFlashTech);
});
it("must return an instance of itself", function () {

@@ -52,2 +48,6 @@ assert.instanceOf(VPAIDFlashTech({src:'fakeSource'}), VPAIDFlashTech);

it("must publish the name of the tech", function(){
assert.equal(vpaidFlashTech.name, 'vpaid-flash');
});
describe("loadAdUnit", function () {

@@ -92,2 +92,29 @@ it("must throw a VASTError if you don't pass a valid dom Element to contain the ad", function(){

});
it("must pass an error to the callback if there is an error instantiating the VPAIDFLASHClient", function(){
var fakeVpaidClient = {
loadAdUnit: sinon.spy()
};
var callback = sinon.spy();
sinon.stub(window, 'VPAIDFLASHClient').returns(fakeVpaidClient);
vpaidFlashTech.loadAdUnit(testDiv, null, callback);
var flushVPAIDClient = secondArg(VPAIDFLASHClient);
var fakeError = new Error('There was an error');
flushVPAIDClient(fakeError);
sinon.assert.calledWith(callback, fakeError);
window.VPAIDFLASHClient.restore();
});
it("must call the loadAdUnit function of the VPAIDFLAHSClient and the callback", function(){
var fakeVpaidClient = {
loadAdUnit: sinon.spy()
};
var callback = sinon.spy();
sinon.stub(window, 'VPAIDFLASHClient').returns(fakeVpaidClient);
vpaidFlashTech.loadAdUnit(testDiv, null, callback);
var flushVPAIDClient = secondArg(VPAIDFLASHClient);
flushVPAIDClient(null);
sinon.assert.calledWith(fakeVpaidClient.loadAdUnit, vpaidFlashTech.mediaFile.src, callback);
window.VPAIDFLASHClient.restore();
});
});

@@ -94,0 +121,0 @@

var VAST_ERROR_PREFIX = 'VAST Error: ';
describe("VPAIDHTML5Tech", function() {
it("must be a function", function () {
assert.isFunction(VPAIDHTML5Tech);
});
it("must return an instance of itself", function() {

@@ -12,7 +8,13 @@ assert.instanceOf(VPAIDHTML5Tech({src: 'fakeSource'}), VPAIDHTML5Tech);

it("must implement supports", function () {
sinon.stub(window, 'isOldIE').returns(false);
assert.isFunction(VPAIDHTML5Tech.supports);
assert(!VPAIDHTML5Tech.supports('application/x-shockwave-flash'));
assert(VPAIDHTML5Tech.supports('application/javascript'));
//Must return false for old IE (IE9 and below)
window.isOldIE.returns(9);
assert(!VPAIDHTML5Tech.supports('application/javascript'));
window.isOldIE.restore();
});

@@ -43,2 +45,7 @@

it("must publish the name of the tech", function(){
assert.equal(vpaidTech.name, 'vpaid-html5');
});
describe("loadAdUnit", function() {

@@ -45,0 +52,0 @@ it("must throw a VASTError if you don't pass a valid dom Element to contain the ad", function() {

@@ -52,2 +52,5 @@ describe("VPAIDIntegrator", function () {

};
this.pauseAd = sinon.spy();
this.resumeAd = sinon.spy();
}

@@ -115,2 +118,3 @@

fakeTech.prototype.name = 'vpaid-fake';
fakeTech.prototype.loadAdUnit = sinon.spy();

@@ -154,2 +158,27 @@ fakeTech.prototype.unloadAdUnit = sinon.spy();

it("must trigger a vpaid.adEnd evt on error evt", function(){
var spy = sinon.spy();
player.on('vpaid.adEnd', spy);
vpaidIntegrator.playAd(vastResponse, callback);
player.trigger('error');
assert.isTrue(spy.calledOnce);
});
it("must trigger a vpaid.adEnd evt on vast.adsCancel evt", function(){
var spy = sinon.spy();
player.on('vpaid.adEnd', spy);
vpaidIntegrator.playAd(vastResponse, callback);
player.trigger('vast.adsCancel');
assert.isTrue(spy.calledOnce);
});
it("must trigger a vpaid.adEnd evt twice", function(){
var spy = sinon.spy();
player.on('vpaid.adEnd', spy);
vpaidIntegrator.playAd(vastResponse, callback);
player.trigger('error');
player.trigger('vast.adsCancel');
assert.isTrue(spy.calledOnce);
});
it("must add 'vjs-vpaid-ad' class to the player element", function () {

@@ -172,14 +201,16 @@ assert.isFalse(dom.hasClass(player.el(), 'vjs-vpaid-ad'));

it("must remove 'vjs-vpaid-ad' class if there is an 'error' event", function () {
vpaidIntegrator.playAd(vastResponse, callback);
player.trigger('error');
this.clock.tick(1);
assert.isFalse(dom.hasClass(player.el(), 'vjs-vpaid-ad'));
});
['error', 'vast.adsCancel', 'vpaid.adEnd'].forEach(function (evt) {
it("must remove 'vjs-vpaid-ad' class if there is an '"+evt+"' event", function () {
vpaidIntegrator.playAd(vastResponse, callback);
player.trigger(evt);
this.clock.tick(1);
assert.isFalse(dom.hasClass(player.el(), 'vjs-vpaid-ad'));
});
it("must unload the adUnit if there is an 'error' event", function () {
vpaidIntegrator.playAd(vastResponse, callback);
player.trigger('error');
this.clock.tick(1);
sinon.assert.calledOnce(fakeTech.prototype.unloadAdUnit);
it("must unload the adUnit if there is an '"+evt+"' event", function () {
vpaidIntegrator.playAd(vastResponse, callback);
player.trigger(evt);
this.clock.tick(1);
sinon.assert.calledOnce(fakeTech.prototype.unloadAdUnit);
});
});

@@ -196,4 +227,4 @@

it("must trigger 'VPAID.adEnd'", function () {
player.on('VPAID.adEnd', callback);
it("must trigger 'vpaid.adEnd'", function () {
player.on('vpaid.adEnd', callback);
vpaidIntegrator.playAd(vastResponse, noop);

@@ -208,2 +239,36 @@ this.clock.tick(1);

describe("return obj", function(){
it("must have the type VPAID", function(){
var adUnit = vpaidIntegrator.playAd(vastResponse, noop);
assert.equal(adUnit.type, 'VPAID')
});
it("must trigger the vpaid.pauseAd evt", function(){
var adUnit =vpaidIntegrator.playAd(vastResponse, noop);
var spy = sinon.spy();
player.on('vpaid.pauseAd', spy);
adUnit.pauseAd();
sinon.assert.calledOnce(spy);
});
it("must trigger the vpaid.resumeAd evt", function(){
var adUnit =vpaidIntegrator.playAd(vastResponse, noop);
var spy = sinon.spy();
player.on('vpaid.resumeAd', spy);
adUnit.resumeAd();
sinon.assert.calledOnce(spy);
});
it("must know if it is paused", function(){
var adUnit = vpaidIntegrator.playAd(vastResponse, noop);
assert(adUnit.isPaused());
adUnit._paused = false;
assert(!adUnit.isPaused());
});
it("must be able to return the source of the ad", function(){
var adUnit = vpaidIntegrator.playAd(vastResponse, noop);
assert.equal(adUnit.getSrc(), fakeTech.prototype.mediaFile);
});
});
});

@@ -225,6 +290,5 @@

sinon.assert.calledWithExactly(callback, fakeTechNativeError, undefined, vastResponse);
});
it("must pass the error , a wrapped adUnit and the vast response to the callback", function () {
it("must pass the error, a wrapped adUnit and the vast response to the callback", function () {
var testTech = new fakeTech();

@@ -249,2 +313,19 @@ vpaidIntegrator._loadAdUnit(testTech, vastResponse, callback);

});
it("must add the tech class to the player and remove it on 'vpaid.adEnd' event",function(){
var testTech = new fakeTech();
var fakeAdUnit = {};
sinon.stub(window, 'VPAIDAdUnitWrapper').returns(fakeAdUnit);
vpaidIntegrator._loadAdUnit(testTech, vastResponse, callback);
var techLoadAdUnitCb = thirdArg(testTech.loadAdUnit);
//We make the adUnit invalid
vpaidAdUnit.initAd = undefined;
techLoadAdUnitCb(null, vpaidAdUnit);
sinon.assert.calledWithExactly(callback, null, fakeAdUnit, vastResponse);
assert.isTrue(dom.hasClass(player.el(), 'vjs-vpaid-fake-ad'));
player.trigger('vpaid.adEnd');
assert.isFalse(dom.hasClass(player.el(), 'vjs-vpaid-fake-ad'));
VPAIDAdUnitWrapper.restore();
});
});

@@ -348,4 +429,14 @@

sinon.spy(adUnitWrapper, 'initAd');
sinon.stub(dom, 'getDimension').returns(
{
width: 720,
height: 480
}
);
});
afterEach(function(){
dom.getDimension.restore();
});
it("must be a function", function () {

@@ -394,3 +485,2 @@ assert.isFunction(vpaidIntegrator._initAd);

it("must call next with no error and the passed adUnit and vastResponse", function(){

@@ -414,7 +504,26 @@ sinon.assert.calledWithExactly(next, null, adUnit, vastResponse);

it("on 'AdVideoStart' event, must track start", function(){
it("on 'AdVideoStart' event, must track start, resume the adUnit and trigger 'play' evt", function(){
var playSpy = sinon.spy();
player.on('play', playSpy);
vpaidIntegrator._adUnit = {
isPaused: echoFn(true)
};
adUnit.trigger('AdVideoStart');
sinon.assert.calledOnce(tracker.trackStart);
assert.isFalse(vpaidIntegrator._adUnit._paused);
assert(playSpy.calledOnce);
});
it("on 'AdStarted' event, must resume the adUnit and trigger 'play' evt", function(){
var playSpy = sinon.spy();
player.on('play', playSpy);
vpaidIntegrator._adUnit = {
isPaused: echoFn(true)
};
adUnit.trigger('AdStarted');
assert.isFalse(vpaidIntegrator._adUnit._paused);
assert(playSpy.calledOnce);
});
it("on 'AdVideoFirstQuartile' event, must track first quartile", function(){

@@ -488,5 +597,11 @@ adUnit.trigger('AdVideoFirstQuartile');

it("on 'AdPaused' event, must track pause", function(){
it("on 'AdPaused' event, must track pause, pause the adUnit and trigger 'pause' evt", function(){
var pauseSpy = sinon.spy();
player.on('pause', pauseSpy);
vpaidIntegrator._adUnit = {};
adUnit.trigger('AdPaused');
sinon.assert.calledOnce(tracker.trackPause);
assert(vpaidIntegrator._adUnit._paused);
assert(pauseSpy.calledOnce);
});

@@ -504,5 +619,13 @@

it("on 'AdPlaying' event, must track resume", function(){
adUnit.trigger('AdPlaying');
sinon.assert.calledOnce(tracker.trackResume);
it("on 'AdPlaying' event, must track resume, resume the adUnit and trigger 'play' evt", function(){
var playSpy = sinon.spy();
player.on('play', playSpy);
vpaidIntegrator._adUnit = {
isPaused: echoFn(true)
};
adUnit.trigger('AdPlaying');
sinon.assert.calledOnce(tracker.trackResume);
assert.isFalse(vpaidIntegrator._adUnit._paused);
assert(playSpy.calledOnce);
});

@@ -560,2 +683,19 @@

it("must pause the ad unit on 'vpaid.pauseAd' evt", function(){
player.trigger('vpaid.pauseAd');
sinon.assert.calledOnce(adUnit.pauseAd);
});
it("must pause the ad unit on 'vpaid.resumeAd' evt", function(){
player.trigger('vpaid.resumeAd');
sinon.assert.calledOnce(adUnit.resumeAd);
});
it("must not pause or resume the adUnit after 'vaid.adEnd' event", function(){
player.trigger('vpaid.adEnd');
player.trigger('vpaid.resumeAd');
player.trigger('vpaid.pauseAd');
sinon.assert.notCalled(adUnit.resumeAd);
sinon.assert.notCalled(adUnit.pauseAd);
});
});

@@ -702,5 +842,5 @@

it("must unsubscribe on 'VPAID.adEnd' events", function () {
it("must unsubscribe on 'vpaid.adEnd' events", function () {
vpaidIntegrator._linkPlayerControls(adUnitWrapper, vastResponse, callback);
player.trigger('VPAID.adEnd');
player.trigger('vpaid.adEnd');
player.trigger('volumechange');

@@ -720,13 +860,13 @@ sinon.assert.notCalled(adUnitWrapper.setAdVolume);

player.trigger('fullscreenchange');
sinon.assert.calledWith(adUnitWrapper.resizeAd, 720, 480, vpaidIntegrator.VIEW_MODE.NORMAL);
sinon.assert.calledWith(adUnitWrapper.resizeAd, 300, 150, vpaidIntegrator.VIEW_MODE.NORMAL);
player.isFullscreen.returns(true);
player.trigger('fullscreenchange');
sinon.assert.calledWith(adUnitWrapper.resizeAd, 720, 480, vpaidIntegrator.VIEW_MODE.FULLSCREEN);
sinon.assert.calledWith(adUnitWrapper.resizeAd, 300, 150, vpaidIntegrator.VIEW_MODE.FULLSCREEN);
});
it("must unsubscribe on 'VPAID-adfinsished'", function () {
it("must unsubscribe on 'vpaid.adEnd' event", function () {
sinon.stub(player, 'isFullscreen');
vpaidIntegrator._linkPlayerControls(adUnitWrapper, vastResponse, callback);
player.trigger('VPAID.adEnd');
player.trigger('vpaid.adEnd');
player.trigger('fullscreenchange');

@@ -810,2 +950,11 @@ sinon.assert.notCalled(adUnitWrapper.resizeAd);

});
it("must not handle vast.resize after 'vpaid.adEnd' events", function(){
var vpaidIntegrator = new VPAIDIntegrator(player, {autoResize: true});
var adUnit = new FakeAdUnit();
vpaidIntegrator._setupEvents(adUnit, new VASTResponse(), noop);
player.trigger('vpaid.adEnd');
player.trigger('vast.resize');
assert(adUnit.resizeAd.notCalled);
});
});

@@ -812,0 +961,0 @@

@@ -25,6 +25,2 @@ describe("playerUtils", function () {

it("must be an object", function () {
assert.isObject(playerUtils);
});
describe("getPlayerSnapshot", function () {

@@ -60,3 +56,3 @@ it("must return a snapshot obj", function () {

it("must keep the state (paused/playing) of the player", function(){
it("must keep the state (paused/playing) of the player", function () {
sinon.stub(player, 'paused').returns(false);

@@ -93,3 +89,3 @@ var snapshot = playerUtils.getPlayerSnapshot(player);

afterEach(function(){
afterEach(function () {
player.remoteTextTracks.restore();

@@ -106,4 +102,4 @@ });

});
it("must be empty if there are no remoteTracks", function(){
it("must be empty if there are no remoteTracks", function () {
player.remoteTextTracks.returns(null);

@@ -117,6 +113,6 @@ var snapshot = playerUtils.getPlayerSnapshot(player);

describe("restorePlayerSnapshot", function(){
describe("restorePlayerSnapshot", function () {
var testTrack, snapshot;
beforeEach(function(){
beforeEach(function () {
testTrack = {

@@ -136,7 +132,7 @@ kind: 'captions',

afterEach(function(){
afterEach(function () {
player.remoteTextTracks.restore();
});
it("must restore the player poster", function(){
it("must restore the player poster", function () {
tech.poster = '';

@@ -148,3 +144,3 @@ playerUtils.restorePlayerSnapshot(player, snapshot);

it("must restore the tech style", function(){
it("must restore the tech style", function () {
tech.setAttribute('style', '');

@@ -156,11 +152,11 @@ playerUtils.restorePlayerSnapshot(player, snapshot);

describe("when src has not changed", function(){
beforeEach(function(){
describe("when src has not changed", function () {
beforeEach(function () {
sinon.stub(player, 'play');
});
afterEach(function(){
afterEach(function () {
player.play.restore();
});
it("must restore the tracks", function(){
it("must restore the tracks", function () {
playerUtils.restorePlayerSnapshot(player, snapshot);

@@ -171,3 +167,3 @@ assert.equal(snapshot.suppressedTracks.length, 1);

it("if snapshot was playing must start the video", function(){
it("if snapshot was playing must start the video", function () {
snapshot.playing = true;

@@ -178,3 +174,3 @@ playerUtils.restorePlayerSnapshot(player, snapshot);

it("if snapshot was paused must not start the video", function(){
it("if snapshot was paused must not start the video", function () {
snapshot.playing = false;

@@ -186,4 +182,4 @@ playerUtils.restorePlayerSnapshot(player, snapshot);

describe("when src has changed", function(){
beforeEach(function(){
describe("when src has changed", function () {
beforeEach(function () {
//We change the src of the player

@@ -193,3 +189,3 @@ player.src("http://c.brightcove.com/services/mobile/streaming/index/rendition.m3u8?assetId=4367587778001");

it("must restore tracks on 'contentloadedmetadata' event", function(){
it("must restore tracks on 'contentloadedmetadata' event", function () {
playerUtils.restorePlayerSnapshot(player, snapshot);

@@ -202,3 +198,3 @@ assert.equal(snapshot.suppressedTracks.length, 1);

it("must restore the src", function(){
it("must restore the src", function () {
assert.equal(player.src(), "http://c.brightcove.com/services/mobile/streaming/index/rendition.m3u8?assetId=4367587778001");

@@ -212,3 +208,3 @@ assert.equal(player.currentType(), '');

it("must load the restored src", function(){
it("must load the restored src", function () {
sinon.stub(player, 'load');

@@ -220,4 +216,4 @@ playerUtils.restorePlayerSnapshot(player, snapshot);

describe("on 'canplay' event", function(){
beforeEach(function(){
describe("on 'canplay' event", function () {
beforeEach(function () {
sinon.stub(player, 'play');

@@ -228,3 +224,3 @@ sinon.stub(playerUtils, 'isReadyToResume');

afterEach(function(){
afterEach(function () {
player.play.restore();

@@ -235,3 +231,3 @@ playerUtils.isReadyToResume.restore();

it("must resume the the player if the tech is ready to resume", function(){
it("must resume the the player if the tech is ready to resume", function () {
snapshot.playing = true;

@@ -249,3 +245,3 @@ snapshot.currentTime = 10;

it("must wait until the tech is ready to resume the player", function(){
it("must wait until the tech is ready to resume the player", function () {
var clock = sinon.useFakeTimers();

@@ -270,3 +266,3 @@ snapshot.playing = true;

it("must try to resume the player if the tech takes more than 2 seconds to be ready", function(){
it("must try to resume the player if the tech takes more than 2 seconds to be ready", function () {
var clock = sinon.useFakeTimers();

@@ -289,3 +285,3 @@ snapshot.playing = true;

it("must log a warning if the resume action throws an exception after waiting for the tech to be ready", function(){
it("must log a warning if the resume action throws an exception after waiting for the tech to be ready", function () {
var clock = sinon.useFakeTimers();

@@ -311,4 +307,4 @@ sinon.stub(videojs.log, 'warn');

describe("isReadyToResume", function(){
it("must return true if the tech.readyState > 1", function(){
describe("isReadyToResume", function () {
it("must return true if the tech.readyState > 1", function () {
assert.isTrue(playerUtils.isReadyToResume({

@@ -319,3 +315,3 @@ readyState: 2

it("must return true if the tech doesn't expose the seekable time ranges", function(){
it("must return true if the tech doesn't expose the seekable time ranges", function () {
assert.isTrue(playerUtils.isReadyToResume({

@@ -327,3 +323,3 @@ readyState: 0,

it("must return true if the tech exposes the seekable time ranges", function(){
it("must return true if the tech exposes the seekable time ranges", function () {
assert.isTrue(playerUtils.isReadyToResume({

@@ -335,3 +331,3 @@ readyState: 0,

it("must return false if the tech isn not ready an seekable", function(){
it("must return false if the tech isn not ready an seekable", function () {
assert.isFalse(playerUtils.isReadyToResume({

@@ -345,12 +341,12 @@ readyState: 0,

describe("playerUtils.prepareForAds", function() {
beforeEach(function(){
sinon.stub(playerUtils, 'isIPhone').returns(false);
describe("playerUtils.prepareForAds", function () {
beforeEach(function () {
sinon.stub(window, 'isIPhone').returns(false);
});
afterEach(function(){
playerUtils.isIPhone.restore();
afterEach(function () {
window.isIPhone.restore();
});
it("must add the BlackPoster component to the player", function(){
it("must add the blackPoster component to the player", function () {
var player = videojs(document.createElement('video'), {});

@@ -361,6 +357,6 @@ playerUtils.prepareForAds(player);

describe("", function(){
describe("", function () {
var player, blackPoster;
beforeEach(function(){
beforeEach(function () {
player = videojs(document.createElement('video'), {});

@@ -373,3 +369,3 @@ playerUtils.prepareForAds(player);

afterEach(function(){
afterEach(function () {
blackPoster.hide.restore();

@@ -379,3 +375,3 @@ blackPoster.show.restore();

it("must hide the BlackPoster on 'error' event", function(){
it("must hide the BlackPoster on 'error' event", function () {
player.trigger('error');

@@ -385,3 +381,3 @@ sinon.assert.calledOnce(blackPoster.hide);

it("must hide the BlackPoster on 'vast.adStart' event", function(){
it("must hide the BlackPoster on 'vast.adStart' event", function () {
player.trigger('vast.adStart');

@@ -391,3 +387,3 @@ sinon.assert.calledOnce(blackPoster.hide);

it("must hide the blackPoster on 'vast.adsCancel' event", function(){
it("must hide the blackPoster on 'vast.adsCancel' event", function () {
player.trigger('vast.adsCancel');

@@ -397,3 +393,3 @@ sinon.assert.calledOnce(blackPoster.hide);

it("must not hide the blackPoster if is already hidden", function(){
it("must not hide the blackPoster if is already hidden", function () {
dom.addClass(blackPoster.el(), 'vjs-hidden');

@@ -405,3 +401,3 @@ player.trigger('vast.adStart');

it("must show the blackPoster on 'loadStart' event", function(){
it("must show the blackPoster on 'loadStart' event", function () {
player.trigger('loadStart');

@@ -412,12 +408,234 @@ sinon.assert.calledOnce(blackPoster.show);

it("must mute the player when you first play the video (player's play method)", function(){
var player = videojs(document.createElement('video'), {});
playerUtils.prepareForAds(player);
player.volume(1);
player.muted(false);
player.play();
assert.isTrue(player.muted());
describe("monkeyPatched", function () {
describe("player.play", function () {
describe("on first play", function () {
var player;
beforeEach(function () {
player = videojs(document.createElement('video'), {});
sinon.stub(window, 'isMobile').returns(true);
});
afterEach(function () {
window.isMobile.restore();
});
it("must mute the player when you first play the video (player's play method)", function () {
playerUtils.prepareForAds(player);
player.volume(1);
player.muted(false);
player.play();
assert.isTrue(player.muted());
});
it("must restore the muted volume on 'vast.firstPlay' evt", function () {
playerUtils.prepareForAds(player);
player.volume(1);
player.muted(false);
player.play();
assert.isTrue(player.muted());
player.trigger('vast.firstPlay');
assert.isFalse(player.muted());
assert.equal(player.volume(), 1);
});
it("must set the currentTime to 0 on 'vast.firstPlay' evt", function () {
var player = videojs(document.createElement('video'), {});
sinon.stub(player, 'currentTime');
sinon.assert.notCalled(player.currentTime);
playerUtils.prepareForAds(player);
player.play();
player.trigger('vast.firstPlay');
sinon.assert.calledWithExactly(player.currentTime, 0);
});
it("must call player's play method", function () {
var player = videojs(document.createElement('video'), {});
var playStub = sinon.stub(player, 'play');
playerUtils.prepareForAds(player);
player.play();
assert(playStub.calledOnce);
});
describe("on iPhone", function () {
it("must NOT set the currentTime to 0 on the first play", function () {
window.isIPhone.returns(true);
var player = videojs(document.createElement('video'), {});
sinon.stub(player, 'currentTime');
sinon.assert.notCalled(player.currentTime);
playerUtils.prepareForAds(player);
player.trigger('vast.firstPlay');
sinon.assert.neverCalledWith(player.currentTime, 0);
});
it("must NOT restore the muted volume on 'vast.firstPlay' evt", function () {
window.isIPhone.returns(true);
playerUtils.prepareForAds(player);
player.volume(1);
player.muted(false);
player.play();
assert.isFalse(player.muted());
player.trigger('vast.firstPlay');
assert.isFalse(player.muted());
assert.equal(player.volume(), 1);
});
});
});
describe("on Resume", function () {
var player, playSpy;
beforeEach(function () {
player = videojs(document.createElement('video'), {});
playSpy = sinon.spy(player, 'play');
});
it("must resume the video content", function () {
playerUtils.prepareForAds(player);
player.trigger('play');
sinon.assert.notCalled(playSpy);
player.play();
sinon.assert.calledOnce(playSpy);
});
it("with an ad playing it must resume the ad and not resume the video content", function () {
var fakeAdUnit = {
resumeAd: sinon.spy()
};
playerUtils.prepareForAds(player);
player.trigger('play');
//We fake that an ad is playing
player.vast = {adUnit: fakeAdUnit};
player.play();
assert.isTrue(playSpy.notCalled);
sinon.assert.calledOnce(fakeAdUnit.resumeAd);
});
it("with an ad playing called with the callOrig flag to true, must call the orig play", function () {
var fakeAdUnit = {
resumeAd: sinon.spy()
};
playerUtils.prepareForAds(player);
player.play();
//We fake that an ad is playing
player.vast = {adUnit: fakeAdUnit};
sinon.assert.calledOnce(playSpy);
player.play(true);
sinon.assert.calledTwice(playSpy);
});
});
it("must return the player", function () {
var player = videojs(document.createElement('video'), {});
playerUtils.prepareForAds(player);
assert.equal(player.play(), player);
});
});
describe("player.pause", function () {
var player, pauseSpy;
beforeEach(function () {
player = videojs(document.createElement('video'), {});
pauseSpy = sinon.spy(player, 'pause');
});
it("must return the player", function () {
playerUtils.prepareForAds(player);
assert.equal(player.pause(), player);
});
it("must pause the content", function () {
playerUtils.prepareForAds(player);
player.pause();
assert.isTrue(pauseSpy.calledOnce);
});
describe("with an ad playing", function () {
beforeEach(function () {
player.vast = {
adUnit: {
pauseAd: sinon.spy()
}
};
});
it("must pause the ad and not the video content", function(){
playerUtils.prepareForAds(player);
player.pause();
assert.isTrue(pauseSpy.notCalled);
assert.isTrue(player.vast.adUnit.pauseAd.calledOnce);
});
it("must pause the content if called with the callOriginalPause flag to true", function(){
playerUtils.prepareForAds(player);
player.pause(true);
assert.isTrue(pauseSpy.calledOnce);
assert.isTrue(player.vast.adUnit.pauseAd.notCalled);
});
});
});
describe("player.paused", function(){
var player, pausedStub;
beforeEach(function () {
player = videojs(document.createElement('video'), {});
pausedStub = sinon.stub(player, 'paused');
});
it("must return true if the player is paused and false otherwise", function(){
playerUtils.prepareForAds(player);
pausedStub.returns(false);
assert.isFalse(player.paused());
pausedStub.returns(true);
assert.isTrue(player.paused());
});
describe("with ads enabled", function(){
beforeEach(function () {
player.vast = {
adUnit: {
isPaused: sinon.stub()
}
};
});
it("must return true if the ad is paused and false otherwise", function(){
playerUtils.prepareForAds(player);
player.vast.adUnit.isPaused.returns(false);
assert.isFalse(player.paused());
player.vast.adUnit.isPaused.returns(true);
assert.isTrue(player.paused());
});
it("must check if the content is paused if called with the callOriginalPause flag to true", function(){
playerUtils.prepareForAds(player);
pausedStub.returns(false);
assert.isFalse(player.paused(true));
pausedStub.returns(true);
assert.isTrue(player.paused(true));
sinon.assert.notCalled(player.vast.adUnit.isPaused);
});
});
});
});
it("must not mute the video if the play is not the firstPlay", function(){
it("must not mute the video if the play is not the firstPlay", function () {
var player = videojs(document.createElement('video'), {});

@@ -433,4 +651,4 @@ playerUtils.prepareForAds(player);

it("must not mute the video if it is on an iphone device", function(){
playerUtils.isIPhone.returns(true);
it("must not mute the video if it is on an iphone device", function () {
window.isIPhone.returns(true);
var player = videojs(document.createElement('video'), {});

@@ -442,28 +660,5 @@ playerUtils.prepareForAds(player);

it("must restore the muted volume on the first play", function(){
it("must add the 'vjs-ad-playing' class on vast.adStart to the player.el()", function () {
var player = videojs(document.createElement('video'), {});
playerUtils.prepareForAds(player);
player.volume(1);
player.muted(false);
player.play();
assert.isTrue(player.muted());
player.trigger('vast.firstPlay');
assert.isFalse(player.muted());
assert.equal(player.volume(), 1);
});
it("must set the currentTime to 0 on the first play", function(){
var player = videojs(document.createElement('video'), {});
sinon.stub(player, 'currentTime');
sinon.assert.notCalled(player.currentTime);
playerUtils.prepareForAds(player);
player.trigger('vast.firstPlay');
sinon.assert.calledWithExactly(player.currentTime, 0);
});
it("must add the 'vjs-ad-playing' class on vast.adStart to the player.el()", function(){
var player = videojs(document.createElement('video'), {});
playerUtils.prepareForAds(player);
assert.isFalse(dom.hasClass(player.el(), 'vjs-ad-playing'));

@@ -474,3 +669,3 @@ player.trigger('vast.adStart');

it("must remove the 'vjs-ad-playing' class on vast.adsCancel to the player.el()", function(){
it("must remove the 'vjs-ad-playing' class on vast.adsCancel to the player.el()", function () {
var player = videojs(document.createElement('video'), {});

@@ -483,3 +678,3 @@ playerUtils.prepareForAds(player);

it("must remove the 'vjs-ad-playing' class on vast.adEnd to the player.el()", function(){
it("must remove the 'vjs-ad-playing' class on vast.adEnd to the player.el()", function () {
var player = videojs(document.createElement('video'), {});

@@ -492,14 +687,3 @@ playerUtils.prepareForAds(player);

it("on Iphone, must NOT set the currentTime to 0 on the first play", function(){
playerUtils.isIPhone.returns(true);
var player = videojs(document.createElement('video'), {});
sinon.stub(player, 'currentTime');
sinon.assert.notCalled(player.currentTime);
playerUtils.prepareForAds(player);
player.trigger('vast.firstPlay');
sinon.assert.neverCalledWith(player.currentTime, 0);
});
describe("firstPlay", function(){
describe("firstPlay", function () {
var player, firstPlaySpy;

@@ -514,3 +698,3 @@

it("must be triggered on the first play", function(){
it("must be triggered on the first play", function () {
player.on('vast.firstPlay', firstPlaySpy);

@@ -521,3 +705,3 @@ player.trigger('play');

it("must not be triggered on a second play event", function(){
it("must not be triggered on a second play event", function () {
player.on('vast.firstPlay', firstPlaySpy);

@@ -531,3 +715,3 @@ player.trigger('play');

it("must be reset on 'loadStart' event", function(){
it("must be reset on 'loadStart' event", function () {
player.on('vast.firstPlay', firstPlaySpy);

@@ -540,3 +724,3 @@ player.trigger('play');

it("must be reset on 'vast.reset' event", function(){
it("must be reset on 'vast.reset' event", function () {
player.on('vast.firstPlay', firstPlaySpy);

@@ -551,3 +735,4 @@ player.trigger('play');

describe("playerUtils.removeNativePoster", function(){ var testDiv, player, tech;
describe("playerUtils.removeNativePoster", function () {
var testDiv, player, tech;

@@ -573,3 +758,3 @@ beforeEach(function () {

it("must remove the poster of the passed player", function(){
it("must remove the poster of the passed player", function () {
var tech = player.el().querySelector('.vjs-tech');

@@ -581,4 +766,4 @@ playerUtils.removeNativePoster(player);

describe("playerUtils.only", function(){
it("must execute the passed handler once and only once no matter how many events we register to it.", function(){
describe("playerUtils.only", function () {
it("must execute the passed handler once and only once no matter how many events we register to it.", function () {
var spy = sinon.spy();

@@ -585,0 +770,0 @@ var player = videojs(document.createElement('video'), {});

@@ -731,2 +731,63 @@ describe("noop", function () {

describe("getInternetExplorerVersion", function(){
var navigators = {
nonIe: {
appName: 'Netscape',
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"
},
ie8: {
appName: 'Microsoft Internet Explorer',
userAgent: "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"
},
ie9: {
appName: 'Microsoft Internet Explorer',
userAgent: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; InfoPath.3; MS-RTC LM 8; .NET4.0C; .NET4.0E)"
},
ie10: {
appName: 'Microsoft Internet Explorer',
userAgent: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)"
},
ie106: {
appName: 'Microsoft Internet Explorer',
userAgent: "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
},
ie11: {
appName: 'Microsoft Internet Explorer',
userAgent: "Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"
}
};
it("must return -1 for nonIe browsers", function(){
assert.strictEqual(getInternetExplorerVersion(navigators.nonIe), -1);
});
it("must return the appropiate IE versions", function(){
assert.strictEqual(getInternetExplorerVersion(navigators.ie8), 8);
assert.strictEqual(getInternetExplorerVersion(navigators.ie9), 9);
assert.strictEqual(getInternetExplorerVersion(navigators.ie10), 10);
assert.strictEqual(getInternetExplorerVersion(navigators.ie106), 10.6);
assert.strictEqual(getInternetExplorerVersion(navigators.ie11), 11);
});
});
describe("isOldIE", function(){
it("must return true if the browser is IE and older thatn 10", function(){
sinon.stub(window, 'getInternetExplorerVersion');
window.getInternetExplorerVersion.returns(-1);
assert.isFalse(isOldIE());
window.getInternetExplorerVersion.returns(7);
assert.isTrue(isOldIE());
window.getInternetExplorerVersion.returns(8);
assert.isTrue(isOldIE());
window.getInternetExplorerVersion.returns(9);
assert.isTrue(isOldIE());
window.getInternetExplorerVersion.returns(10.6);
assert.isFalse(isOldIE());
window.getInternetExplorerVersion.returns(11);
assert.isFalse(isOldIE());
window.getInternetExplorerVersion.restore();
});
});
describe("isIDevice", function(){

@@ -748,3 +809,3 @@ var old_UA;

});
it("must return true it the userAgent contains iPad", function(){

@@ -759,2 +820,86 @@ _UA = "browser iPad";

});
});
});
describe("isMobile", function(){
var old_UA;
beforeEach(function(){
old_UA = window._UA;
});
afterEach(function(){
window._UA = old_UA;
});
it("must return true if the userAgent contains iPhone or iPad or iPod or android or windows phone", function(){
window._UA = "browser iPhone";
assert.isTrue(isMobile());
window._UA = "browser iPad";
assert.isTrue(isMobile());
window._UA = "browser iPod";
assert.isTrue(isMobile());
window._UA = "Android";
assert.isTrue(isMobile());
window._UA = "Windows Phone";
assert.isTrue(isMobile());
});
it("must return false it the userAgent is not from mobile", function(){
window._UA = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)";
assert.isFalse(isMobile());
});
});
describe("isIPhone", function(){
var old_UA;
beforeEach(function(){
old_UA = window._UA;
});
afterEach(function(){
window._UA = old_UA;
});
it("must return true if the userAgent contains iPhone or iPod and false otherwise", function(){
window._UA = "browser iPhone";
assert.isTrue(isIPhone());
window._UA = "browser iPad";
assert.isFalse(isIPhone());
window._UA = "browser iPod";
assert.isTrue(isIPhone());
window._UA = "Android";
assert.isFalse(isIPhone());
window._UA = "Windows Phone";
assert.isFalse(isIPhone());
window._UA = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)";
assert.isFalse(isIPhone());
});
});
describe("isAndroid", function(){
var old_UA;
beforeEach(function(){
old_UA = window._UA;
});
afterEach(function(){
window._UA = old_UA;
});
it("must return true if the userAgent contains iPhone or iPod and false otherwise", function(){
window._UA = "browser iPhone";
assert.isFalse(isAndroid());
window._UA = "browser iPad";
assert.isFalse(isAndroid());
window._UA = "browser iPod";
assert.isFalse(isAndroid());
window._UA = "Android";
assert.isTrue(isAndroid());
window._UA = "Windows Phone";
assert.isFalse(isAndroid());
window._UA = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)";
assert.isFalse(isAndroid());
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc