UNPKG

flowplayer-vpaid

Version:

VPAID 2.0 (Flash/JS) support within Flowplayer 6 HTML

1,527 lines (1,312 loc) 69.6 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.fpvpaid = f()}})(function(){var define,module,exports;return (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){ 'use strict'; //simple representation of the API Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var IVPAIDAdUnit = exports.IVPAIDAdUnit = function () { function IVPAIDAdUnit() { _classCallCheck(this, IVPAIDAdUnit); } _createClass(IVPAIDAdUnit, [{ key: 'handshakeVersion', //all methods below //are async methods value: function handshakeVersion() { var playerVPAIDVersion = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '2.0'; var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; } //creativeData is an object to be consistent with VPAIDHTML }, { key: 'initAd', value: function initAd(width, height, viewMode, desiredBitrate) { var creativeData = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : { AdParameters: '' }; var environmentVars = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : { flashVars: '' }; var callback = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : undefined; } }, { key: 'resizeAd', value: function resizeAd(width, height, viewMode) { var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined; } }, { key: 'startAd', value: function startAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; } }, { key: 'stopAd', value: function stopAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; } }, { key: 'pauseAd', value: function pauseAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; } }, { key: 'resumeAd', value: function resumeAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; } }, { key: 'expandAd', value: function expandAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; } }, { key: 'collapseAd', value: function collapseAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; } }, { key: 'skipAd', value: function skipAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; } //properties that will be treat as async methods }, { key: 'getAdLinear', value: function getAdLinear(callback) {} }, { key: 'getAdWidth', value: function getAdWidth(callback) {} }, { key: 'getAdHeight', value: function getAdHeight(callback) {} }, { key: 'getAdExpanded', value: function getAdExpanded(callback) {} }, { key: 'getAdSkippableState', value: function getAdSkippableState(callback) {} }, { key: 'getAdRemainingTime', value: function getAdRemainingTime(callback) {} }, { key: 'getAdDuration', value: function getAdDuration(callback) {} }, { key: 'setAdVolume', value: function setAdVolume(soundVolume) { var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; } }, { key: 'getAdVolume', value: function getAdVolume(callback) {} }, { key: 'getAdCompanions', value: function getAdCompanions(callback) {} }, { key: 'getAdIcons', value: function getAdIcons(callback) {} }]); return IVPAIDAdUnit; }(); Object.defineProperty(IVPAIDAdUnit, 'EVENTS', { writable: false, configurable: false, value: ['AdLoaded', 'AdStarted', 'AdStopped', 'AdSkipped', 'AdSkippableStateChange', // VPAID 2.0 new event 'AdSizeChange', // VPAID 2.0 new event 'AdLinearChange', 'AdDurationChange', // VPAID 2.0 new event 'AdExpandedChange', 'AdRemainingTimeChange', // [Deprecated in 2.0] but will be still fired for backwards compatibility 'AdVolumeChange', 'AdImpression', 'AdVideoStart', 'AdVideoFirstQuartile', 'AdVideoMidpoint', 'AdVideoThirdQuartile', 'AdVideoComplete', 'AdClickThru', 'AdInteraction', // VPAID 2.0 new event 'AdUserAcceptInvitation', 'AdUserMinimize', 'AdUserClose', 'AdPaused', 'AdPlaying', 'AdLog', 'AdError'] }); },{}],2:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var IVPAIDAdUnit = require('./IVPAIDAdUnit').IVPAIDAdUnit; var ALL_VPAID_METHODS = Object.getOwnPropertyNames(IVPAIDAdUnit.prototype).filter(function (property) { return ['constructor'].indexOf(property) === -1; }); var VPAIDAdUnit = exports.VPAIDAdUnit = function (_IVPAIDAdUnit) { _inherits(VPAIDAdUnit, _IVPAIDAdUnit); function VPAIDAdUnit(flash) { _classCallCheck(this, VPAIDAdUnit); var _this = _possibleConstructorReturn(this, (VPAIDAdUnit.__proto__ || Object.getPrototypeOf(VPAIDAdUnit)).call(this)); _this._destroyed = false; _this._flash = flash; return _this; } _createClass(VPAIDAdUnit, [{ key: '_destroy', value: function _destroy() { var _this2 = this; this._destroyed = true; ALL_VPAID_METHODS.forEach(function (methodName) { _this2._flash.removeCallbackByMethodName(methodName); }); IVPAIDAdUnit.EVENTS.forEach(function (event) { _this2._flash.offEvent(event); }); this._flash = null; } }, { key: 'isDestroyed', value: function isDestroyed() { return this._destroyed; } }, { key: 'on', value: function on(eventName, callback) { this._flash.on(eventName, callback); } }, { key: 'off', value: function off(eventName, callback) { this._flash.off(eventName, callback); } //VPAID interface }, { key: 'handshakeVersion', value: function handshakeVersion() { var playerVPAIDVersion = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '2.0'; var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; this._flash.callFlashMethod('handshakeVersion', [playerVPAIDVersion], callback); } }, { key: 'initAd', value: function initAd(width, height, viewMode, desiredBitrate) { var creativeData = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : { AdParameters: '' }; var environmentVars = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : { flashVars: '' }; var callback = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : undefined; //resize element that has the flash object this._flash.setSize(width, height); creativeData = creativeData || { AdParameters: '' }; environmentVars = environmentVars || { flashVars: '' }; this._flash.callFlashMethod('initAd', [this._flash.getWidth(), this._flash.getHeight(), viewMode, desiredBitrate, creativeData.AdParameters || '', environmentVars.flashVars || ''], callback); } }, { key: 'resizeAd', value: function resizeAd(width, height, viewMode) { var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined; //resize element that has the flash object this._flash.setSize(width, height); //resize ad inside the flash this._flash.callFlashMethod('resizeAd', [this._flash.getWidth(), this._flash.getHeight(), viewMode], callback); } }, { key: 'startAd', value: function startAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; this._flash.callFlashMethod('startAd', [], callback); } }, { key: 'stopAd', value: function stopAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; this._flash.callFlashMethod('stopAd', [], callback); } }, { key: 'pauseAd', value: function pauseAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; this._flash.callFlashMethod('pauseAd', [], callback); } }, { key: 'resumeAd', value: function resumeAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; this._flash.callFlashMethod('resumeAd', [], callback); } }, { key: 'expandAd', value: function expandAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; this._flash.callFlashMethod('expandAd', [], callback); } }, { key: 'collapseAd', value: function collapseAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; this._flash.callFlashMethod('collapseAd', [], callback); } }, { key: 'skipAd', value: function skipAd() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; this._flash.callFlashMethod('skipAd', [], callback); } //properties that will be treat as async methods }, { key: 'getAdLinear', value: function getAdLinear(callback) { this._flash.callFlashMethod('getAdLinear', [], callback); } }, { key: 'getAdWidth', value: function getAdWidth(callback) { this._flash.callFlashMethod('getAdWidth', [], callback); } }, { key: 'getAdHeight', value: function getAdHeight(callback) { this._flash.callFlashMethod('getAdHeight', [], callback); } }, { key: 'getAdExpanded', value: function getAdExpanded(callback) { this._flash.callFlashMethod('getAdExpanded', [], callback); } }, { key: 'getAdSkippableState', value: function getAdSkippableState(callback) { this._flash.callFlashMethod('getAdSkippableState', [], callback); } }, { key: 'getAdRemainingTime', value: function getAdRemainingTime(callback) { this._flash.callFlashMethod('getAdRemainingTime', [], callback); } }, { key: 'getAdDuration', value: function getAdDuration(callback) { this._flash.callFlashMethod('getAdDuration', [], callback); } }, { key: 'setAdVolume', value: function setAdVolume(volume) { var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; this._flash.callFlashMethod('setAdVolume', [volume], callback); } }, { key: 'getAdVolume', value: function getAdVolume(callback) { this._flash.callFlashMethod('getAdVolume', [], callback); } }, { key: 'getAdCompanions', value: function getAdCompanions(callback) { this._flash.callFlashMethod('getAdCompanions', [], callback); } }, { key: 'getAdIcons', value: function getAdIcons(callback) { this._flash.callFlashMethod('getAdIcons', [], callback); } }]); return VPAIDAdUnit; }(IVPAIDAdUnit); },{"./IVPAIDAdUnit":1}],3:[function(require,module,exports){ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var JSFlashBridge = require('./jsFlashBridge').JSFlashBridge; var VPAIDAdUnit = require('./VPAIDAdUnit').VPAIDAdUnit; var noop = require('./utils').noop; var callbackTimeout = require('./utils').callbackTimeout; var isPositiveInt = require('./utils').isPositiveInt; var createElementWithID = require('./utils').createElementWithID; var uniqueVPAID = require('./utils').unique('vpaid'); var ERROR = 'error'; var FLASH_VERSION = '10.1.0'; var VPAIDFLASHClient = function () { function VPAIDFLASHClient(vpaidParentEl, callback) { var swfConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { data: 'VPAIDFlash.swf', width: 800, height: 400 }; var _this = this; var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { wmode: 'transparent', salign: 'tl', align: 'left', allowScriptAccess: 'always', scale: 'noScale', allowFullScreen: 'true', quality: 'high' }; var vpaidOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : { debug: false, timeout: 10000 }; _classCallCheck(this, VPAIDFLASHClient); if (!VPAIDFLASHClient.hasExternalDependencies()) { return onError('no swfobject in global scope. check: https://github.com/swfobject/swfobject or https://code.google.com/p/swfobject/'); } this._vpaidParentEl = vpaidParentEl; this._flashID = uniqueVPAID(); this._destroyed = false; callback = callback || noop; swfConfig.width = isPositiveInt(swfConfig.width, 800); swfConfig.height = isPositiveInt(swfConfig.height, 400); createElementWithID(vpaidParentEl, this._flashID); params.movie = swfConfig.data; params.FlashVars = 'flashid=' + this._flashID + '&handler=' + JSFlashBridge.VPAID_FLASH_HANDLER + '&debug=' + vpaidOptions.debug + '&salign=' + params.salign; if (!VPAIDFLASHClient.isSupported()) { return onError('user don\'t support flash or doesn\'t have the minimum required version of flash ' + FLASH_VERSION); } this.el = swfobject.createSWF(swfConfig, params, this._flashID); if (!this.el) { return onError('swfobject failed to create object in element'); } var handler = callbackTimeout(vpaidOptions.timeout, function (err, data) { $loadPendedAdUnit.call(_this); callback(err, data); }, function () { callback('vpaid flash load timeout ' + vpaidOptions.timeout); }); this._flash = new JSFlashBridge(this.el, swfConfig.data, this._flashID, swfConfig.width, swfConfig.height, handler); function onError(error) { setTimeout(function () { callback(new Error(error)); }, 0); return this; } } _createClass(VPAIDFLASHClient, [{ key: 'destroy', value: function destroy() { this._destroyAdUnit(); if (this._flash) { this._flash.destroy(); this._flash = null; } this.el = null; this._destroyed = true; } }, { key: 'isDestroyed', value: function isDestroyed() { return this._destroyed; } }, { key: '_destroyAdUnit', value: function _destroyAdUnit() { delete this._loadLater; if (this._adUnitLoad) { this._adUnitLoad = null; this._flash.removeCallback(this._adUnitLoad); } if (this._adUnit) { this._adUnit._destroy(); this._adUnit = null; } } }, { key: 'loadAdUnit', value: function loadAdUnit(adURL, callback) { var _this2 = this; $throwIfDestroyed.call(this); if (this._adUnit) { this._destroyAdUnit(); } if (this._flash.isReady()) { this._adUnitLoad = function (err, message) { if (!err) { _this2._adUnit = new VPAIDAdUnit(_this2._flash); } _this2._adUnitLoad = null; callback(err, _this2._adUnit); }; this._flash.callFlashMethod('loadAdUnit', [adURL], this._adUnitLoad); } else { this._loadLater = { url: adURL, callback: callback }; } } }, { key: 'unloadAdUnit', value: function unloadAdUnit() { var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; $throwIfDestroyed.call(this); this._destroyAdUnit(); this._flash.callFlashMethod('unloadAdUnit', [], callback); } }, { key: 'getFlashID', value: function getFlashID() { $throwIfDestroyed.call(this); return this._flash.getFlashID(); } }, { key: 'getFlashURL', value: function getFlashURL() { $throwIfDestroyed.call(this); return this._flash.getFlashURL(); } }]); return VPAIDFLASHClient; }(); setStaticProperty('isSupported', function () { return VPAIDFLASHClient.hasExternalDependencies() && swfobject.hasFlashPlayerVersion(FLASH_VERSION); }); setStaticProperty('hasExternalDependencies', function () { return !!window.swfobject; }); function $throwIfDestroyed() { if (this._destroyed) { throw new error('VPAIDFlashToJS is destroyed!'); } } function $loadPendedAdUnit() { if (this._loadLater) { this.loadAdUnit(this._loadLater.url, this._loadLater.callback); delete this._loadLater; } } function setStaticProperty(propertyName, value) { Object.defineProperty(VPAIDFLASHClient, propertyName, { writable: false, configurable: false, value: value }); } window.VPAIDFLASHClient = VPAIDFLASHClient; module.exports = VPAIDFLASHClient; },{"./VPAIDAdUnit":2,"./jsFlashBridge":4,"./utils":7}],4:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var unique = require('./utils').unique; var isPositiveInt = require('./utils').isPositiveInt; var stringEndsWith = require('./utils').stringEndsWith; var SingleValueRegistry = require('./registry').SingleValueRegistry; var MultipleValuesRegistry = require('./registry').MultipleValuesRegistry; var registry = require('./jsFlashBridgeRegistry'); var VPAID_FLASH_HANDLER = 'vpaid_video_flash_handler'; var ERROR = 'AdError'; var JSFlashBridge = exports.JSFlashBridge = function () { function JSFlashBridge(el, flashURL, flashID, width, height, loadHandShake) { _classCallCheck(this, JSFlashBridge); this._el = el; this._flashID = flashID; this._flashURL = flashURL; this._width = width; this._height = height; this._handlers = new MultipleValuesRegistry(); this._callbacks = new SingleValueRegistry(); this._uniqueMethodIdentifier = unique(this._flashID); this._ready = false; this._handShakeHandler = loadHandShake; registry.addInstance(this._flashID, this); } _createClass(JSFlashBridge, [{ key: 'on', value: function on(eventName, callback) { this._handlers.add(eventName, callback); } }, { key: 'off', value: function off(eventName, callback) { return this._handlers.remove(eventName, callback); } }, { key: 'offEvent', value: function offEvent(eventName) { return this._handlers.removeByKey(eventName); } }, { key: 'offAll', value: function offAll() { return this._handlers.removeAll(); } }, { key: 'callFlashMethod', value: function callFlashMethod(methodName) { var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; var callbackID = ''; // if no callback, some methods the return is void so they don't need callback if (callback) { callbackID = this._uniqueMethodIdentifier() + '_' + methodName; this._callbacks.add(callbackID, callback); } try { //methods are created by ExternalInterface.addCallback in as3 code, if for some reason it failed //this code will throw an error this._el[methodName]([callbackID].concat(args)); } catch (e) { if (callback) { $asyncCallback.call(this, callbackID, e); } else { //if there isn't any callback to return error use error event handler this._trigger(ERROR, e); } } } }, { key: 'removeCallback', value: function removeCallback(callback) { return this._callbacks.removeByValue(callback); } }, { key: 'removeCallbackByMethodName', value: function removeCallbackByMethodName(suffix) { var _this = this; this._callbacks.filterKeys(function (key) { return stringEndsWith(key, suffix); }).forEach(function (key) { _this._callbacks.remove(key); }); } }, { key: 'removeAllCallbacks', value: function removeAllCallbacks() { return this._callbacks.removeAll(); } }, { key: '_trigger', value: function _trigger(eventName, event) { var _this2 = this; this._handlers.get(eventName).forEach(function (callback) { //clickThru has to be sync, if not will be block by the popupblocker if (eventName === 'AdClickThru') { callback(event); } else { setTimeout(function () { if (_this2._handlers.get(eventName).length > 0) { callback(event); } }, 0); } }); } }, { key: '_callCallback', value: function _callCallback(methodName, callbackID, err, result) { var callback = this._callbacks.get(callbackID); //not all methods callback's are mandatory //but if there exist an error, fire the error event if (!callback) { if (err && callbackID === '') { this.trigger(ERROR, err); } return; } $asyncCallback.call(this, callbackID, err, result); } }, { key: '_handShake', value: function _handShake(err, data) { this._ready = true; if (this._handShakeHandler) { this._handShakeHandler(err, data); delete this._handShakeHandler; } } //methods like properties specific to this implementation of VPAID }, { key: 'getSize', value: function getSize() { return { width: this._width, height: this._height }; } }, { key: 'setSize', value: function setSize(newWidth, newHeight) { this._width = isPositiveInt(newWidth, this._width); this._height = isPositiveInt(newHeight, this._height); this._el.setAttribute('width', this._width); this._el.setAttribute('height', this._height); } }, { key: 'getWidth', value: function getWidth() { return this._width; } }, { key: 'setWidth', value: function setWidth(newWidth) { this.setSize(newWidth, this._height); } }, { key: 'getHeight', value: function getHeight() { return this._height; } }, { key: 'setHeight', value: function setHeight(newHeight) { this.setSize(this._width, newHeight); } }, { key: 'getFlashID', value: function getFlashID() { return this._flashID; } }, { key: 'getFlashURL', value: function getFlashURL() { return this._flashURL; } }, { key: 'isReady', value: function isReady() { return this._ready; } }, { key: 'destroy', value: function destroy() { this.offAll(); this.removeAllCallbacks(); registry.removeInstanceByID(this._flashID); if (this._el.parentElement) { this._el.parentElement.removeChild(this._el); } } }]); return JSFlashBridge; }(); function $asyncCallback(callbackID, err, result) { var _this3 = this; setTimeout(function () { var callback = _this3._callbacks.get(callbackID); if (callback) { _this3._callbacks.remove(callbackID); callback(err, result); } }, 0); } Object.defineProperty(JSFlashBridge, 'VPAID_FLASH_HANDLER', { writable: false, configurable: false, value: VPAID_FLASH_HANDLER }); /** * External interface handler * * @param {string} flashID identifier of the flash who call this * @param {string} typeID what type of message is, can be 'event' or 'callback' * @param {string} typeName if the typeID is a event the typeName will be the eventName, if is a callback the typeID is the methodName that is related this callback * @param {string} callbackID only applies when the typeID is 'callback', identifier of the callback to call * @param {object} error error object * @param {object} data */ window[VPAID_FLASH_HANDLER] = function (flashID, typeID, typeName, callbackID, error, data) { var instance = registry.getInstanceByID(flashID); if (!instance) return; if (typeName === 'handShake') { instance._handShake(error, data); } else { if (typeID !== 'event') { instance._callCallback(typeName, callbackID, error, data); } else { instance._trigger(typeName, data); } } }; },{"./jsFlashBridgeRegistry":5,"./registry":6,"./utils":7}],5:[function(require,module,exports){ 'use strict'; var SingleValueRegistry = require('./registry').SingleValueRegistry; var instances = new SingleValueRegistry(); var JSFlashBridgeRegistry = {}; Object.defineProperty(JSFlashBridgeRegistry, 'addInstance', { writable: false, configurable: false, value: function value(id, instance) { instances.add(id, instance); } }); Object.defineProperty(JSFlashBridgeRegistry, 'getInstanceByID', { writable: false, configurable: false, value: function value(id) { return instances.get(id); } }); Object.defineProperty(JSFlashBridgeRegistry, 'removeInstanceByID', { writable: false, configurable: false, value: function value(id) { return instances.remove(id); } }); module.exports = JSFlashBridgeRegistry; },{"./registry":6}],6:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var MultipleValuesRegistry = exports.MultipleValuesRegistry = function () { function MultipleValuesRegistry() { _classCallCheck(this, MultipleValuesRegistry); this._registries = {}; } _createClass(MultipleValuesRegistry, [{ key: 'add', value: function add(id, value) { if (!this._registries[id]) { this._registries[id] = []; } if (this._registries[id].indexOf(value) === -1) { this._registries[id].push(value); } } }, { key: 'get', value: function get(id) { return this._registries[id] || []; } }, { key: 'filterKeys', value: function filterKeys(handler) { return Object.keys(this._registries).filter(handler); } }, { key: 'findByValue', value: function findByValue(value) { var _this = this; var keys = Object.keys(this._registries).filter(function (key) { return _this._registries[key].indexOf(value) !== -1; }); return keys; } }, { key: 'remove', value: function remove(key, value) { if (!this._registries[key]) { return; } var index = this._registries[key].indexOf(value); if (index < 0) { return; } return this._registries[key].splice(index, 1); } }, { key: 'removeByKey', value: function removeByKey(id) { var old = this._registries[id]; delete this._registries[id]; return old; } }, { key: 'removeByValue', value: function removeByValue(value) { var _this2 = this; var keys = this.findByValue(value); return keys.map(function (key) { return _this2.remove(key, value); }); } }, { key: 'removeAll', value: function removeAll() { var old = this._registries; this._registries = {}; return old; } }, { key: 'size', value: function size() { return Object.keys(this._registries).length; } }]); return MultipleValuesRegistry; }(); var SingleValueRegistry = exports.SingleValueRegistry = function () { function SingleValueRegistry() { _classCallCheck(this, SingleValueRegistry); this._registries = {}; } _createClass(SingleValueRegistry, [{ key: 'add', value: function add(id, value) { this._registries[id] = value; } }, { key: 'get', value: function get(id) { return this._registries[id]; } }, { key: 'filterKeys', value: function filterKeys(handler) { return Object.keys(this._registries).filter(handler); } }, { key: 'findByValue', value: function findByValue(value) { var _this3 = this; var keys = Object.keys(this._registries).filter(function (key) { return _this3._registries[key] === value; }); return keys; } }, { key: 'remove', value: function remove(id) { var old = this._registries[id]; delete this._registries[id]; return old; } }, { key: 'removeByValue', value: function removeByValue(value) { var _this4 = this; var keys = this.findByValue(value); return keys.map(function (key) { return _this4.remove(key); }); } }, { key: 'removeAll', value: function removeAll() { var old = this._registries; this._registries = {}; return old; } }, { key: 'size', value: function size() { return Object.keys(this._registries).length; } }]); return SingleValueRegistry; }(); },{}],7:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.unique = unique; exports.noop = noop; exports.callbackTimeout = callbackTimeout; exports.createElementWithID = createElementWithID; exports.isPositiveInt = isPositiveInt; exports.stringEndsWith = stringEndsWith; function unique(prefix) { var count = -1; return function (f) { return prefix + '_' + ++count; }; } function noop() {} function callbackTimeout(timer, onSuccess, onTimeout) { var timeout = setTimeout(function () { onSuccess = noop; onTimeout(); }, timer); return function () { clearTimeout(timeout); onSuccess.apply(this, arguments); }; } function createElementWithID(parent, id) { var nEl = document.createElement('div'); nEl.id = id; parent.innerHTML = ''; parent.appendChild(nEl); return nEl; } function isPositiveInt(newVal, oldVal) { return !isNaN(parseFloat(newVal)) && isFinite(newVal) && newVal > 0 ? newVal : oldVal; } var endsWith = function () { if (String.prototype.endsWith) return String.prototype.endsWith; return function endsWith(searchString, position) { var subjectString = this.toString(); if (position === undefined || position > subjectString.length) { position = subjectString.length; } position -= searchString.length; var lastIndex = subjectString.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; }(); function stringEndsWith(string, search) { return endsWith.call(string, search); } },{}],8:[function(require,module,exports){ 'use strict'; var METHODS = [ 'handshakeVersion', 'initAd', 'startAd', 'stopAd', 'skipAd', // VPAID 2.0 new method 'resizeAd', 'pauseAd', 'resumeAd', 'expandAd', 'collapseAd', 'subscribe', 'unsubscribe' ]; var EVENTS = [ 'AdLoaded', 'AdStarted', 'AdStopped', 'AdSkipped', 'AdSkippableStateChange', // VPAID 2.0 new event 'AdSizeChange', // VPAID 2.0 new event 'AdLinearChange', 'AdDurationChange', // VPAID 2.0 new event 'AdExpandedChange', 'AdRemainingTimeChange', // [Deprecated in 2.0] but will be still fired for backwards compatibility 'AdVolumeChange', 'AdImpression', 'AdVideoStart', 'AdVideoFirstQuartile', 'AdVideoMidpoint', 'AdVideoThirdQuartile', 'AdVideoComplete', 'AdClickThru', 'AdInteraction', // VPAID 2.0 new event 'AdUserAcceptInvitation', 'AdUserMinimize', 'AdUserClose', 'AdPaused', 'AdPlaying', 'AdLog', 'AdError' ]; var GETTERS = [ 'getAdLinear', 'getAdWidth', // VPAID 2.0 new getter 'getAdHeight', // VPAID 2.0 new getter 'getAdExpanded', 'getAdSkippableState', // VPAID 2.0 new getter 'getAdRemainingTime', 'getAdDuration', // VPAID 2.0 new getter 'getAdVolume', 'getAdCompanions', // VPAID 2.0 new getter 'getAdIcons' // VPAID 2.0 new getter ]; var SETTERS = [ 'setAdVolume' ]; /** * This callback is displayed as global member. The callback use nodejs error-first callback style * @callback NodeStyleCallback * @param {string|null} * @param {undefined|object} */ /** * IVPAIDAdUnit * * @class * * @param {object} creative * @param {HTMLElement} el * @param {HTMLVideoElement} video */ function IVPAIDAdUnit(creative, el, video) {} /** * handshakeVersion * * @param {string} VPAIDVersion * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.handshakeVersion = function (VPAIDVersion, callback) {}; /** * initAd * * @param {number} width * @param {number} height * @param {string} viewMode can be 'normal', 'thumbnail' or 'fullscreen' * @param {number} desiredBitrate indicates the desired bitrate in kbps * @param {object} [creativeData] used for additional initialization data * @param {object} [environmentVars] used for passing implementation-specific of js version * @param {NodeStyleCallback} callback */ IVPAIDAdUnit.prototype.initAd = function(width, height, viewMode, desiredBitrate, creativeData, environmentVars, callback) {}; /** * startAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.startAd = function(callback) {}; /** * stopAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.stopAd = function(callback) {}; /** * skipAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.skipAd = function(callback) {}; /** * resizeAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.resizeAd = function(width, height, viewMode, callback) {}; /** * pauseAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.pauseAd = function(callback) {}; /** * resumeAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.resumeAd = function(callback) {}; /** * expandAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.expandAd = function(callback) {}; /** * collapseAd * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.collapseAd = function(callback) {}; /** * subscribe * * @param {string} event * @param {nodeStyleCallback} handler * @param {object} context */ IVPAIDAdUnit.prototype.subscribe = function(event, handler, context) {}; /** * startAd * * @param {string} event * @param {function} handler */ IVPAIDAdUnit.prototype.unsubscribe = function(event, handler) {}; /** * getAdLinear * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdLinear = function(callback) {}; /** * getAdWidth * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdWidth = function(callback) {}; /** * getAdHeight * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdHeight = function(callback) {}; /** * getAdExpanded * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdExpanded = function(callback) {}; /** * getAdSkippableState * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdSkippableState = function(callback) {}; /** * getAdRemainingTime * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdRemainingTime = function(callback) {}; /** * getAdDuration * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdDuration = function(callback) {}; /** * getAdVolume * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdVolume = function(callback) {}; /** * getAdCompanions * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdCompanions = function(callback) {}; /** * getAdIcons * * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.getAdIcons = function(callback) {}; /** * setAdVolume * * @param {number} volume * @param {nodeStyleCallback} callback */ IVPAIDAdUnit.prototype.setAdVolume = function(volume, callback) {}; addStaticToInterface(IVPAIDAdUnit, 'METHODS', METHODS); addStaticToInterface(IVPAIDAdUnit, 'GETTERS', GETTERS); addStaticToInterface(IVPAIDAdUnit, 'SETTERS', SETTERS); addStaticToInterface(IVPAIDAdUnit, 'EVENTS', EVENTS); var VPAID1_METHODS = METHODS.filter(function(method) { return ['skipAd'].indexOf(method) === -1; }); addStaticToInterface(IVPAIDAdUnit, 'checkVPAIDInterface', function checkVPAIDInterface (creative) { var result = VPAID1_METHODS.every(function(key) { return typeof creative[key] === 'function'; }); return result; }); module.exports = IVPAIDAdUnit; function addStaticToInterface(Interface, name, value) { Object.defineProperty(Interface, name, { writable: false, configurable: false, value: value }); } },{}],9:[function(require,module,exports){ 'use strict'; var IVPAIDAdUnit = require('./IVPAIDAdUnit'); var Subscriber = require('./subscriber'); var checkVPAIDInterface = IVPAIDAdUnit.checkVPAIDInterface; var utils = require('./utils'); var METHODS = IVPAIDAdUnit.METHODS; var ERROR = 'AdError'; var AD_CLICK = 'AdClickThru'; var FILTERED_EVENTS = IVPAIDAdUnit.EVENTS.filter(function (event) { return event != AD_CLICK; }); /** * This callback is displayed as global member. The callback use nodejs error-first callback style * @callback NodeStyleCallback * @param {string|null} * @param {undefined|object} */ /** * VPAIDAdUnit * @class * * @param VPAIDCreative * @param {HTMLElement} [el] this will be used in initAd environmentVars.slot if defined * @param {HTMLVideoElement} [video] this will be used in initAd environmentVars.videoSlot if defined */ function VPAIDAdUnit(VPAIDCreative, el, video, iframe) { this._isValid = checkVPAIDInterface(VPAIDCreative); if (this._isValid) { this._creative = VPAIDCreative; this._el = el; this._videoEl = video; this._iframe = iframe; this._subscribers = new Subscriber(); $addEventsSubscribers.call(this); } } VPAIDAdUnit.prototype = Object.create(IVPAIDAdUnit.prototype); /** * isValidVPAIDAd will return if the VPAIDCreative passed in constructor is valid or not * * @return {boolean} */ VPAIDAdUnit.prototype.isValidVPAIDAd = function isValidVPAIDAd() { return this._isValid; }; IVPAIDAdUnit.METHODS.forEach(function(method) { //NOTE: this methods arguments order are implemented differently from the spec var ignores = [ 'subscribe', 'unsubscribe', 'initAd' ]; if (ignores.indexOf(method) !== -1) return; VPAIDAdUnit.prototype[method] = function () { var ariaty = IVPAIDAdUnit.prototype[method].length; // TODO avoid leaking arguments // https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments var args = Array.prototype.slice.call(arguments); var callback = (ariaty === args.length) ? args.pop() : undefined; setTimeout(function () { var result, error = null; try { result = this._creative[method].apply(this._creative, args); } catch(e) { error = e; } callOrTriggerEvent(callback, this._subscribers, error, result); }.bind(this), 0); }; }); /** * initAd concreate implementation * * @param {number} width * @param {number} height * @param {string} viewMode can be 'normal', 'thumbnail' or 'fullscreen' * @param {number} desiredBitrate indicates the desired bitrate in kbps * @param {object} [creativeData] used for additional initialization data * @param {object} [environmentVars] used for passing implementation-specific of js version, if el & video was used in constructor slot & videoSlot will be added to the object * @param {NodeStyleCallback} callback */ VPAIDAdUnit.prototype.initAd = function initAd(width, height, viewMode, desiredBitrate, creativeData, environmentVars, callback) { creativeData = creativeData || {}; environmentVars = utils.extend({ slot: this._el, videoSlot: this._videoEl }, environmentVars || {}); setTimeout(function () { var error; try { this._creative.initAd(width, height, viewMode, desiredBitrate, creativeData, environmentVars); } catch (e) { error = e; } callOrTriggerEvent(callback, this._subscribers, error); }.bind(this), 0); }; /** * subscribe * * @param {string} event * @param {nodeStyleCallback} handler * @param {object} context */ VPAIDAdUnit.prototype.subscribe = function subscribe(event, handler, context) { this._subscribers.subscribe(handler, event, context); }; /** * unsubscribe * * @param {string} event * @param {nodeStyleCallback} handler */ VPAIDAdUnit.prototype.unsubscribe = function unsubscribe(event, handler) { this._subscribers.unsubscribe(handler, event); }; //alias VPAIDAdUnit.prototype.on = VPAIDAdUnit.prototype.subscribe; VPAIDAdUnit.prototype.off = VPAIDAdUnit.prototype.unsubscribe; IVPAIDAdUnit.GETTERS.forEach(function(getter) { VPAIDAdUnit.prototype[getter] = function (callback) { setTimeout(function () { var result, error = null; try { result = this._creative[getter](); } catch(e) { error = e; } callOrTriggerEvent(callback, this._subscribers, error, result); }.bind(this), 0); }; }); /** * setAdVolume * * @param volume * @param {nodeStyleCallback} callback */ VPAIDAdUnit.prototype.setAdVolume = function setAdVolume(volume, callback) { setTimeout(function () { var result, error = null; try { this._creative.setAdVolume(volume); result = this._creative.getAdVolume(); } catch(e) { error = e; } if (!error) { error = utils.validate(result === volume, 'failed to apply volume: ' + volume); } callOrTriggerEvent(callback, this._subscribers, error, result); }.bind(this), 0); }; VPAIDAdUnit.prototype._destroy = function destroy() { this.stopAd(); this._subscribers.unsubscribeAll(); }; function $a