├── .babelrc ├── .gitignore ├── 38861cba61c66739c1452c3a71e39852.ttf ├── LICENSE ├── README.md ├── _config.yml ├── clappr-1142-20161018.js ├── demo ├── autoplay_ad.html ├── connect_reconnect.html ├── cvap.html ├── cvap2.html ├── demo_for_real_vast.html ├── demo_player.old.html ├── demo_player_pauseroll.html ├── demo_player_preroll.html ├── just_player.html └── test.txt ├── dist ├── 38861cba61c66739c1452c3a71e39852.ttf ├── clappr-ad-plugin.old.js ├── clappr-vast-ad-plugin.js ├── clappr.js ├── clappr.min.cdnvideo.repo.js ├── clappr_ad_plugin.js ├── cvap.js ├── cvap2.js ├── cvap_full.js ├── cvapg.js └── vast-client.js ├── gulpfile.js ├── package.json ├── src ├── clappr-ad-plugin.old.js ├── clappr-vast-ad-plugin.js ├── cvap.js ├── cvap2.js ├── cvap_full.js ├── vast-client.js ├── vast-example.xml └── vast_real.xml └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015" 4 | ], 5 | "minified": true, 6 | "comments": false 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .idea/ 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /38861cba61c66739c1452c3a71e39852.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/va-an/clappr-vast-ad-plugin/df2c551f31de40b7e3e021961096ebf8043a07b5/38861cba61c66739c1452c3a71e39852.ttf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Attention! All gnomes gone out of here. 2 | Unfortunately I no longer develop and support this repository. 3 | 4 | # clappr-vast-ad-plugin 5 | Plugin for Clappr for playing advertisements by VAST (preroll and pauseroll). 6 | 7 | 8 | # About 9 | This work was started independently from https://github.com/kslimani/clappr-html5-preroll-skeleton-plugin repo and maybe repeat main things from there. 10 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-midnight -------------------------------------------------------------------------------- /demo/autoplay_ad.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | cvap demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 26 | 27 | -------------------------------------------------------------------------------- /demo/connect_reconnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | HTMLplayer 4 | 5 | 6 |
7 |
8 | 37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /demo/cvap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | cvap demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 40 | 41 | -------------------------------------------------------------------------------- /demo/cvap2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /demo/demo_for_real_vast.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | real demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 74 | 75 | -------------------------------------------------------------------------------- /demo/demo_player.old.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | preroll test 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 44 | 45 | -------------------------------------------------------------------------------- /demo/demo_player_pauseroll.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | pauseroll demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 45 | 46 | -------------------------------------------------------------------------------- /demo/demo_player_preroll.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | preroll demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 45 | 46 | -------------------------------------------------------------------------------- /demo/just_player.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /demo/test.txt: -------------------------------------------------------------------------------- 1 | https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html 2 | https://bugs.chromium.org/p/chromium/issues/detail?id=159336 3 | https://github.com/clappr/clappr/issues/404 4 | http://stackoverflow.com/questions/27018923/video-js-autoclick-on-play-button-to-get-around-ios-autoplay-limitation 5 | http://stackoverflow.com/questions/22916828/autoplay-attribute-for-html-5-in-android-devieces 6 | http://stackoverflow.com/questions/9075520/how-to-autoplay-html5-mp4-video-on-android 7 | http://stackoverflow.com/questions/16058719/how-can-i-auto-play-the-video-using-jwplayer-in-ipad-the-code-above 8 | -------------------------------------------------------------------------------- /dist/38861cba61c66739c1452c3a71e39852.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/va-an/clappr-vast-ad-plugin/df2c551f31de40b7e3e021961096ebf8043a07b5/dist/38861cba61c66739c1452c3a71e39852.ttf -------------------------------------------------------------------------------- /dist/clappr-ad-plugin.old.js: -------------------------------------------------------------------------------- 1 | 'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){vastTracker.complete();adObject.wasCompleted=true;adPlugin.skipAd(plr,plst)}});plr.on(Clappr.Events.PLAYER_PLAY,function(){plr.core.mediaControl.container.settings.seekEnabled=plst.length<=0;if(plr.getCurrentTime()<=1){vastTracker.setProgress(1);adObject.wasStarted=true}})}},{key:'adButtonTimer',value:function adButtonTimer(s){var self=this;var timerId=setInterval(function(){self.ab.textContent='You can skip this ad in '+parseInt(s-plr.getCurrentTime());if(plr.getCurrentTime()>s){clearInterval(timerId);self.adSkipButtonEvent();self.ab.textContent='Skip Ad';console.log('time to skip ad!')}},300)}},{key:'adSkipButtonEvent',value:function adSkipButtonEvent(){var self=this;this.ab.onclick=function(){console.log('ab onclick');adPlugin.skipAd(self.player,self.playlist)}}}],[{key:'skipAd',value:function skipAd(p,playlist){var playlistItem=playlist.shift();adVideoPlayNow=playlistItem.ad;p.load(playlistItem.source,'',true);var ab=document.getElementById('adButton');ab.parentNode.removeChild(ab);if(!adObject.wasCompleted){vastTracker.skip()}}}]);return adPlugin}();var adButton=Clappr.UIContainerPlugin.extend({name:'ad_button',initialize:function initialize(){this.render()},bindEvents:function bindEvents(){this.listenTo(this.container,Clappr.Events.CONTAINER_CLICK,this.clickToContainer);this.listenTo(this.container,Clappr.Events.CONTAINER_PLAY,this.destroyAdPlugin);this.listenTo(this.container,Clappr.Events.CONTAINER_PAUSE,this.containerPause)},containerPause:function containerPause(){vastTracker.setPaused(true)},destroyAdPlugin:function destroyAdPlugin(){if(adObject.wasStarted&&!adObject.wasCompleted){vastTracker.setPaused(false)}if(!adVideoPlayNow){this.destroy()}},clickToContainer:function clickToContainer(){window.open(adObject.clickLink).focus()},show:function show(){this.$el.show()},render:function render(){this.$el.css('font-size','20px');this.$el.css('position','absolute');this.$el.css('color','white');this.$el.css('top','70%');this.$el.css('right','0%');this.$el.css('background-color','black');this.$el.css('z-index','100500');this.$el.css('border','solid 3px #333333');this.$el.css('padding','5px');this.container.$el.append(this.$el);this.$el[0].id='adButton';this.show();return this}}); -------------------------------------------------------------------------------- /dist/clappr-vast-ad-plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict';var adVideoPlayNow=false;var p='';var playlist=[];var adObject={};var vastTracker='';var vct='';var typeVideo='';var firstStart=true;var pauseNow=false;var preroll=false;var pauseroll=false;var skipButtonPressed=false;var isFullscreen=false;var progressEventsSeconds=[];adObject.adMediaFile='';var setTypeAd=function setTypeAd(type){if(type=='preroll'){preroll=true;adVideoPlayNow=true}else if(type=='pauseroll'){pauseroll=true;adVideoPlayNow=false}};var setVideoType=function setVideoType(type){typeVideo=type};var getSource=function getSource(type){if(type=='video'){var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=playlist[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var z=_step.value;if(!z.ad){return z}}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}}else if(type=='ad'){var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=playlist[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){var _z=_step2.value;if(_z.ad){return _z}}}catch(err){_didIteratorError2=true;_iteratorError2=err}finally{try{if(!_iteratorNormalCompletion2&&_iterator2.return){_iterator2.return()}}finally{if(_didIteratorError2){throw _iteratorError2}}}}else if(type==null){if(preroll){return getSource('ad')}else if(pauseroll){return getSource('video')}}};var fsEventOn=function fsEventOn(){p.on(Clappr.Events.PLAYER_FULLSCREEN,function(){isFullscreen=!isFullscreen;if(adVideoPlayNow){vastTracker.setFullscreen(isFullscreen);vastTracker.setExpand(isFullscreen)}})};var loadVAST=function loadVAST(urlVast,video){return new Promise(function(resolve,rejected){DMVAST.client.get(urlVast,function(r,e){if(!r){rejected('Error loading VAST - WTF \xAF\\_(\u30C4)_/\xAF')}console.log(r);if(!r.ads[0].creatives[0].trackingEvents['skip']&&r.ads[0].creatives[0].trackingEvents['close']){r.ads[0].creatives[0].trackingEvents['skip']=r.ads[0].creatives[0].trackingEvents['close'];delete r.ads[0].creatives[0].trackingEvents['close']}adObject.adMediaFile=r.ads[0].creatives[0].mediaFiles[0].fileURL;adObject.clickLink=r.ads[0].creatives[0].videoClickThroughURLTemplate;vastTracker=new DMVAST.tracker(r.ads[0],r.ads[0].creatives[0]);var currentDate=function currentDate(){var d=new Date;return'('+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds()+') '};vastTracker.emitAlwaysEvents.push('expand');vastTracker.emitAlwaysEvents.push('collapse');vastTracker.setExpand=function(fullscreen){console.log(currentDate()+' Ad event: '+(fullscreen?'expand':'collapse'));this.track(fullscreen?'expand':'collapse')};vastTracker.on('start',function(){return console.log(currentDate()+' Ad event: start')});vastTracker.on('skip',function(){return console.log(currentDate()+' Ad event: skip')});vastTracker.on('pause',function(){return console.log(currentDate()+' Ad event: pause')});vastTracker.on('resume',function(){return console.log(currentDate()+' Ad event: resume')});vastTracker.on('complete',function(){return console.log(currentDate()+' Ad event: complete')});vastTracker.on('firstQuartile',function(){return console.log(currentDate()+' Ad event: firstQuartile')});vastTracker.on('midpoint',function(){return console.log(currentDate()+' Ad event: midpoint')});vastTracker.on('thirdQuartile',function(){return console.log(currentDate()+' Ad event: thirdQuartile')});vastTracker.on('mute',function(){return console.log(currentDate()+' Ad event: mute')});vastTracker.on('unmute',function(){return console.log(currentDate()+' Ad event: unmute')});vastTracker.on('fullscreen',function(){return console.log(currentDate()+' Ad event: fullscreen')});vastTracker.on('exitFullscreen',function(){return console.log(currentDate()+' Ad event: exitFullscreen')});vastTracker.on('clickthrough',function(url){return console.log(currentDate()+' Ad event: click')});vastTracker.on('creativeView',function(){console.log(currentDate()+' Ad event: impression');console.log(currentDate()+' Ad event: creativeView')});for(var k in vastTracker.trackingEvents){var re=/progress-\d*/;if(!k.search(re)){progressEventsSeconds.push(parseInt(k.split('-')[1]))}}var setSkipDelay=function setSkipDelay(sd){if(!sd||sd>=r.ads[0].creatives[0].duration||sd<0){adObject.skipDelay=r.ads[0].creatives[0].duration/2}else{adObject.skipDelay=sd}};var st2f=false;var customURLs=[];for(var w in r.ads[0].extensions){if(r.ads[0].extensions[w].attributes.type.toLowerCase()=='skiptime2'&&!st2f){var prsDrExtnsn=function prsDrExtnsn(durationString){var durationComponents=void 0,minutes=void 0,seconds=void 0,secondsAndMS=void 0;if(!(durationString!=null)){return null}durationComponents=durationString.split(':');if(durationComponents.length!==2){return null}secondsAndMS=durationComponents[1].split('.');seconds=parseInt(secondsAndMS[0]);if(secondsAndMS.length===2){seconds+=parseFloat('0.'+secondsAndMS[1])}minutes=parseInt(durationComponents[0]*60);if(isNaN(minutes||isNaN(seconds||minutes>60*60||seconds>60))){return null}return minutes+seconds};setSkipDelay(prsDrExtnsn(r.ads[0].extensions[w].children[0].value));st2f=true}else if(r.ads[0].extensions[w].attributes.type.toLowerCase()=='customtracking'){for(var z in r.ads[0].extensions[w].children){customURLs.push(r.ads[0].extensions[w].children[z].value)}console.log(currentDate()+' Ad event: CustomTracking');vastTracker.trackURLs(customURLs)}}if(!st2f){setSkipDelay(r.ads[0].creatives[0].skipDelay)}progressEventsSeconds.sort(function(a,b){return a-b});playlist=[{source:adObject.adMediaFile,ad:true},{source:video,ad:false,typeVideo:typeVideo}];if(r.ads[0].creatives[0].mediaFiles[0].apiFramework=='VPAID'){rejected('Error loading VAST - VPAID not supported')}resolve()})})};var _visibilityAPI=function(){var stateKey,eventKey,keys={hidden:'visibilitychange',webkitHidden:'webkitvisibilitychange',mozHidden:'mozvisibilitychange',msHidden:'msvisibilitychange'};for(stateKey in keys){if(stateKey in document){eventKey=keys[stateKey];break}}return{'setHandler':function setHandler(c){if(c)document.addEventListener(eventKey,c)},'tabVisible':function tabVisible(){return!document[stateKey]}}}();_visibilityAPI.setHandler(function(){if(adVideoPlayNow){if(_visibilityAPI.tabVisible()){setTimeout(function(){p.play()},300)}else{p.pause()}}});var adPlugin=Clappr.UIContainerPlugin.extend({name:'ad_plugin',AdMuted:false,videoWasCompleted:false,initialize:function initialize(){this.render();this.checkAdTime()},bindEvents:function bindEvents(){this.listenTo(this.container,Clappr.Events.CONTAINER_CLICK,this.ContainerClick);this.listenTo(this.container,Clappr.Events.CONTAINER_PLAY,this.containerPlay);this.listenTo(this.container,Clappr.Events.CONTAINER_ENDED,this.containerEnded);this.listenTo(this.container,Clappr.Events.CONTAINER_PAUSE,this.containerPause);this.listenTo(this.container,Clappr.Events.CONTAINER_VOLUME,this.containerVolume)},containerVolume:function containerVolume(){if(adVideoPlayNow&&p){if(p.getVolume()==0&&!this.AdMuted){vastTracker.setMuted(true);this.AdMuted=true}else if(p.getVolume()!=0&&this.AdMuted){vastTracker.setMuted(false);this.AdMuted=false}}},checkAdTime:function checkAdTime(){if(adVideoPlayNow){(function(){var fq=false,mp=false,tq=false;var timerId=setInterval(function(){if(skipButtonPressed){clearInterval(timerId)}else{if(progressEventsSeconds.length&&p.getCurrentTime()>=progressEventsSeconds[0]){vastTracker.setProgress(progressEventsSeconds.shift())}if(p.getCurrentTime()>=p.getDuration()*0.25&&!fq){vastTracker.setProgress(p.getCurrentTime());fq=true}else if(p.getCurrentTime()>=p.getDuration()*0.5&&!mp){vastTracker.setProgress(p.getCurrentTime());mp=true}else if(p.getCurrentTime()>=p.getDuration()*0.75&&!tq){vastTracker.setProgress(p.getCurrentTime());tq=true;clearInterval(timerId)}}},300)})()}},initPlayerFor:function initPlayerFor(type){if(type=='video'){adVideoPlayNow=false;pauseNow=false;p.load(getSource('video').source);if(getSource('video').typeVideo=='vod'){p.seek(vct)}}else if(type=='ad'){adVideoPlayNow=true;p.load(getSource('ad').source);p.setVolume(100);skipButtonPressed=false}},containerPlay:function containerPlay(){var self=this;p.core.mediaControl.container.settings.seekEnabled=!adVideoPlayNow;if(adVideoPlayNow){if(isFullscreen){vastTracker.setFullscreen(true);vastTracker.setExpand(true)}}if(preroll){if(adVideoPlayNow){if(firstStart){p.setVolume(100);vastTracker.setDuration(p.getDuration());vastTracker.load();vastTracker.setProgress(0.1);firstStart=false}else{vastTracker.setPaused(false)}}if(this.videoWasCompleted){this.videoWasCompleted=false;loadVAST(vastUrl,mainVideo).then(function(){return self.initPlayerFor('ad')})}}else if(pauseroll){if(adVideoPlayNow)if(p.getCurrentTime()==0){vastTracker.setDuration(p.getDuration());vastTracker.load();vastTracker.setProgress(0.1)}else{vastTracker.setPaused(false)}if(!adVideoPlayNow&&!firstStart&&pauseNow&&p.getCurrentTime()!=0){if(getSource('video').typeVideo=='vod'){vct=p.getCurrentTime()}loadVAST(vastUrl,mainVideo).then(function(){return self.initPlayerFor('ad')})}pauseNow=false;adVideoPlayNow=p.options.sources[0]!=getSource('video').source;if(adVideoPlayNow){this.show()}else{this.hide()}}},containerEnded:function containerEnded(){var self=this;if(adVideoPlayNow){vastTracker.complete();this.initPlayerFor('video')}else if(!adVideoPlayNow&&preroll){self.videoWasCompleted=true;firstStart=true}},containerPause:function containerPause(){if(adVideoPlayNow&&!p.ended){vastTracker.setPaused(true)}if(preroll){}else if(pauseroll){firstStart=false;pauseNow=true}},ContainerClick:function ContainerClick(){if(adVideoPlayNow){window.open(adObject.clickLink).focus();vastTracker.click()}else if(!adVideoPlayNow&&pauseroll&&getSource('video').typeVideo=='live'){p.pause()}},show:function show(){var _this=this;var showAdButton=function showAdButton(){_this.$el.show();var timerId=setInterval(function(){var ab=document.getElementById('adButton');ab.textContent='You can skip this ad in '+parseInt(adObject.skipDelay-p.getCurrentTime());if(p.getCurrentTime()>adObject.skipDelay){clearInterval(timerId);ab.onclick=function(){skipButtonPressed=true;vastTracker.skip();_this.initPlayerFor('video')};ab.textContent='Skip Ad'}},300)};if(preroll){if(adVideoPlayNow){showAdButton()}else{this.hide()}}else if(pauseroll){showAdButton()}},hide:function hide(){console.log('hide called');this.$el.hide()},render:function render(){this.$el.css('font-size','20px');this.$el.css('position','absolute');this.$el.css('color','white');this.$el.css('top','70%');this.$el.css('right','0%');this.$el.css('background-color','black');this.$el.css('z-index','100500');this.$el.css('border','solid 3px #333333');this.$el.css('padding','5px');this.container.$el.append(this.$el);this.$el[0].id='adButton';if(preroll){this.show()}else if(pauseroll){if(adVideoPlayNow){this.show()}else{this.hide()}}return this}}); -------------------------------------------------------------------------------- /dist/clappr_ad_plugin.js: -------------------------------------------------------------------------------- 1 | var adPlugin=function(n){function r(t){if(o[t])return o[t].exports;var e=o[t]={exports:{},id:t,loaded:!1};return n[t].call(e.exports,e,e.exports,r),e.loaded=!0,e.exports}var o={};return r.m=n,r.c=o,r.p="",r(0)}([function(n,r,o){!function(){throw new Error('Cannot find module "./src/vastPlugin"')}(),function(){throw new Error('Cannot find module "./src/adPlugin"')}()}]); -------------------------------------------------------------------------------- /dist/cvap.js: -------------------------------------------------------------------------------- 1 | 'use strict';var adVideoPlayNow=false;var p='';var playlist=[];var adObject={};var typeVideo='';var preroll=false;var pauseroll=false;var isFullscreen=false;var pauseNow=false;var firstStart=true;var vastTracker='';var progressEventsSeconds=[];var customURLs=[];var skipButtonPressed=false;var adFirstStart='';var vct='';adObject.adMediaFile='';var cnfPlrAd=function cnfPlrAd(){player.source=getSource().source;player.plugins?player.plugins.push(adPlugin):player.plugins=[adPlugin];p=new Clappr.Player(player);fsEventOn()};var cnfPlr=function cnfPlr(){if(preroll){loadVAST(vastUrl,mainVideo).then(function(){cnfPlrAd()},function(msg){player.source=getSource('video').source;p=new Clappr.Player(player);console.log(msg)})}else if(pauseroll){cnfPlrAd()}};var _visibilityAPI=function(){var stateKey,eventKey,keys={hidden:'visibilitychange',webkitHidden:'webkitvisibilitychange',mozHidden:'mozvisibilitychange',msHidden:'msvisibilitychange'};for(stateKey in keys){if(stateKey in document){eventKey=keys[stateKey];break}}return{'setHandler':function setHandler(c){if(c)document.addEventListener(eventKey,c)},'tabVisible':function tabVisible(){return!document[stateKey]}}}();_visibilityAPI.setHandler(function(){if(adVideoPlayNow){if(_visibilityAPI.tabVisible()){setTimeout(function(){p.play()},300)}else{p.pause()}}});var currentDate=function currentDate(){var d=new Date;return'('+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds()+') '};var getSource=function getSource(type){if(type=='video'){var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=playlist[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var z=_step.value;if(!z.ad){return z}}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}}else if(type=='ad'){var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=playlist[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){var _z=_step2.value;if(_z.ad){return _z}}}catch(err){_didIteratorError2=true;_iteratorError2=err}finally{try{if(!_iteratorNormalCompletion2&&_iterator2.return){_iterator2.return()}}finally{if(_didIteratorError2){throw _iteratorError2}}}}else if(type==null){if(!preroll&&!pauseroll||preroll&&pauseroll){console.log('Error - please configure type ag: setTypeAd(\'preroll\') or setTypeAd(\'pauseroll\')')}else{if(preroll){return getSource('ad')}else if(pauseroll){return getSource('video')}}}};var setTypeAd=function setTypeAd(type){if(type=='preroll'){preroll=true;adVideoPlayNow=true}else if(type=='pauseroll'){pauseroll=true;adVideoPlayNow=false}};var setVideoType=function setVideoType(type){typeVideo=type;playlist=[{source:'',ad:true},{source:mainVideo,ad:false,typeVideo:type}]};var fsEventOn=function fsEventOn(){p.on(Clappr.Events.PLAYER_FULLSCREEN,function(){isFullscreen=!isFullscreen;if(adVideoPlayNow){vastTracker.setFullscreen(isFullscreen);vastTracker.setExpand(isFullscreen)}})};var loadVAST=function loadVAST(urlVast,video){return new Promise(function(resolve,rejected){DMVAST.client.get(urlVast,function(r,e){if(!r){adVideoPlayNow?adVideoPlayNow=false:'';rejected('Error loading VAST - r is null')}console.log(r);if(!r.ads[0].creatives[0].trackingEvents['skip']&&r.ads[0].creatives[0].trackingEvents['close']){r.ads[0].creatives[0].trackingEvents['skip']=r.ads[0].creatives[0].trackingEvents['close'];delete r.ads[0].creatives[0].trackingEvents['close']}adObject.adMediaFile=r.ads[0].creatives[0].mediaFiles[0].fileURL;adObject.clickLink=r.ads[0].creatives[0].videoClickThroughURLTemplate;vastTracker=new DMVAST.tracker(r.ads[0],r.ads[0].creatives[0]);vastTracker.emitAlwaysEvents.push('expand');vastTracker.emitAlwaysEvents.push('collapse');vastTracker.setExpand=function(fullscreen){console.log(currentDate()+' Ad event: '+(fullscreen?'expand':'collapse'));this.track(fullscreen?'expand':'collapse')};vastTracker.on('start',function(){return console.log(currentDate()+' Ad event: start')});vastTracker.on('skip',function(){return console.log(currentDate()+' Ad event: skip')});vastTracker.on('pause',function(){return console.log(currentDate()+' Ad event: pause')});vastTracker.on('resume',function(){return console.log(currentDate()+' Ad event: resume')});vastTracker.on('complete',function(){return console.log(currentDate()+' Ad event: complete')});vastTracker.on('firstQuartile',function(){return console.log(currentDate()+' Ad event: firstQuartile')});vastTracker.on('midpoint',function(){return console.log(currentDate()+' Ad event: midpoint')});vastTracker.on('thirdQuartile',function(){return console.log(currentDate()+' Ad event: thirdQuartile')});vastTracker.on('mute',function(){return console.log(currentDate()+' Ad event: mute')});vastTracker.on('unmute',function(){return console.log(currentDate()+' Ad event: unmute')});vastTracker.on('fullscreen',function(){return console.log(currentDate()+' Ad event: fullscreen')});vastTracker.on('exitFullscreen',function(){return console.log(currentDate()+' Ad event: exitFullscreen')});vastTracker.on('clickthrough',function(url){return console.log(currentDate()+' Ad event: click')});vastTracker.on('creativeView',function(){console.log(currentDate()+' Ad event: impression');console.log(currentDate()+' Ad event: creativeView')});for(var k in vastTracker.trackingEvents){var re=/progress-\d*/;if(!k.search(re)){progressEventsSeconds.push(parseInt(k.split('-')[1]))}}var setSkipDelay=function setSkipDelay(sd){if(!sd||sd>=r.ads[0].creatives[0].duration||sd<0){adObject.skipDelay=r.ads[0].creatives[0].duration/2}else{adObject.skipDelay=sd}};var st2f=false;for(var w in r.ads[0].extensions){if(r.ads[0].extensions[w].attributes.type.toLowerCase()=='skiptime2'&&!st2f){var prsDrExtnsn=function prsDrExtnsn(durationString){var durationComponents=void 0,minutes=void 0,seconds=void 0,secondsAndMS=void 0;if(!(durationString!=null)){return null}durationComponents=durationString.split(':');if(durationComponents.length!==2){return null}secondsAndMS=durationComponents[1].split('.');seconds=parseInt(secondsAndMS[0]);if(secondsAndMS.length===2){seconds+=parseFloat('0.'+secondsAndMS[1])}minutes=parseInt(durationComponents[0]*60);if(isNaN(minutes||isNaN(seconds||minutes>60*60||seconds>60))){return null}return minutes+seconds};setSkipDelay(prsDrExtnsn(r.ads[0].extensions[w].children[0].value));st2f=true}else if(r.ads[0].extensions[w].attributes.type.toLowerCase()=='customtracking'){for(var z in r.ads[0].extensions[w].children){customURLs.push(r.ads[0].extensions[w].children[z].value)}}}if(!st2f){setSkipDelay(r.ads[0].creatives[0].skipDelay)}progressEventsSeconds.sort(function(a,b){return a-b});getSource('ad').source=adObject.adMediaFile;if(r.ads[0].creatives[0].mediaFiles[0].apiFramework=='VPAID'){adVideoPlayNow?adVideoPlayNow=false:'';rejected('Error loading VAST - VPAID not supported')}adFirstStart=true;resolve()})})};var adPlugin=Clappr.UIContainerPlugin.extend({name:'ad_plugin',videoWasCompleted:false,AdMuted:false,initialize:function initialize(){this.render();this.checkAdTime()},bindEvents:function bindEvents(){this.listenTo(this.container,Clappr.Events.CONTAINER_PAUSE,this.containerPause);this.listenTo(this.container,Clappr.Events.CONTAINER_PLAY,this.containerPlay);this.listenTo(this.container,Clappr.Events.CONTAINER_ENDED,this.containerEnded);this.listenTo(this.container,Clappr.Events.CONTAINER_CLICK,this.ContainerClick);this.listenTo(this.container,Clappr.Events.CONTAINER_VOLUME,this.containerVolume)},show:function show(){var _this=this;var showAdButton=function showAdButton(){_this.$el.show();var timerId=setInterval(function(){var ab=document.getElementById('adButton');ab.textContent='You can skip this ad in '+parseInt(adObject.skipDelay-p.getCurrentTime());if(p.getCurrentTime()>adObject.skipDelay){clearInterval(timerId);ab.onclick=function(){skipButtonPressed=true;vastTracker.skip();_this.initPlayerFor('video')};ab.textContent='Skip Ad'}},300)};if(preroll){if(adVideoPlayNow){showAdButton()}else{this.hide()}}else if(pauseroll){showAdButton()}},hide:function hide(){this.$el.hide()},render:function render(){this.$el.css('font-size','20px');this.$el.css('position','absolute');this.$el.css('color','white');this.$el.css('top','70%');this.$el.css('right','0%');this.$el.css('background-color','black');this.$el.css('z-index','100500');this.$el.css('border','solid 3px #333333');this.$el.css('padding','5px');this.container.$el.append(this.$el);this.$el[0].id='adButton';if(preroll){this.show()}else if(pauseroll){if(adVideoPlayNow){this.show()}else{this.hide()}}return this},containerPause:function containerPause(){if(adVideoPlayNow&&!p.ended){vastTracker.setPaused(true)}if(!adVideoPlayNow){pauseNow=true}},containerPlay:function containerPlay(){p.core.mediaControl.container.settings.seekEnabled=!adVideoPlayNow;var self=this;if(adVideoPlayNow){if(adFirstStart){vastTracker.setProgress(0.1);vastTracker.setDuration(p.getDuration());vastTracker.load();p.setVolume(100);vastTracker.trackURLs(customURLs);console.log(currentDate()+' Ad event: CustomTracking');adFirstStart=false}else{vastTracker.setPaused(false)}}if(preroll){if(this.videoWasCompleted){this.videoWasCompleted=false;loadVAST(vastUrl,mainVideo).then(function(){return self.initPlayerFor('ad')})}}else if(pauseroll){if(!adVideoPlayNow&&pauseNow&&!firstStart){pauseNow=false;if(getSource('video').typeVideo=='vod'){vct=p.getCurrentTime()}loadVAST(vastUrl,mainVideo).then(function(){return self.initPlayerFor('ad')})}}firstStart=false},containerEnded:function containerEnded(){firstStart=true;pauseNow=false;var self=this;if(adVideoPlayNow){vastTracker.complete();this.initPlayerFor('video')}else if(!adVideoPlayNow&&preroll){self.videoWasCompleted=true}},ContainerClick:function ContainerClick(){if(adVideoPlayNow){window.open(adObject.clickLink).focus();vastTracker.click()}else if(!adVideoPlayNow&&pauseroll&&getSource('video').typeVideo=='live'){p.pause()}},initPlayerFor:function initPlayerFor(type){if(type=='video'){adVideoPlayNow=false;pauseNow=false;p.load(getSource('video').source);if(getSource('video').typeVideo=='vod'){p.seek(vct)}}else if(type=='ad'){adVideoPlayNow=true;p.load(getSource('ad').source);p.setVolume(100);skipButtonPressed=false;p.play()}},checkAdTime:function checkAdTime(){if(adVideoPlayNow){(function(){var fq=false,mp=false,tq=false;var timerId=setInterval(function(){if(skipButtonPressed){clearInterval(timerId)}else{if(progressEventsSeconds.length&&p.getCurrentTime()>=progressEventsSeconds[0]){vastTracker.setProgress(progressEventsSeconds.shift());console.log(currentDate()+' Ad event: progress')}if(p.getCurrentTime()>=p.getDuration()*0.25&&!fq){vastTracker.setProgress(p.getCurrentTime());fq=true}else if(p.getCurrentTime()>=p.getDuration()*0.5&&!mp){vastTracker.setProgress(p.getCurrentTime());mp=true}else if(p.getCurrentTime()>=p.getDuration()*0.75&&!tq){vastTracker.setProgress(p.getCurrentTime());tq=true;clearInterval(timerId)}}},300)})()}},containerVolume:function containerVolume(){if(adVideoPlayNow&&p){if(p.getVolume()==0&&!this.AdMuted||p.getVolume()!=0&&this.AdMuted){this.AdMuted=!this.AdMuted;vastTracker.setMuted(this.AdMuted)}}}}); -------------------------------------------------------------------------------- /dist/cvap2.js: -------------------------------------------------------------------------------- 1 | 'use strict';var adVideoPlayNow=true;var mainVideoPlayNow=false;var preroll=true;var pauseroll=false;var sbPressed=false;var adFirstStart=true;var pauseNow=false;var progressEventsSeconds=[];var videoMainVod=false;var videoMainLive=false;var videoCurrentTime=0;var isFullscreen=false;var videoAd=void 0;var player=void 0;var skipDelay=void 0;var vastTracker=void 0;var clickLink=void 0;var myFirstPlay=true;var loadVAST=function loadVAST(url){return new Promise(function(resolve,reject){if(myFirstPlay&&pauseroll){myFirstPlay=false;resolve()}else{DMVAST.client.get(url,function(r,e){if(!r){adVideoPlayNow?adVideoPlayNow=false:'';reject('Error loading VAST - r is null')}console.log(r);if(r.ads[0].creatives[0].mediaFiles[0].apiFramework=='VPAID'){adVideoPlayNow?adVideoPlayNow=false:'';reject('Error loading VAST - VPAID not supported')}vastTracker=new DMVAST.tracker(r.ads[0],r.ads[0].creatives[0]);vastTracker.on('start',function(){return console.log(getCurrentDate()+' Ad event: start')});vastTracker.on('pause',function(){return console.log(getCurrentDate()+' Ad event: pause')});vastTracker.on('resume',function(){return console.log(getCurrentDate()+' Ad event: resume')});vastTracker.on('mute',function(){return console.log(getCurrentDate()+' Ad event: mute')});vastTracker.on('unmute',function(){return console.log(getCurrentDate()+' Ad event: unmute')});vastTracker.on('skip',function(){return console.log(getCurrentDate()+' Ad event: skip')});vastTracker.on('clickthrough',function(url){return console.log(getCurrentDate()+' Ad event: click')});vastTracker.on('complete',function(){return console.log(getCurrentDate()+' Ad event: complete')});vastTracker.on('firstQuartile',function(){return console.log(getCurrentDate()+' Ad event: firstQuartile')});vastTracker.on('midpoint',function(){return console.log(getCurrentDate()+' Ad event: midpoint')});vastTracker.on('thirdQuartile',function(){return console.log(getCurrentDate()+' Ad event: thirdQuartile')});vastTracker.on('fullscreen',function(){return console.log(getCurrentDate()+' Ad event: fullscreen')});vastTracker.on('exitFullscreen',function(){return console.log(getCurrentDate()+' Ad event: exitFullscreen')});vastTracker.on('creativeView',function(){console.log(getCurrentDate()+' Ad event: impression');console.log(getCurrentDate()+' Ad event: creativeView')});for(var k in vastTracker.trackingEvents){var re=/progress-\d*/;if(!k.search(re)){progressEventsSeconds.push(parseInt(k.split('-')[1]))}}progressEventsSeconds.sort(function(a,b){return a-b});videoAd=r.ads[0].creatives[0].mediaFiles[0].fileURL;skipDelay=r.ads[0].creatives[0].skipDelay;clickLink=r.ads[0].creatives[0].videoClickThroughURLTemplate;console.log('loadvast');resolve()})}})};var fsEventOn=function fsEventOn(){player.on(Clappr.Events.PLAYER_FULLSCREEN,function(){isFullscreen=!isFullscreen;if(adVideoPlayNow){vastTracker.setFullscreen(isFullscreen)}})};var getCurrentDate=function getCurrentDate(){var d=new Date;return'('+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds()+') '};var setTypeVideo=function setTypeVideo(type){if(type=='vod'){videoMainVod=true}else if(type=='live'){videoMainLive=true}};var getVideoSource=function getVideoSource(){if(preroll){return videoAd}else if(pauseroll){return videoMain}};var setTypeAd=function setTypeAd(type){adVideoPlayNow=false;preroll=false;pauseroll=false;if(type=='preroll'){adVideoPlayNow=true;preroll=true}else if(type=='pauseroll'){pauseroll=true}};var _visibilityAPI=function(){var stateKey,eventKey,keys={hidden:'visibilitychange',webkitHidden:'webkitvisibilitychange',mozHidden:'mozvisibilitychange',msHidden:'msvisibilitychange'};for(stateKey in keys){if(stateKey in document){eventKey=keys[stateKey];break}}return{'setHandler':function setHandler(c){if(c)document.addEventListener(eventKey,c)},'tabVisible':function tabVisible(){return!document[stateKey]}}}();_visibilityAPI.setHandler(function(){if(adVideoPlayNow){if(_visibilityAPI.tabVisible()){setTimeout(function(){player.play()},300)}else{player.pause()}}});var clapprAdVastPlugin=Clappr.UIContainerPlugin.extend({name:'clappr-vast-ad-plugin',version:'2.0',adMuted:false,videoWasComplited:false,initialize:function initialize(){this.render()},render:function render(){this.$el.css('font-size','20px');this.$el.css('position','absolute');this.$el.css('color','white');this.$el.css('top','70%');this.$el.css('right','0%');this.$el.css('background-color','black');this.$el.css('z-index','100500');this.$el.css('border','solid 3px #333333');this.$el.css('padding','5px');this.container.$el.append(this.$el);this.$el[0].id='adButton';if(preroll){this.show()}else if(pauseroll){if(adVideoPlayNow){this.show()}else{this.hide()}}return this},bindEvents:function bindEvents(){this.listenTo(this.container,Clappr.Events.CONTAINER_ENDED,this.containerEnded);this.listenTo(this.container,Clappr.Events.CONTAINER_PLAY,this.containerPlay);this.listenTo(this.container,Clappr.Events.CONTAINER_VOLUME,this.containerVolume);this.listenTo(this.container,Clappr.Events.CONTAINER_PAUSE,this.containerPause);this.listenTo(this.container,Clappr.Events.CONTAINER_CLICK,this.containerClick)},containerClick:function containerClick(){if(adVideoPlayNow){window.open(clickLink).focus();vastTracker.click()}else{player.pause()}},containerPause:function containerPause(){if(adVideoPlayNow&&!player.ended){vastTracker.setPaused(true)}else{player.pause();pauseNow=true}},containerVolume:function containerVolume(){if(adVideoPlayNow&&player){if(player.getVolume()==0&&!this.AdMuted||player.getVolume()!=0&&this.AdMuted){this.AdMuted=!this.AdMuted;vastTracker.setMuted(this.AdMuted)}}},containerPlay:function containerPlay(){var _this=this;mainVideoPlayNow?this.hide():null;player.core.mediaControl.container.settings.seekEnabled=!adVideoPlayNow;if(adVideoPlayNow){this.checkAdTime();this.show();if(adFirstStart){vastTracker.setProgress(0.1);vastTracker.load();adFirstStart=false}else{vastTracker.setPaused(false)}}else{this.hide()}if(preroll){if(this.videoWasComplited){this.videoWasComplited=false;loadVAST(vastUrl).then(function(){return _this.switchSource('va')});adVideoPlayNow=true;adFirstStart=true}}else if(pauseroll){if(!adVideoPlayNow&&pauseNow&&player.isPlaying()){pauseNow=false;if(videoMainVod){videoCurrentTime=player.getCurrentTime()}adFirstStart=true;loadVAST(vastUrl).then(function(){return _this.switchSource('va')});this.show()}}},containerEnded:function containerEnded(){pauseNow=false;if(adVideoPlayNow){vastTracker.complete();this.switchSource('av')}else if(preroll){this.videoWasComplited=true}},switchSource:function switchSource(type){if(player!=null){var f=void 0,s=void 0;if(type=='av'){adVideoPlayNow=false;f=videoAd;s=videoMain}else if(type=='va'){adVideoPlayNow=true;f=videoMain;s=videoAd}var el=player.core.getCurrentPlayback().el;el.src=s;!sbPressed?el.play():null;if(type=='av'&&videoMainVod){player.seek(videoCurrentTime)}}},show:function show(){var _this2=this;var showAdButton=function showAdButton(){_this2.$el.show();var timerId=setInterval(function(){var ab=document.getElementById('adButton');ab.textContent='You can skip this ad in '+parseInt(skipDelay-player.getCurrentTime());if(player.getCurrentTime()>skipDelay){clearInterval(timerId);ab.onclick=function(){vastTracker.skip();sbPressed=true;_this2.switchSource('av');sbPressed=false};ab.textContent='Skip Ad'}},300)};if(preroll){if(adVideoPlayNow){showAdButton()}else{this.hide()}}else if(pauseroll){showAdButton()}},hide:function hide(){this.$el.hide()},checkAdTime:function checkAdTime(){if(adVideoPlayNow){(function(){var fq=false,mp=false,tq=false;var timerId=setInterval(function(){if(sbPressed){clearInterval(timerId)}else{if(progressEventsSeconds.length&&player.getCurrentTime()>=progressEventsSeconds[0]){vastTracker.setProgress(progressEventsSeconds.shift());console.log(getCurrentDate()+' Ad event: progress')}if(player.getCurrentTime()>=player.getDuration()*0.25&&!fq){vastTracker.setProgress(player.getCurrentTime());fq=true}else if(player.getCurrentTime()>=player.getDuration()*0.5&&!mp){vastTracker.setProgress(player.getCurrentTime());mp=true}else if(player.getCurrentTime()>=player.getDuration()*0.75&&!tq){vastTracker.setProgress(player.getCurrentTime());tq=true;clearInterval(timerId)}}},300)})()}}}); -------------------------------------------------------------------------------- /dist/vast-client.js: -------------------------------------------------------------------------------- 1 | "use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};(function(f){if((typeof exports==="undefined"?"undefined":_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.DMVAST=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;o0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);if(typeof console.trace==="function"){console.trace()}}}return this};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throw TypeError("listener must be a function");var fired=false;function g(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);return this};EventEmitter.prototype.removeListener=function(type,listener){var list,position,length,i;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events||!this._events[type])return this;list=this._events[type];length=list.length;position=-1;if(list===listener||isFunction(list.listener)&&list.listener===listener){delete this._events[type];if(this._events.removeListener)this.emit("removeListener",type,listener)}else if(isObject(list)){for(i=length;i-->0;){if(list[i]===listener||list[i].listener&&list[i].listener===listener){position=i;break}}if(position<0)return this;if(list.length===1){list.length=0;delete this._events[type]}else{list.splice(position,1)}if(this._events.removeListener)this.emit("removeListener",type,listener)}return this};EventEmitter.prototype.removeAllListeners=function(type){var key,listeners;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[type])delete this._events[type];return this}if(arguments.length===0){for(key in this._events){if(key==="removeListener")continue;this.removeAllListeners(key)}this.removeAllListeners("removeListener");this._events={};return this}listeners=this._events[type];if(isFunction(listeners)){this.removeListener(type,listeners)}else if(listeners){while(listeners.length){this.removeListener(type,listeners[listeners.length-1])}}delete this._events[type];return this};EventEmitter.prototype.listeners=function(type){var ret;if(!this._events||!this._events[type])ret=[];else if(isFunction(this._events[type]))ret=[this._events[type]];else ret=this._events[type].slice();return ret};EventEmitter.prototype.listenerCount=function(type){if(this._events){var evlistener=this._events[type];if(isFunction(evlistener))return 1;else if(evlistener)return evlistener.length}return 0};EventEmitter.listenerCount=function(emitter,type){return emitter.listenerCount(type)};function isFunction(arg){return typeof arg==="function"}function isNumber(arg){return typeof arg==="number"}function isObject(arg){return(typeof arg==="undefined"?"undefined":_typeof(arg))==="object"&&arg!==null}function isUndefined(arg){return arg===void 0}},{}],2:[function(require,module,exports){var VASTAd;VASTAd=function(){function VASTAd(){this.id=null;this.sequence=null;this.system=null;this.title=null;this.description=null;this.advertiser=null;this.pricing=null;this.survey=null;this.errorURLTemplates=[];this.impressionURLTemplates=[];this.creatives=[];this.extensions=[]}return VASTAd}();module.exports=VASTAd},{}],3:[function(require,module,exports){var VASTClient,VASTParser,VASTUtil;VASTParser=require("./parser");VASTUtil=require("./util");VASTClient=function(){function VASTClient(){}VASTClient.cappingFreeLunch=0;VASTClient.cappingMinimumTimeInterval=0;VASTClient.options={withCredentials:false,timeout:0};VASTClient.get=function(url,opts,cb){var extend,now,options,timeSinceLastCall;now=+new Date;extend=exports.extend=function(object,properties){var key,val;for(key in properties){val=properties[key];object[key]=val}return object};if(!cb){if(typeof opts==="function"){cb=opts}options={}}options=extend(this.options,opts);if(this.totalCallsTimeout=this.totalCalls){cb(null,new Error("VAST call canceled \u2013 FreeLunch capping not reached yet "+this.totalCalls+"/"+this.cappingFreeLunch));return}timeSinceLastCall=now-this.lastSuccessfullAd;if(timeSinceLastCall<0){this.lastSuccessfullAd=0}else if(timeSinceLastCall0){noCreatives=false}}if(noCreatives){if(!errorAlreadyRaised){_this.track(response.errorURLTemplates,{ERRORCODE:303})}}if(response.ads.length===0){response=null}return cb(null,response)};loopIndex=response.ads.length;while(loopIndex--){ad=response.ads[loopIndex];if(ad.nextWrapperURL==null){continue}(function(ad){var baseURL,protocol,ref2;if(parentURLs.length>=10||(ref2=ad.nextWrapperURL,indexOf.call(parentURLs,ref2)>=0)){_this.track(ad.errorURLTemplates,{ERRORCODE:302});response.ads.splice(response.ads.indexOf(ad),1);complete();return}if(ad.nextWrapperURL.indexOf("//")===0){protocol=location.protocol;ad.nextWrapperURL=""+protocol+ad.nextWrapperURL}else if(ad.nextWrapperURL.indexOf("://")===-1){baseURL=url.slice(0,url.lastIndexOf("/"));ad.nextWrapperURL=baseURL+"/"+ad.nextWrapperURL}return _this._parse(ad.nextWrapperURL,parentURLs,options,function(err,wrappedResponse){var base,creative,errorAlreadyRaised,eventName,index,l,len3,len4,len5,len6,m,n,o,ref3,ref4,ref5,ref6,wrappedAd;errorAlreadyRaised=false;if(err!=null){_this.track(ad.errorURLTemplates,{ERRORCODE:301});response.ads.splice(response.ads.indexOf(ad),1);errorAlreadyRaised=true}else if(wrappedResponse==null){_this.track(ad.errorURLTemplates,{ERRORCODE:303});response.ads.splice(response.ads.indexOf(ad),1);errorAlreadyRaised=true}else{response.errorURLTemplates=response.errorURLTemplates.concat(wrappedResponse.errorURLTemplates);index=response.ads.indexOf(ad);response.ads.splice(index,1);ref3=wrappedResponse.ads;for(l=0,len3=ref3.length;l60*60||seconds>60)))){return-1}return hours+minutes+seconds};VASTParser.parseXPosition=function(xPosition){if(xPosition==="left"||xPosition==="right"){return xPosition}return parseInt(xPosition||0)};VASTParser.parseYPosition=function(yPosition){if(yPosition==="top"||yPosition==="bottom"){return yPosition}return parseInt(yPosition||0)};VASTParser.parseNodeText=function(node){return node&&(node.textContent||node.text||"").trim()};return VASTParser}();module.exports=VASTParser},{"./ad":2,"./companionad":4,"./creative":5,"./extension":6,"./extensionchild":7,"./icon":8,"./mediafile":10,"./nonlinear":11,"./response":13,"./urlhandler":15,"./util":18,"events":1}],13:[function(require,module,exports){var VASTResponse;VASTResponse=function(){function VASTResponse(){this.ads=[];this.errorURLTemplates=[]}return VASTResponse}();module.exports=VASTResponse},{}],14:[function(require,module,exports){var EventEmitter,VASTClient,VASTCreativeLinear,VASTTracker,VASTUtil,extend=function extend(child,parent){for(var key in parent){if(hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child},hasProp={}.hasOwnProperty;VASTClient=require("./client");VASTUtil=require("./util");VASTCreativeLinear=require("./creative").VASTCreativeLinear;EventEmitter=require("events").EventEmitter;VASTTracker=function(superClass){extend(VASTTracker,superClass);function VASTTracker(ad,creative){var eventName,events,ref;this.ad=ad;this.creative=creative;this.muted=false;this.impressed=false;this.skipable=false;this.skipDelayDefault=-1;this.trackingEvents={};this.emitAlwaysEvents=["creativeView","start","firstQuartile","midpoint","thirdQuartile","complete","resume","pause","rewind","skip","closeLinear","close"];ref=this.creative.trackingEvents;for(eventName in ref){events=ref[eventName];this.trackingEvents[eventName]=events.slice(0)}if(this.creative instanceof VASTCreativeLinear){this.setDuration(this.creative.duration);this.skipDelay=this.creative.skipDelay;this.linear=true;this.clickThroughURLTemplate=this.creative.videoClickThroughURLTemplate;this.clickTrackingURLTemplates=this.creative.videoClickTrackingURLTemplates}else{this.skipDelay=-1;this.linear=false}this.on("start",function(){VASTClient.lastSuccessfullAd=+new Date})}VASTTracker.prototype.setDuration=function(duration){this.assetDuration=duration;return this.quartiles={"firstQuartile":Math.round(25*this.assetDuration)/100,"midpoint":Math.round(50*this.assetDuration)/100,"thirdQuartile":Math.round(75*this.assetDuration)/100}};VASTTracker.prototype.setProgress=function(progress){var eventName,events,i,len,percent,quartile,ref,skipDelay,time;skipDelay=this.skipDelay===null?this.skipDelayDefault:this.skipDelay;if(skipDelay!==-1&&!this.skipable){if(skipDelay>progress){this.emit("skip-countdown",skipDelay-progress)}else{this.skipable=true;this.emit("skip-countdown",0)}}if(this.linear&&this.assetDuration>0){events=[];if(progress>0){events.push("start");percent=Math.round(progress/this.assetDuration*100);events.push("progress-"+percent+"%");events.push("progress-"+Math.round(progress));ref=this.quartiles;for(quartile in ref){time=ref[quartile];if(time<=progress&&progress<=time+1){events.push(quartile)}}}for(i=0,len=events.length;i-1){this.emitAlwaysEvents.splice(idx,1)}}};VASTTracker.prototype.trackURLs=function(URLTemplates,variables){if(variables==null){variables={}}if(this.linear){variables["CONTENTPLAYHEAD"]=this.progressFormated()}return VASTUtil.track(URLTemplates,variables)};VASTTracker.prototype.progressFormated=function(){var h,m,ms,s,seconds;seconds=parseInt(this.progress);h=seconds/(60*60);if(h.length<2){h="0"+h}m=seconds/60%60;if(m.length<2){m="0"+m}s=seconds%60;if(s.length<2){s="0"+m}ms=parseInt((this.progress-seconds)*100);return h+":"+m+":"+s+"."+ms};return VASTTracker}(EventEmitter);module.exports=VASTTracker},{"./client":3,"./creative":5,"./util":18,"events":1}],15:[function(require,module,exports){var URLHandler,flash,xhr;xhr=require("./urlhandlers/xmlhttprequest");flash=require("./urlhandlers/flash");URLHandler=function(){function URLHandler(){}URLHandler.get=function(url,options,cb){var ref,response;if(!cb){if(typeof options==="function"){cb=options}options={}}if(options.response!=null){response=options.response;delete options.response;return cb(null,response)}else if((ref=options.urlhandler)!=null?ref.supported():void 0){return options.urlhandler.get(url,options,cb)}else if(typeof window==="undefined"||window===null){return require("./urlhandlers/"+"node").get(url,options,cb)}else if(xhr.supported()){return xhr.get(url,options,cb)}else if(flash.supported()){return flash.get(url,options,cb)}else{return cb(new Error("Current context is not supported by any of the default URLHandlers. Please provide a custom URLHandler"))}};return URLHandler}();module.exports=URLHandler},{"./urlhandlers/flash":16,"./urlhandlers/xmlhttprequest":17}],16:[function(require,module,exports){var FlashURLHandler;FlashURLHandler=function(){function FlashURLHandler(){}FlashURLHandler.xdr=function(){var xdr;if(window.XDomainRequest){xdr=new XDomainRequest}return xdr};FlashURLHandler.supported=function(){return!!this.xdr()};FlashURLHandler.get=function(url,options,cb){var xdr,xmlDocument;if(xmlDocument=typeof window.ActiveXObject==="function"?new window.ActiveXObject("Microsoft.XMLDOM"):void 0){xmlDocument.async=false}else{return cb(new Error("FlashURLHandler: Microsoft.XMLDOM format not supported"))}xdr=this.xdr();xdr.open("GET",url);xdr.timeout=options.timeout||0;xdr.withCredentials=options.withCredentials||false;xdr.send();xdr.onprogress=function(){};return xdr.onload=function(){xmlDocument.loadXML(xdr.responseText);return cb(null,xmlDocument)}};return FlashURLHandler}();module.exports=FlashURLHandler},{}],17:[function(require,module,exports){var XHRURLHandler;XHRURLHandler=function(){function XHRURLHandler(){}XHRURLHandler.xhr=function(){var xhr;xhr=new window.XMLHttpRequest;if("withCredentials"in xhr){return xhr}};XHRURLHandler.supported=function(){return!!this.xhr()};XHRURLHandler.get=function(url,options,cb){var xhr;if(window.location.protocol==="https:"&&url.indexOf("http://")===0){return cb(new Error("XHRURLHandler: Cannot go from HTTPS to HTTP."))}try{xhr=this.xhr();xhr.open("GET",url);xhr.timeout=options.timeout||0;xhr.withCredentials=options.withCredentials||false;xhr.overrideMimeType&&xhr.overrideMimeType("text/xml");xhr.onreadystatechange=function(){if(xhr.readyState===4){if(xhr.status===200){return cb(null,xhr.responseXML)}else{return cb(new Error("XHRURLHandler: "+xhr.statusText))}}};return xhr.send()}catch(error){return cb(new Error("XHRURLHandler: Unexpected error"))}};return XHRURLHandler}();module.exports=XHRURLHandler},{}],18:[function(require,module,exports){var VASTUtil;VASTUtil=function(){function VASTUtil(){}VASTUtil.track=function(URLTemplates,variables){var URL,URLs,i,j,len,results;URLs=this.resolveURLTemplates(URLTemplates,variables);results=[];for(j=0,len=URLs.length;j", 25 | "license": "GPL-3.0", 26 | "bugs": { 27 | "url": "https://github.com/vix-simplex/clappr-ad-plugin/issues" 28 | }, 29 | "homepage": "https://github.com/vix-simplex/clappr-ad-plugin#readme", 30 | "devDependencies": { 31 | "babel-cli": "^6.16.0", 32 | "babel-core": "^6.17.0", 33 | "babel-loader": "^6.2.5", 34 | "babel-plugin-add-module-exports": "^0.2.1", 35 | "babel-preset-es2015": "^6.16.0", 36 | "clean-webpack-plugin": "^0.1.13", 37 | "http-cli": "^1.1.0", 38 | "webpack": "^1.13.2" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/clappr-ad-plugin.old.js: -------------------------------------------------------------------------------- 1 | let adVideoPlayNow = ''; 2 | let p = ''; 3 | let adMediaFile = ''; 4 | let playlist = []; 5 | let adObject = {}; 6 | let vastTracker = ''; 7 | 8 | adObject.wasStarted = false; 9 | adObject.wasCompleted = false; 10 | adObject.setTypeAd = (type) => { 11 | adObject.typeAd = type; 12 | if (adObject.typeAd == 'pauseroll') { 13 | console.log('mid'); 14 | } else if (adObject.typeAd == 'preroll') { 15 | console.log('pre'); 16 | } 17 | }; 18 | 19 | 20 | // for containerEnded 21 | let amf = ''; 22 | 23 | let generatePlaylist = (urlVast, video) => { 24 | 25 | }; 26 | 27 | let createPromise = (urlVast, video) => { 28 | return new Promise(function (resolve, rejected) { 29 | DMVAST.client.get(urlVast, function (r, e) { 30 | 31 | // for containerEnded 32 | amf = r; 33 | console.log(amf); 34 | 35 | adMediaFile = r.ads[0].creatives[0].mediaFiles[0].fileURL; 36 | adObject.skipDelay = r.ads[0].creatives[0].skipDelay; 37 | adObject.clickLink = r.ads[0].creatives[0].videoClickThroughURLTemplate; 38 | 39 | vastTracker = new DMVAST.tracker(r.ads[0], r.ads[0].creatives[0]); 40 | console.log(vastTracker); 41 | 42 | const currentDate = () => { 43 | let d = new Date(); 44 | return "(" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ") "; 45 | }; 46 | 47 | vastTracker.on('start', () => { 48 | console.log(currentDate() + " Ad event: start"); 49 | }); 50 | vastTracker.on('skip', () => { 51 | console.log(currentDate() + " Ad event: skip"); 52 | }); 53 | vastTracker.on('pause', () => { 54 | console.log(currentDate() + " Ad event: pause"); 55 | }); 56 | vastTracker.on('resume', () => { 57 | console.log(currentDate() + " Ad event: resume"); 58 | }); 59 | vastTracker.on('resume', () => { 60 | console.log(currentDate() + " Ad event: complete"); 61 | }); 62 | 63 | playlist = [ 64 | { 65 | source: adMediaFile, 66 | ad: true 67 | }, 68 | { 69 | source: video, 70 | ad: false 71 | } 72 | ]; 73 | resolve(); 74 | }); 75 | }); 76 | }; 77 | 78 | // main visibility API function 79 | // use visibility API to check if current tab is active or not 80 | var _visibilityAPI = (function () { 81 | var stateKey, 82 | eventKey, 83 | keys = { 84 | hidden: "visibilitychange", 85 | webkitHidden: "webkitvisibilitychange", 86 | mozHidden: "mozvisibilitychange", 87 | msHidden: "msvisibilitychange" 88 | }; 89 | for (stateKey in keys) { 90 | if (stateKey in document) { 91 | eventKey = keys[stateKey]; 92 | break; 93 | } 94 | } 95 | return { 96 | 'setHandler': function (c) { 97 | if (c) document.addEventListener(eventKey, c); 98 | }, 99 | 'tabVisible': function () { 100 | return !document[stateKey]; 101 | } 102 | } 103 | })(); 104 | 105 | _visibilityAPI.setHandler(function () { 106 | if (p.options.source == adMediaFile) { 107 | if (_visibilityAPI.tabVisible()) { 108 | setTimeout(function () { 109 | p.play(); 110 | }, 300); 111 | } else { 112 | p.pause(); 113 | } 114 | } 115 | }); 116 | 117 | class adPlugin { 118 | constructor(skipoffset, plst, plr) { 119 | this.adButtonTimer(skipoffset); 120 | this.playlist = plst; 121 | this.player = plr; 122 | this.ab = document.getElementById('adButton'); 123 | this.playerEvents(this.player, this.playlist); 124 | } 125 | 126 | playerEvents(plr, plst) { 127 | plr.on(Clappr.Events.PLAYER_ENDED, function () { 128 | if (plst.length > 0) { 129 | vastTracker.complete(); 130 | adObject.wasCompleted = true; 131 | adPlugin.skipAd(plr, plst); 132 | } 133 | }); 134 | 135 | plr.on(Clappr.Events.PLAYER_PLAY, function () { 136 | plr.core.mediaControl.container.settings.seekEnabled = plst.length <= 0; 137 | if (plr.getCurrentTime() <= 1) { 138 | vastTracker.setProgress(1); 139 | adObject.wasStarted = true; 140 | } 141 | }); 142 | } 143 | 144 | adButtonTimer(s) { 145 | let self = this; 146 | var timerId = setInterval(function () { 147 | self.ab.textContent = 'You can skip this ad in ' + parseInt(s - plr.getCurrentTime()); 148 | if (plr.getCurrentTime() > s) { 149 | clearInterval(timerId); 150 | self.adSkipButtonEvent(); 151 | self.ab.textContent = 'Skip Ad'; 152 | console.log('time to skip ad!'); 153 | } 154 | }, 300); 155 | } 156 | 157 | adSkipButtonEvent() { 158 | var self = this; 159 | this.ab.onclick = () => { 160 | console.log('ab onclick'); 161 | adPlugin.skipAd(self.player, self.playlist); 162 | }; 163 | } 164 | 165 | static skipAd(p, playlist) { 166 | var playlistItem = playlist.shift(); 167 | adVideoPlayNow = playlistItem.ad; 168 | p.load(playlistItem.source, '', true); 169 | var ab = document.getElementById('adButton'); 170 | ab.parentNode.removeChild(ab); 171 | if (!adObject.wasCompleted) { 172 | vastTracker.skip(); 173 | } 174 | } 175 | } 176 | 177 | var adButton = Clappr.UIContainerPlugin.extend({ 178 | name: 'ad_button', 179 | initialize: function initialize() { 180 | this.render(); 181 | }, 182 | 183 | bindEvents: function bindEvents() { 184 | // this.listenTo(this.container, Clappr.Events.CONTAINER_PAUSE, this.show); 185 | this.listenTo(this.container, Clappr.Events.CONTAINER_CLICK, this.clickToContainer); 186 | this.listenTo(this.container, Clappr.Events.CONTAINER_PLAY, this.destroyAdPlugin); 187 | this.listenTo(this.container, Clappr.Events.CONTAINER_PAUSE, this.containerPause); 188 | }, 189 | 190 | containerPause: function () { 191 | vastTracker.setPaused(true); 192 | }, 193 | 194 | destroyAdPlugin: function () { 195 | if (adObject.wasStarted && !adObject.wasCompleted) { 196 | vastTracker.setPaused(false); 197 | } 198 | if (!adVideoPlayNow) { 199 | this.destroy(); 200 | } 201 | }, 202 | 203 | clickToContainer: function () { 204 | window.open(adObject.clickLink).focus(); 205 | }, 206 | 207 | show: function show() { 208 | this.$el.show(); 209 | }, 210 | 211 | render: function render() { 212 | this.$el.css('font-size', '20px'); 213 | this.$el.css('position', 'absolute'); 214 | this.$el.css('color', 'white'); 215 | this.$el.css('top', '70%'); 216 | this.$el.css('right', '0%'); 217 | this.$el.css('background-color', 'black'); 218 | this.$el.css('z-index', '100500'); 219 | this.$el.css('border', 'solid 3px #333333'); 220 | this.$el.css('padding', '5px'); 221 | this.container.$el.append(this.$el); 222 | this.$el[0].id = 'adButton'; 223 | this.show(); 224 | return this; 225 | } 226 | }); 227 | -------------------------------------------------------------------------------- /src/clappr-vast-ad-plugin.js: -------------------------------------------------------------------------------- 1 | // preroll 2 | 3 | // pauseroll 4 | // TODO how detect - live or vod? 5 | // TODO live pauseroll? 6 | 7 | // common 8 | 9 | let adVideoPlayNow = false; 10 | let p = ''; 11 | let playlist = []; 12 | let adObject = {}; 13 | let vastTracker = ''; 14 | let vct = ''; 15 | let typeVideo = ''; 16 | let firstStart = true; 17 | let pauseNow = false; 18 | let preroll = false; 19 | let pauseroll = false; 20 | let skipButtonPressed = false; 21 | let isFullscreen = false; 22 | let progressEventsSeconds = []; 23 | 24 | adObject.adMediaFile = ''; 25 | 26 | const setTypeAd = (type) => { 27 | if (type == 'preroll') { 28 | preroll = true; 29 | adVideoPlayNow = true; 30 | } else if (type == 'pauseroll') { 31 | pauseroll = true; 32 | adVideoPlayNow = false; 33 | } 34 | }; 35 | 36 | const setVideoType = (type) => { 37 | typeVideo = type; 38 | }; 39 | 40 | const getSource = (type) => { 41 | if (type == 'video') { 42 | for (let z of playlist) { 43 | if (!z.ad) { 44 | return z; 45 | } 46 | } 47 | } else if (type == 'ad') { 48 | for (let z of playlist) { 49 | if (z.ad) { 50 | return z; 51 | } 52 | } 53 | } else if (type == null) { 54 | if (preroll) { 55 | return getSource('ad'); 56 | } else if (pauseroll) { 57 | return getSource('video'); 58 | } 59 | } 60 | }; 61 | 62 | const fsEventOn = () => { 63 | p.on(Clappr.Events.PLAYER_FULLSCREEN, function () { 64 | isFullscreen = !isFullscreen; 65 | if (adVideoPlayNow) { 66 | vastTracker.setFullscreen(isFullscreen); 67 | // isFullscreen ? 68 | // vastTracker.trackURLs(r.ads[0].creatives[0].trackingEvents['expand']) : 69 | // vastTracker.trackURLs(r.ads[0].creatives[0].trackingEvents['collapse']); 70 | vastTracker.setExpand(isFullscreen); 71 | } 72 | }) 73 | }; 74 | 75 | const loadVAST = (urlVast, video) => { 76 | return new Promise(function (resolve, rejected) { 77 | DMVAST.client.get(urlVast, function (r, e) { 78 | if (!r) { 79 | rejected('Error loading VAST - WTF ¯\\\_(ツ)_/¯'); 80 | } 81 | console.log(r); 82 | 83 | // use 'close' instead 'skip', if there is 'close' and there is no 'skip' 84 | if (!r.ads[0].creatives[0].trackingEvents['skip'] && r.ads[0].creatives[0].trackingEvents['close']) { 85 | r.ads[0].creatives[0].trackingEvents['skip'] = r.ads[0].creatives[0].trackingEvents['close']; 86 | delete r.ads[0].creatives[0].trackingEvents['close']; 87 | } 88 | 89 | // console.log(r.ads[0].creatives[0].trackingEvents.fullscreen[0]); 90 | // console.log(r.ads[0].creatives[0].trackingEvents.expand[0]); 91 | 92 | // console.log(r.ads[0].creatives[0].mediaFiles); 93 | // console.log(r.ads[0].creatives[0].mediaFiles[0]); 94 | // console.log(r.ads[0].creatives[0].mediaFiles[0].apiFramework); 95 | // console.log(r.ads[0].creatives[0].mediaFiles[0].fileURL); 96 | // console.log(r.ads[0].creatives[0].type); 97 | 98 | // console.log('skip delay = ' + r.ads[0].creatives[0].skipDelay); 99 | 100 | adObject.adMediaFile = r.ads[0].creatives[0].mediaFiles[0].fileURL; 101 | adObject.clickLink = r.ads[0].creatives[0].videoClickThroughURLTemplate; 102 | 103 | vastTracker = new DMVAST.tracker(r.ads[0], r.ads[0].creatives[0]); 104 | 105 | const currentDate = () => { 106 | let d = new Date(); 107 | return "(" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ") "; 108 | }; 109 | 110 | // for vast-events: expand, collapse 111 | vastTracker.emitAlwaysEvents.push('expand'); 112 | vastTracker.emitAlwaysEvents.push('collapse'); 113 | vastTracker.setExpand = function (fullscreen) { 114 | console.log(currentDate() + " Ad event: " + (fullscreen ? "expand" : "collapse")); 115 | this.track(fullscreen ? "expand" : "collapse"); 116 | }; 117 | 118 | // console.log(vastTracker); 119 | vastTracker.on('start', () => console.log(currentDate() + " Ad event: start")); 120 | vastTracker.on('skip', () => console.log(currentDate() + " Ad event: skip")); 121 | vastTracker.on('pause', () => console.log(currentDate() + " Ad event: pause")); 122 | vastTracker.on('resume', () => console.log(currentDate() + " Ad event: resume")); 123 | vastTracker.on('complete', () => console.log(currentDate() + " Ad event: complete")); 124 | vastTracker.on('firstQuartile', () => console.log(currentDate() + " Ad event: firstQuartile")); 125 | vastTracker.on('midpoint', () => console.log(currentDate() + " Ad event: midpoint")); 126 | vastTracker.on('thirdQuartile', () => console.log(currentDate() + " Ad event: thirdQuartile")); 127 | vastTracker.on('mute', () => console.log(currentDate() + " Ad event: mute")); 128 | vastTracker.on('unmute', () => console.log(currentDate() + " Ad event: unmute")); 129 | vastTracker.on('fullscreen', () => console.log(currentDate() + " Ad event: fullscreen")); 130 | vastTracker.on('exitFullscreen', () => console.log(currentDate() + " Ad event: exitFullscreen")); 131 | vastTracker.on('clickthrough', url => console.log(currentDate() + " Ad event: click")); 132 | vastTracker.on('creativeView', () => { 133 | console.log(currentDate() + " Ad event: impression"); 134 | console.log(currentDate() + " Ad event: creativeView"); 135 | }); 136 | 137 | // parsing seconds for progress-\d* events 138 | for (let k in vastTracker.trackingEvents) { 139 | let re = /progress-\d*/; 140 | if (!k.search(re)) { 141 | progressEventsSeconds.push(parseInt(k.split('-')[1])); 142 | } 143 | } 144 | 145 | // parsing extensions 146 | const setSkipDelay = sd => { 147 | if (!sd || sd >= r.ads[0].creatives[0].duration || sd < 0) { 148 | adObject.skipDelay = r.ads[0].creatives[0].duration / 2; 149 | } else { 150 | adObject.skipDelay = sd; 151 | } 152 | }; 153 | let st2f = false; 154 | let customURLs = []; 155 | for (let w in r.ads[0].extensions) { 156 | if (r.ads[0].extensions[w].attributes.type.toLowerCase() == 'skiptime2' && !st2f) { 157 | const prsDrExtnsn = durationString => { 158 | let durationComponents, minutes, seconds, secondsAndMS; 159 | if (!(durationString != null)) { 160 | return null; 161 | } 162 | durationComponents = durationString.split(":"); 163 | if (durationComponents.length !== 2) { 164 | return null; 165 | } 166 | secondsAndMS = durationComponents[1].split("."); 167 | seconds = parseInt(secondsAndMS[0]); 168 | if (secondsAndMS.length === 2) { 169 | seconds += parseFloat("0." + secondsAndMS[1]); 170 | } 171 | minutes = parseInt(durationComponents[0] * 60); 172 | if (isNaN(minutes || isNaN(seconds || minutes > 60 * 60 || seconds > 60))) { 173 | return null; 174 | } 175 | return minutes + seconds; 176 | }; 177 | setSkipDelay(prsDrExtnsn(r.ads[0].extensions[w].children[0].value)); 178 | st2f = true; 179 | } else if (r.ads[0].extensions[w].attributes.type.toLowerCase() == 'customtracking') { 180 | for (let z in r.ads[0].extensions[w].children) { 181 | // console.log(r.ads[0].extensions[w].children[z].value.trim()); 182 | customURLs.push(r.ads[0].extensions[w].children[z].value); 183 | } 184 | console.log(currentDate() + " Ad event: CustomTracking"); 185 | vastTracker.trackURLs(customURLs); 186 | } 187 | } 188 | if (!st2f) { 189 | setSkipDelay(r.ads[0].creatives[0].skipDelay); 190 | } 191 | 192 | progressEventsSeconds.sort((a, b) => a - b); 193 | playlist = [ 194 | { 195 | source: adObject.adMediaFile, 196 | ad: true 197 | }, 198 | { 199 | source: video, 200 | ad: false, 201 | typeVideo: typeVideo 202 | } 203 | ]; 204 | 205 | if (r.ads[0].creatives[0].mediaFiles[0].apiFramework == 'VPAID') { 206 | rejected('Error loading VAST - VPAID not supported'); 207 | } 208 | resolve(); 209 | }); 210 | }); 211 | }; 212 | 213 | // main visibility API function 214 | // use visibility API to check if current tab is active or not 215 | const _visibilityAPI = (function () { 216 | var stateKey, 217 | eventKey, 218 | keys = { 219 | hidden: "visibilitychange", 220 | webkitHidden: "webkitvisibilitychange", 221 | mozHidden: "mozvisibilitychange", 222 | msHidden: "msvisibilitychange" 223 | }; 224 | for (stateKey in keys) { 225 | if (stateKey in document) { 226 | eventKey = keys[stateKey]; 227 | break; 228 | } 229 | } 230 | return { 231 | 'setHandler': function (c) { 232 | if (c) document.addEventListener(eventKey, c); 233 | }, 234 | 'tabVisible': function () { 235 | return !document[stateKey]; 236 | } 237 | } 238 | })(); 239 | 240 | _visibilityAPI.setHandler(function () { 241 | if (adVideoPlayNow) { 242 | if (_visibilityAPI.tabVisible()) { 243 | setTimeout(function () { 244 | p.play(); 245 | }, 300); 246 | } else { 247 | p.pause(); 248 | } 249 | } 250 | }); 251 | 252 | let adPlugin = Clappr.UIContainerPlugin.extend({ 253 | name: 'ad_plugin', 254 | AdMuted: false, 255 | videoWasCompleted: false, 256 | 257 | initialize: function initialize() { 258 | this.render(); 259 | this.checkAdTime(); 260 | }, 261 | 262 | bindEvents: function bindEvents() { 263 | // console.log('bind events - called'); 264 | this.listenTo(this.container, Clappr.Events.CONTAINER_CLICK, this.ContainerClick); 265 | this.listenTo(this.container, Clappr.Events.CONTAINER_PLAY, this.containerPlay); 266 | this.listenTo(this.container, Clappr.Events.CONTAINER_ENDED, this.containerEnded); 267 | this.listenTo(this.container, Clappr.Events.CONTAINER_PAUSE, this.containerPause); 268 | this.listenTo(this.container, Clappr.Events.CONTAINER_VOLUME, this.containerVolume); 269 | }, 270 | 271 | containerVolume: function () { 272 | if (adVideoPlayNow && p) { 273 | // console.log(p.getVolume()); 274 | if (p.getVolume() == 0 && !this.AdMuted) { 275 | vastTracker.setMuted(true); 276 | this.AdMuted = true; 277 | } else if (p.getVolume() != 0 && this.AdMuted) { 278 | vastTracker.setMuted(false); 279 | this.AdMuted = false; 280 | } 281 | } 282 | }, 283 | 284 | // VAST-events - firstQuartile, midpoint, thirdQuartile, progress 285 | checkAdTime: function () { 286 | if (adVideoPlayNow) { 287 | let fq = false, mp = false, tq = false; 288 | let timerId = setInterval(function () { 289 | if (skipButtonPressed) { 290 | clearInterval(timerId); 291 | } else { 292 | // if (progressEventsSeconds.length) { 293 | if (progressEventsSeconds.length && p.getCurrentTime() >= progressEventsSeconds[0]) { 294 | vastTracker.setProgress(progressEventsSeconds.shift()); 295 | } 296 | // } 297 | if (p.getCurrentTime() >= p.getDuration() * 0.25 && !fq) { 298 | vastTracker.setProgress(p.getCurrentTime()); 299 | fq = true; 300 | } else if (p.getCurrentTime() >= p.getDuration() * 0.5 && !mp) { 301 | vastTracker.setProgress(p.getCurrentTime()); 302 | mp = true; 303 | } else if (p.getCurrentTime() >= p.getDuration() * 0.75 && !tq) { 304 | vastTracker.setProgress(p.getCurrentTime()); 305 | tq = true; 306 | clearInterval(timerId); 307 | } 308 | } 309 | }, 300); 310 | } 311 | }, 312 | 313 | initPlayerFor: function (type) { 314 | // console.log('ipf'); 315 | if (type == 'video') { 316 | // console.log('ipfv'); 317 | adVideoPlayNow = false; 318 | pauseNow = false; 319 | p.load(getSource('video').source); 320 | if (getSource('video').typeVideo == 'vod') { 321 | p.seek(vct); 322 | } 323 | } else if (type == 'ad') { 324 | // console.log('ipfa'); 325 | adVideoPlayNow = true; 326 | p.load(getSource('ad').source); 327 | p.setVolume(100); 328 | skipButtonPressed = false; 329 | } 330 | }, 331 | 332 | containerPlay: function () { 333 | let self = this; 334 | // console.log('play called'); 335 | p.core.mediaControl.container.settings.seekEnabled = !adVideoPlayNow; 336 | if (adVideoPlayNow) { 337 | if (isFullscreen) { 338 | vastTracker.setFullscreen(true); 339 | vastTracker.setExpand(true); 340 | // vastTracker.trackURLs(r.ads[0].creatives[0].trackingEvents['expand']); 341 | } 342 | } 343 | 344 | if (preroll) { 345 | if (adVideoPlayNow) { 346 | if (firstStart) { 347 | p.setVolume(100); 348 | vastTracker.setDuration(p.getDuration()); 349 | vastTracker.load(); 350 | vastTracker.setProgress(0.1); 351 | firstStart = false; 352 | } else { 353 | vastTracker.setPaused(false); 354 | } 355 | } 356 | 357 | if (this.videoWasCompleted) { 358 | this.videoWasCompleted = false; 359 | loadVAST(vastUrl, mainVideo).then(() => self.initPlayerFor('ad')); 360 | } 361 | } else if (pauseroll) { 362 | if (adVideoPlayNow) 363 | if (p.getCurrentTime() == 0) { 364 | vastTracker.setDuration(p.getDuration()); 365 | vastTracker.load(); 366 | vastTracker.setProgress(0.1); 367 | } else { 368 | vastTracker.setPaused(false); 369 | } 370 | if (!adVideoPlayNow && !firstStart && pauseNow && p.getCurrentTime() != 0) { 371 | if (getSource('video').typeVideo == 'vod') { 372 | vct = p.getCurrentTime(); 373 | } 374 | loadVAST(vastUrl, mainVideo).then(() => self.initPlayerFor('ad')); 375 | } 376 | pauseNow = false; 377 | adVideoPlayNow = p.options.sources[0] != getSource('video').source; 378 | if (adVideoPlayNow) { 379 | this.show(); 380 | } else { 381 | this.hide(); 382 | } 383 | } 384 | }, 385 | 386 | containerEnded: function () { 387 | let self = this; 388 | if (adVideoPlayNow) { 389 | vastTracker.complete(); 390 | this.initPlayerFor('video'); 391 | } else if (!adVideoPlayNow && preroll) { 392 | self.videoWasCompleted = true; 393 | firstStart = true; 394 | } 395 | }, 396 | 397 | containerPause: function () { 398 | // console.log('pause called'); 399 | if (adVideoPlayNow && !p.ended) { 400 | vastTracker.setPaused(true); 401 | } 402 | if (preroll) { 403 | 404 | } else if (pauseroll) { 405 | firstStart = false; 406 | pauseNow = true; 407 | } 408 | // vastTracker.setPaused(true); 409 | }, 410 | 411 | ContainerClick: function () { 412 | if (adVideoPlayNow) { 413 | window.open(adObject.clickLink).focus(); 414 | vastTracker.click(); 415 | } else if (!adVideoPlayNow && pauseroll && getSource('video').typeVideo == 'live') { 416 | p.pause(); 417 | } 418 | }, 419 | 420 | show: function () { 421 | // console.log('show called'); 422 | const showAdButton = () => { 423 | this.$el.show(); 424 | let timerId = setInterval(() => { 425 | let ab = document.getElementById('adButton'); 426 | ab.textContent = 'You can skip this ad in ' + parseInt(adObject.skipDelay - p.getCurrentTime()); 427 | if (p.getCurrentTime() > adObject.skipDelay) { 428 | clearInterval(timerId); 429 | ab.onclick = () => { 430 | skipButtonPressed = true; 431 | // console.log('ab onclick'); 432 | vastTracker.skip(); 433 | this.initPlayerFor('video'); 434 | }; 435 | ab.textContent = 'Skip Ad'; 436 | // console.log('time to skip ad!'); 437 | } 438 | }, 300); 439 | }; 440 | if (preroll) { 441 | if (adVideoPlayNow) { 442 | showAdButton(); 443 | } else { 444 | this.hide(); 445 | } 446 | } else if (pauseroll) { 447 | showAdButton(); 448 | } 449 | // console.log('show called'); 450 | }, 451 | 452 | hide: function () { 453 | console.log('hide called'); 454 | this.$el.hide(); 455 | }, 456 | 457 | render: function render() { 458 | // console.log('render called'); 459 | this.$el.css('font-size', '20px'); 460 | this.$el.css('position', 'absolute'); 461 | this.$el.css('color', 'white'); 462 | this.$el.css('top', '70%'); 463 | this.$el.css('right', '0%'); 464 | this.$el.css('background-color', 'black'); 465 | this.$el.css('z-index', '100500'); 466 | this.$el.css('border', 'solid 3px #333333'); 467 | this.$el.css('padding', '5px'); 468 | this.container.$el.append(this.$el); 469 | this.$el[0].id = 'adButton'; 470 | 471 | if (preroll) { 472 | this.show(); 473 | } else if (pauseroll) { 474 | if (adVideoPlayNow) { 475 | // console.log('render - show'); 476 | this.show(); 477 | } else { 478 | this.hide(); 479 | // console.log('render - hide'); 480 | } 481 | } 482 | // this.$el.html('pew pew pew'); 483 | return this; 484 | } 485 | }); 486 | -------------------------------------------------------------------------------- /src/cvap.js: -------------------------------------------------------------------------------- 1 | let adVideoPlayNow = false; 2 | let p = ''; 3 | let playlist = []; 4 | let adObject = {}; 5 | let typeVideo = ''; 6 | let preroll = false; 7 | let pauseroll = false; 8 | let isFullscreen = false; 9 | let pauseNow = false; 10 | let firstStart = true; 11 | let vastTracker = ''; 12 | let progressEventsSeconds = []; 13 | let customURLs = []; 14 | let skipButtonPressed = false; 15 | let adFirstStart = ''; 16 | let vct = ''; 17 | 18 | adObject.adMediaFile = ''; 19 | 20 | const cnfPlrAd = () => { 21 | player.source = getSource().source; 22 | player.plugins ? player.plugins.push(adPlugin) : player.plugins = [adPlugin]; 23 | p = new Clappr.Player(player); 24 | fsEventOn(); 25 | }; 26 | 27 | const cnfPlr = () => { 28 | if (preroll) { 29 | loadVAST(vastUrl, mainVideo).then( 30 | function () { 31 | cnfPlrAd(); 32 | }, 33 | function (msg) { 34 | player.source = getSource('video').source; 35 | p = new Clappr.Player(player); 36 | console.log(msg); 37 | }); 38 | } else if (pauseroll) { 39 | cnfPlrAd(); 40 | } 41 | }; 42 | 43 | const _visibilityAPI = (function () { 44 | var stateKey, 45 | eventKey, 46 | keys = { 47 | hidden: "visibilitychange", 48 | webkitHidden: "webkitvisibilitychange", 49 | mozHidden: "mozvisibilitychange", 50 | msHidden: "msvisibilitychange" 51 | }; 52 | for (stateKey in keys) { 53 | if (stateKey in document) { 54 | eventKey = keys[stateKey]; 55 | break; 56 | } 57 | } 58 | return { 59 | 'setHandler': function (c) { 60 | if (c) document.addEventListener(eventKey, c); 61 | }, 62 | 'tabVisible': function () { 63 | return !document[stateKey]; 64 | } 65 | } 66 | })(); 67 | 68 | _visibilityAPI.setHandler(function () { 69 | if (adVideoPlayNow) { 70 | if (_visibilityAPI.tabVisible()) { 71 | setTimeout(function () { 72 | p.play(); 73 | }, 300); 74 | } else { 75 | p.pause(); 76 | } 77 | } 78 | }); 79 | 80 | 81 | const currentDate = () => { 82 | let d = new Date(); 83 | return "(" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ") "; 84 | }; 85 | 86 | const getSource = (type) => { 87 | if (type == 'video') { 88 | for (let z of playlist) { 89 | if (!z.ad) { 90 | return z; 91 | } 92 | } 93 | } else if (type == 'ad') { 94 | for (let z of playlist) { 95 | if (z.ad) { 96 | return z; 97 | } 98 | } 99 | } else if (type == null) { 100 | if (!preroll && !pauseroll || preroll && pauseroll) { 101 | console.log('Error - please configure type ag: setTypeAd(\'preroll\') or setTypeAd(\'pauseroll\')'); 102 | } else { 103 | if (preroll) { 104 | return getSource('ad'); 105 | } else if (pauseroll) { 106 | return getSource('video'); 107 | } 108 | } 109 | } 110 | }; 111 | 112 | const setTypeAd = (type) => { 113 | if (type == 'preroll') { 114 | preroll = true; 115 | adVideoPlayNow = true; 116 | } else if (type == 'pauseroll') { 117 | pauseroll = true; 118 | adVideoPlayNow = false; 119 | } 120 | }; 121 | 122 | const setVideoType = (type) => { 123 | typeVideo = type; 124 | playlist = [ 125 | { 126 | source: '', 127 | ad: true 128 | }, 129 | { 130 | source: mainVideo, 131 | ad: false, 132 | typeVideo: type 133 | } 134 | ]; 135 | }; 136 | 137 | const fsEventOn = () => { 138 | p.on(Clappr.Events.PLAYER_FULLSCREEN, function () { 139 | isFullscreen = !isFullscreen; 140 | if (adVideoPlayNow) { 141 | vastTracker.setFullscreen(isFullscreen); 142 | vastTracker.setExpand(isFullscreen); 143 | } 144 | }) 145 | }; 146 | 147 | const loadVAST = (urlVast, video) => { 148 | return new Promise(function (resolve, rejected) { 149 | DMVAST.client.get(urlVast, function (r, e) { 150 | if (!r) { 151 | adVideoPlayNow ? adVideoPlayNow = false : ''; 152 | rejected('Error loading VAST - r is null'); 153 | } 154 | console.log(r); 155 | 156 | // use 'close' instead 'skip', if there is 'close' and there is no 'skip' 157 | if (!r.ads[0].creatives[0].trackingEvents['skip'] && r.ads[0].creatives[0].trackingEvents['close']) { 158 | r.ads[0].creatives[0].trackingEvents['skip'] = r.ads[0].creatives[0].trackingEvents['close']; 159 | delete r.ads[0].creatives[0].trackingEvents['close']; 160 | } 161 | adObject.adMediaFile = r.ads[0].creatives[0].mediaFiles[0].fileURL; 162 | adObject.clickLink = r.ads[0].creatives[0].videoClickThroughURLTemplate; 163 | vastTracker = new DMVAST.tracker(r.ads[0], r.ads[0].creatives[0]); 164 | 165 | // for vast-events: expand, collapse 166 | vastTracker.emitAlwaysEvents.push('expand'); 167 | vastTracker.emitAlwaysEvents.push('collapse'); 168 | vastTracker.setExpand = function (fullscreen) { 169 | console.log(currentDate() + " Ad event: " + (fullscreen ? "expand" : "collapse")); 170 | this.track(fullscreen ? "expand" : "collapse"); 171 | }; 172 | 173 | vastTracker.on('start', () => console.log(currentDate() + " Ad event: start")); 174 | vastTracker.on('skip', () => console.log(currentDate() + " Ad event: skip")); 175 | vastTracker.on('pause', () => console.log(currentDate() + " Ad event: pause")); 176 | vastTracker.on('resume', () => console.log(currentDate() + " Ad event: resume")); 177 | vastTracker.on('complete', () => console.log(currentDate() + " Ad event: complete")); 178 | vastTracker.on('firstQuartile', () => console.log(currentDate() + " Ad event: firstQuartile")); 179 | vastTracker.on('midpoint', () => console.log(currentDate() + " Ad event: midpoint")); 180 | vastTracker.on('thirdQuartile', () => console.log(currentDate() + " Ad event: thirdQuartile")); 181 | vastTracker.on('mute', () => console.log(currentDate() + " Ad event: mute")); 182 | vastTracker.on('unmute', () => console.log(currentDate() + " Ad event: unmute")); 183 | vastTracker.on('fullscreen', () => console.log(currentDate() + " Ad event: fullscreen")); 184 | vastTracker.on('exitFullscreen', () => console.log(currentDate() + " Ad event: exitFullscreen")); 185 | vastTracker.on('clickthrough', url => console.log(currentDate() + " Ad event: click")); 186 | vastTracker.on('creativeView', () => { 187 | console.log(currentDate() + " Ad event: impression"); 188 | console.log(currentDate() + " Ad event: creativeView"); 189 | }); 190 | 191 | // parsing seconds for progress-\d* events 192 | for (let k in vastTracker.trackingEvents) { 193 | let re = /progress-\d*/; 194 | if (!k.search(re)) { 195 | progressEventsSeconds.push(parseInt(k.split('-')[1])); 196 | } 197 | } 198 | 199 | // parsing extensions 200 | const setSkipDelay = sd => { 201 | if (!sd || sd >= r.ads[0].creatives[0].duration || sd < 0) { 202 | adObject.skipDelay = r.ads[0].creatives[0].duration / 2; 203 | } else { 204 | adObject.skipDelay = sd; 205 | } 206 | }; 207 | let st2f = false; 208 | for (let w in r.ads[0].extensions) { 209 | if (r.ads[0].extensions[w].attributes.type.toLowerCase() == 'skiptime2' && !st2f) { 210 | const prsDrExtnsn = durationString => { 211 | let durationComponents, minutes, seconds, secondsAndMS; 212 | if (!(durationString != null)) { 213 | return null; 214 | } 215 | durationComponents = durationString.split(":"); 216 | if (durationComponents.length !== 2) { 217 | return null; 218 | } 219 | secondsAndMS = durationComponents[1].split("."); 220 | seconds = parseInt(secondsAndMS[0]); 221 | if (secondsAndMS.length === 2) { 222 | seconds += parseFloat("0." + secondsAndMS[1]); 223 | } 224 | minutes = parseInt(durationComponents[0] * 60); 225 | if (isNaN(minutes || isNaN(seconds || minutes > 60 * 60 || seconds > 60))) { 226 | return null; 227 | } 228 | return minutes + seconds; 229 | }; 230 | setSkipDelay(prsDrExtnsn(r.ads[0].extensions[w].children[0].value)); 231 | st2f = true; 232 | } else if (r.ads[0].extensions[w].attributes.type.toLowerCase() == 'customtracking') { 233 | for (let z in r.ads[0].extensions[w].children) { 234 | customURLs.push(r.ads[0].extensions[w].children[z].value); 235 | } 236 | } 237 | } 238 | if (!st2f) { 239 | setSkipDelay(r.ads[0].creatives[0].skipDelay); 240 | } 241 | 242 | progressEventsSeconds.sort((a, b) => a - b); 243 | getSource('ad').source = adObject.adMediaFile; 244 | 245 | if (r.ads[0].creatives[0].mediaFiles[0].apiFramework == 'VPAID') { 246 | adVideoPlayNow ? adVideoPlayNow = false : ''; 247 | rejected('Error loading VAST - VPAID not supported'); 248 | } 249 | adFirstStart = true; 250 | resolve(); 251 | }); 252 | }); 253 | }; 254 | 255 | let adPlugin = Clappr.UIContainerPlugin.extend({ 256 | name: 'ad_plugin', 257 | videoWasCompleted: false, 258 | AdMuted: false, 259 | 260 | initialize: function initialize() { 261 | this.render(); 262 | this.checkAdTime(); 263 | }, 264 | 265 | bindEvents: function bindEvents() { 266 | this.listenTo(this.container, Clappr.Events.CONTAINER_PAUSE, this.containerPause); 267 | this.listenTo(this.container, Clappr.Events.CONTAINER_PLAY, this.containerPlay); 268 | this.listenTo(this.container, Clappr.Events.CONTAINER_ENDED, this.containerEnded); 269 | this.listenTo(this.container, Clappr.Events.CONTAINER_CLICK, this.ContainerClick); 270 | this.listenTo(this.container, Clappr.Events.CONTAINER_VOLUME, this.containerVolume); 271 | }, 272 | 273 | show: function () { 274 | const showAdButton = () => { 275 | this.$el.show(); 276 | let timerId = setInterval(() => { 277 | let ab = document.getElementById('adButton'); 278 | ab.textContent = 'You can skip this ad in ' + parseInt(adObject.skipDelay - p.getCurrentTime()); 279 | if (p.getCurrentTime() > adObject.skipDelay) { 280 | clearInterval(timerId); 281 | ab.onclick = () => { 282 | skipButtonPressed = true; 283 | vastTracker.skip(); 284 | this.initPlayerFor('video'); 285 | }; 286 | ab.textContent = 'Skip Ad'; 287 | } 288 | }, 300); 289 | }; 290 | if (preroll) { 291 | if (adVideoPlayNow) { 292 | showAdButton(); 293 | } else { 294 | this.hide(); 295 | } 296 | } else if (pauseroll) { 297 | showAdButton(); 298 | } 299 | }, 300 | 301 | hide: function () { 302 | this.$el.hide(); 303 | }, 304 | 305 | render: function render() { 306 | this.$el.css('font-size', '20px'); 307 | this.$el.css('position', 'absolute'); 308 | this.$el.css('color', 'white'); 309 | this.$el.css('top', '70%'); 310 | this.$el.css('right', '0%'); 311 | this.$el.css('background-color', 'black'); 312 | this.$el.css('z-index', '100500'); 313 | this.$el.css('border', 'solid 3px #333333'); 314 | this.$el.css('padding', '5px'); 315 | this.container.$el.append(this.$el); 316 | this.$el[0].id = 'adButton'; 317 | 318 | if (preroll) { 319 | this.show(); 320 | } else if (pauseroll) { 321 | if (adVideoPlayNow) { 322 | this.show(); 323 | } else { 324 | this.hide(); 325 | } 326 | } 327 | return this; 328 | }, 329 | 330 | containerPause: function () { 331 | if (adVideoPlayNow && !p.ended) { 332 | vastTracker.setPaused(true); 333 | } 334 | // not activate 'play' event when pause 335 | if (!adVideoPlayNow) { 336 | pauseNow = true; 337 | } 338 | }, 339 | 340 | containerPlay: function () { 341 | p.core.mediaControl.container.settings.seekEnabled = !adVideoPlayNow; 342 | let self = this; 343 | if (adVideoPlayNow) { 344 | if (adFirstStart) { 345 | vastTracker.setProgress(0.1); 346 | vastTracker.setDuration(p.getDuration()); 347 | vastTracker.load(); 348 | p.setVolume(100); 349 | vastTracker.trackURLs(customURLs); 350 | console.log(currentDate() + " Ad event: CustomTracking"); 351 | adFirstStart = false; 352 | } else { 353 | vastTracker.setPaused(false); 354 | } 355 | } 356 | if (preroll) { 357 | if (this.videoWasCompleted) { 358 | this.videoWasCompleted = false; 359 | loadVAST(vastUrl, mainVideo).then(() => self.initPlayerFor('ad')); 360 | } 361 | } else if (pauseroll) { 362 | if (!adVideoPlayNow && pauseNow && !firstStart) { 363 | pauseNow = false; 364 | if (getSource('video').typeVideo == 'vod') { 365 | vct = p.getCurrentTime(); 366 | } 367 | loadVAST(vastUrl, mainVideo).then(() => self.initPlayerFor('ad')); 368 | } 369 | } 370 | firstStart = false; 371 | }, 372 | 373 | containerEnded: function () { 374 | firstStart = true; 375 | pauseNow = false; 376 | let self = this; 377 | if (adVideoPlayNow) { 378 | vastTracker.complete(); 379 | this.initPlayerFor('video'); 380 | } else if (!adVideoPlayNow && preroll) { 381 | self.videoWasCompleted = true; 382 | } 383 | 384 | }, 385 | 386 | ContainerClick: function () { 387 | if (adVideoPlayNow) { 388 | window.open(adObject.clickLink).focus(); 389 | vastTracker.click(); 390 | } else if (!adVideoPlayNow && pauseroll && getSource('video').typeVideo == 'live') { 391 | p.pause(); 392 | } 393 | }, 394 | 395 | initPlayerFor: function (type) { 396 | if (type == 'video') { 397 | adVideoPlayNow = false; 398 | pauseNow = false; 399 | p.load(getSource('video').source); 400 | if (getSource('video').typeVideo == 'vod') { 401 | p.seek(vct); 402 | } 403 | } else if (type == 'ad') { 404 | adVideoPlayNow = true; 405 | p.load(getSource('ad').source); 406 | p.setVolume(100); 407 | skipButtonPressed = false; 408 | p.play(); 409 | } 410 | }, 411 | 412 | checkAdTime: function () { 413 | if (adVideoPlayNow) { 414 | let fq = false, mp = false, tq = false; 415 | let timerId = setInterval(function () { 416 | if (skipButtonPressed) { 417 | clearInterval(timerId); 418 | } else { 419 | if (progressEventsSeconds.length && p.getCurrentTime() >= progressEventsSeconds[0]) { 420 | vastTracker.setProgress(progressEventsSeconds.shift()); 421 | console.log(currentDate() + " Ad event: progress") 422 | } 423 | if (p.getCurrentTime() >= p.getDuration() * 0.25 && !fq) { 424 | vastTracker.setProgress(p.getCurrentTime()); 425 | fq = true; 426 | } else if (p.getCurrentTime() >= p.getDuration() * 0.5 && !mp) { 427 | vastTracker.setProgress(p.getCurrentTime()); 428 | mp = true; 429 | } else if (p.getCurrentTime() >= p.getDuration() * 0.75 && !tq) { 430 | vastTracker.setProgress(p.getCurrentTime()); 431 | tq = true; 432 | clearInterval(timerId); 433 | } 434 | } 435 | }, 300); 436 | } 437 | }, 438 | 439 | containerVolume: function () { 440 | if (adVideoPlayNow && p) { 441 | if (p.getVolume() == 0 && !this.AdMuted || p.getVolume() != 0 && this.AdMuted) { 442 | this.AdMuted = !this.AdMuted; 443 | vastTracker.setMuted(this.AdMuted); 444 | } 445 | } 446 | }, 447 | }); 448 | -------------------------------------------------------------------------------- /src/cvap2.js: -------------------------------------------------------------------------------- 1 | let adVideoPlayNow = true; 2 | let mainVideoPlayNow = false; 3 | let preroll = true; 4 | let pauseroll = false; 5 | let sbPressed = false; 6 | let adFirstStart = true; 7 | let pauseNow = false; 8 | let progressEventsSeconds = []; 9 | let videoMainVod = false; 10 | let videoMainLive = false; 11 | let videoCurrentTime = 0; 12 | let isFullscreen = false; 13 | let videoAd; 14 | let player; 15 | let skipDelay; 16 | let vastTracker; 17 | let clickLink; 18 | let myFirstPlay = true; 19 | 20 | const loadVAST = (url) => { 21 | return new Promise(function (resolve, reject) { 22 | if (myFirstPlay && pauseroll) { 23 | myFirstPlay = false; 24 | resolve(); 25 | } else { 26 | DMVAST.client.get(url, function (r, e) { 27 | 28 | if (!r) { 29 | adVideoPlayNow ? adVideoPlayNow = false : ''; 30 | reject('Error loading VAST - r is null'); 31 | } 32 | console.log(r); 33 | 34 | if (r.ads[0].creatives[0].mediaFiles[0].apiFramework == 'VPAID') { 35 | adVideoPlayNow ? adVideoPlayNow = false : ''; 36 | reject('Error loading VAST - VPAID not supported'); 37 | } 38 | 39 | vastTracker = new DMVAST.tracker(r.ads[0], r.ads[0].creatives[0]); 40 | vastTracker.on('start', () => console.log(getCurrentDate() + " Ad event: start")); 41 | vastTracker.on('pause', () => console.log(getCurrentDate() + " Ad event: pause")); 42 | vastTracker.on('resume', () => console.log(getCurrentDate() + " Ad event: resume")); 43 | vastTracker.on('mute', () => console.log(getCurrentDate() + " Ad event: mute")); 44 | vastTracker.on('unmute', () => console.log(getCurrentDate() + " Ad event: unmute")); 45 | vastTracker.on('skip', () => console.log(getCurrentDate() + " Ad event: skip")); 46 | vastTracker.on('clickthrough', url => console.log(getCurrentDate() + " Ad event: click")); 47 | vastTracker.on('complete', () => console.log(getCurrentDate() + " Ad event: complete")); 48 | vastTracker.on('firstQuartile', () => console.log(getCurrentDate() + " Ad event: firstQuartile")); 49 | vastTracker.on('midpoint', () => console.log(getCurrentDate() + " Ad event: midpoint")); 50 | vastTracker.on('thirdQuartile', () => console.log(getCurrentDate() + " Ad event: thirdQuartile")); 51 | vastTracker.on('fullscreen', () => console.log(getCurrentDate() + " Ad event: fullscreen")); 52 | vastTracker.on('exitFullscreen', () => console.log(getCurrentDate() + " Ad event: exitFullscreen")); 53 | vastTracker.on('creativeView', () => { 54 | console.log(getCurrentDate() + " Ad event: impression"); 55 | console.log(getCurrentDate() + " Ad event: creativeView"); 56 | }); 57 | 58 | for (let k in vastTracker.trackingEvents) { 59 | let re = /progress-\d*/; 60 | if (!k.search(re)) { 61 | progressEventsSeconds.push(parseInt(k.split('-')[1])); 62 | } 63 | } 64 | progressEventsSeconds.sort((a, b) => a - b); 65 | 66 | videoAd = r.ads[0].creatives[0].mediaFiles[0].fileURL; 67 | skipDelay = r.ads[0].creatives[0].skipDelay; 68 | clickLink = r.ads[0].creatives[0].videoClickThroughURLTemplate; 69 | 70 | console.log('loadvast'); 71 | resolve(); 72 | }); 73 | } 74 | } 75 | ); 76 | }; 77 | 78 | const fsEventOn = () => { 79 | player.on(Clappr.Events.PLAYER_FULLSCREEN, function () { 80 | isFullscreen = !isFullscreen; 81 | if (adVideoPlayNow) { 82 | vastTracker.setFullscreen(isFullscreen); 83 | // vastTracker.setExpand(isFullscreen); 84 | } 85 | }) 86 | }; 87 | 88 | const getCurrentDate = () => { 89 | let d = new Date(); 90 | return "(" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ") "; 91 | }; 92 | 93 | const setTypeVideo = (type) => { 94 | if (type == 'vod') { 95 | videoMainVod = true; 96 | } else if (type == 'live') { 97 | videoMainLive = true; 98 | } 99 | }; 100 | 101 | const getVideoSource = () => { 102 | if (preroll) { 103 | return videoAd; 104 | } else if (pauseroll) { 105 | return videoMain; 106 | } 107 | }; 108 | 109 | const setTypeAd = (type) => { 110 | adVideoPlayNow = false; 111 | preroll = false; 112 | pauseroll = false; 113 | 114 | if (type == 'preroll') { 115 | adVideoPlayNow = true; 116 | preroll = true; 117 | } else if (type == 'pauseroll') { 118 | pauseroll = true; 119 | } 120 | }; 121 | 122 | const _visibilityAPI = (function () { 123 | var stateKey, 124 | eventKey, 125 | keys = { 126 | hidden: "visibilitychange", 127 | webkitHidden: "webkitvisibilitychange", 128 | mozHidden: "mozvisibilitychange", 129 | msHidden: "msvisibilitychange" 130 | }; 131 | for (stateKey in keys) { 132 | if (stateKey in document) { 133 | eventKey = keys[stateKey]; 134 | break; 135 | } 136 | } 137 | return { 138 | 'setHandler': function (c) { 139 | if (c) document.addEventListener(eventKey, c); 140 | }, 141 | 'tabVisible': function () { 142 | return !document[stateKey]; 143 | } 144 | } 145 | })(); 146 | 147 | _visibilityAPI.setHandler(function () { 148 | if (adVideoPlayNow) { 149 | if (_visibilityAPI.tabVisible()) { 150 | setTimeout(function () { 151 | player.play(); 152 | }, 300); 153 | } else { 154 | player.pause(); 155 | } 156 | } 157 | }); 158 | 159 | let clapprAdVastPlugin = Clappr.UIContainerPlugin.extend({ 160 | name: 'clappr-vast-ad-plugin', 161 | version: '2.0', 162 | adMuted: false, 163 | videoWasComplited: false, 164 | 165 | initialize: function initialize() { 166 | this.render(); 167 | // this.checkAdTime(); 168 | }, 169 | 170 | render: function render() { 171 | this.$el.css('font-size', '20px'); 172 | this.$el.css('position', 'absolute'); 173 | this.$el.css('color', 'white'); 174 | this.$el.css('top', '70%'); 175 | this.$el.css('right', '0%'); 176 | this.$el.css('background-color', 'black'); 177 | this.$el.css('z-index', '100500'); 178 | this.$el.css('border', 'solid 3px #333333'); 179 | this.$el.css('padding', '5px'); 180 | this.container.$el.append(this.$el); 181 | this.$el[0].id = 'adButton'; 182 | 183 | if (preroll) { 184 | this.show(); 185 | } else if (pauseroll) { 186 | if (adVideoPlayNow) { 187 | this.show(); 188 | } else { 189 | this.hide(); 190 | } 191 | } 192 | return this; 193 | }, 194 | 195 | bindEvents: function bindEvents() { 196 | this.listenTo(this.container, Clappr.Events.CONTAINER_ENDED, this.containerEnded); 197 | this.listenTo(this.container, Clappr.Events.CONTAINER_PLAY, this.containerPlay); 198 | this.listenTo(this.container, Clappr.Events.CONTAINER_VOLUME, this.containerVolume); 199 | this.listenTo(this.container, Clappr.Events.CONTAINER_PAUSE, this.containerPause); 200 | this.listenTo(this.container, Clappr.Events.CONTAINER_CLICK, this.containerClick); 201 | }, 202 | 203 | containerClick: function () { 204 | if (adVideoPlayNow) { 205 | window.open(clickLink).focus(); 206 | vastTracker.click(); 207 | } else { 208 | player.pause(); 209 | } 210 | }, 211 | 212 | containerPause: function () { 213 | if (adVideoPlayNow && !player.ended) { 214 | vastTracker.setPaused(true); 215 | } 216 | // not activate 'play' event when pause 217 | else { 218 | player.pause(); 219 | pauseNow = true; 220 | } 221 | }, 222 | 223 | containerVolume: function () { 224 | if (adVideoPlayNow && player) { 225 | if (player.getVolume() == 0 && !this.AdMuted || player.getVolume() != 0 && this.AdMuted) { 226 | this.AdMuted = !this.AdMuted; 227 | vastTracker.setMuted(this.AdMuted); 228 | } 229 | } 230 | }, 231 | 232 | containerPlay: function () { 233 | mainVideoPlayNow ? this.hide() : null; 234 | player.core.mediaControl.container.settings.seekEnabled = !adVideoPlayNow; 235 | 236 | if (adVideoPlayNow) { 237 | this.checkAdTime(); 238 | this.show(); 239 | if (adFirstStart) { 240 | vastTracker.setProgress(0.1); 241 | vastTracker.load(); 242 | adFirstStart = false; 243 | } else { 244 | vastTracker.setPaused(false); 245 | } 246 | } else { 247 | this.hide(); 248 | } 249 | if (preroll) { 250 | if (this.videoWasComplited) { 251 | this.videoWasComplited = false; 252 | loadVAST(vastUrl).then(() => this.switchSource('va')); 253 | adVideoPlayNow = true; 254 | adFirstStart = true; 255 | // player.pause(); 256 | } 257 | 258 | } else if (pauseroll) { 259 | if (!adVideoPlayNow && pauseNow && player.isPlaying()) { 260 | pauseNow = false; 261 | if (videoMainVod) { 262 | videoCurrentTime = player.getCurrentTime(); 263 | } 264 | 265 | adFirstStart = true; 266 | loadVAST(vastUrl).then(() => this.switchSource('va')); 267 | this.show(); 268 | } 269 | } 270 | }, 271 | 272 | containerEnded: function () { 273 | pauseNow = false; 274 | 275 | if (adVideoPlayNow) { 276 | vastTracker.complete(); 277 | this.switchSource('av'); 278 | } else if (preroll) { 279 | this.videoWasComplited = true; 280 | } 281 | }, 282 | 283 | switchSource: function (type) { 284 | if (player != null) { 285 | let f, s; 286 | if (type == 'av') { 287 | adVideoPlayNow = false; 288 | f = videoAd; 289 | s = videoMain; 290 | } else if (type == 'va') { 291 | adVideoPlayNow = true; 292 | f = videoMain; 293 | s = videoAd; 294 | } 295 | let el = player.core.getCurrentPlayback().el; 296 | 297 | // let endListener = () => { 298 | // el.removeEventListener('ended', endListener); 299 | // el.src = f; 300 | // // el.load(); 301 | // el.play(); 302 | // }; 303 | 304 | el.src = s; 305 | // el.load(); 306 | 307 | // if (!pauseroll) { 308 | // el.addEventListener('ended', endListener); 309 | // } 310 | !sbPressed ? el.play() : null; 311 | 312 | if (type == 'av' && videoMainVod) { 313 | player.seek(videoCurrentTime); 314 | } 315 | } 316 | }, 317 | 318 | show: function () { 319 | const showAdButton = () => { 320 | this.$el.show(); 321 | let timerId = setInterval(() => { 322 | let ab = document.getElementById('adButton'); 323 | ab.textContent = 'You can skip this ad in ' + parseInt(skipDelay - player.getCurrentTime()); 324 | if (player.getCurrentTime() > skipDelay) { 325 | clearInterval(timerId); 326 | ab.onclick = () => { 327 | vastTracker.skip(); 328 | sbPressed = true; 329 | this.switchSource('av'); 330 | sbPressed = false; 331 | }; 332 | ab.textContent = 'Skip Ad'; 333 | } 334 | }, 300); 335 | }; 336 | if (preroll) { 337 | if (adVideoPlayNow) { 338 | showAdButton(); 339 | } else { 340 | this.hide(); 341 | } 342 | } else if (pauseroll) { 343 | showAdButton(); 344 | } 345 | }, 346 | 347 | hide: function () { 348 | this.$el.hide(); 349 | }, 350 | 351 | checkAdTime: function () { 352 | if (adVideoPlayNow) { 353 | let fq = false, mp = false, tq = false; 354 | let timerId = setInterval(function () { 355 | if (sbPressed) { 356 | clearInterval(timerId); 357 | } else { 358 | if (progressEventsSeconds.length && player.getCurrentTime() >= progressEventsSeconds[0]) { 359 | vastTracker.setProgress(progressEventsSeconds.shift()); 360 | console.log(getCurrentDate() + " Ad event: progress") 361 | } 362 | if (player.getCurrentTime() >= player.getDuration() * 0.25 && !fq) { 363 | vastTracker.setProgress(player.getCurrentTime()); 364 | fq = true; 365 | } else if (player.getCurrentTime() >= player.getDuration() * 0.5 && !mp) { 366 | vastTracker.setProgress(player.getCurrentTime()); 367 | mp = true; 368 | } else if (player.getCurrentTime() >= player.getDuration() * 0.75 && !tq) { 369 | vastTracker.setProgress(player.getCurrentTime()); 370 | tq = true; 371 | clearInterval(timerId); 372 | } 373 | } 374 | }, 300); 375 | } 376 | }, 377 | }); 378 | -------------------------------------------------------------------------------- /src/vast-example.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | GDFP 6 | External NCA1C1L1 LinearInlineSkippable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 00:00:10 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | http://localhost:8808/ad-event/expand 36 | http://localhost:8808/ad-event/collapse 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/vast_real.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AdFox IMHO Vi 5 | VAST Ad 6 | 7 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 37 | 38 | 39 | 42 | 43 | 44 | 47 | 48 | 49 | 50 | 51 | 00:00:25 52 | 53 | 54 | 57 | 58 | 59 | 62 | 63 | 64 | 67 | 68 | 69 | 72 | 73 | 74 | 77 | 78 | 79 | 82 | 83 | 84 | 87 | 88 | 89 | 92 | 93 | 94 | 97 | 98 | 99 | 102 | 103 | 104 | 107 | 108 | 109 | 112 | 113 | 114 | 117 | 118 | 119 | 122 | 123 | 124 | 127 | 128 | 129 | 132 | 133 | 134 | 135 | 136 | 137 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 156 | 157 | 158 | 161 | 162 | 163 | 166 | 167 | 168 | 171 | 172 | 173 | 176 | 177 | 178 | 181 | 182 | 183 | 186 | 187 | 188 | 191 | 192 | 193 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: ['./src/vastPlugin', './src/adPlugin'], 3 | watch: true, 4 | module: { 5 | loaders: [ 6 | { 7 | test: /\.js$/, 8 | loader: 'babel' 9 | } 10 | ] 11 | }, 12 | 13 | output: { 14 | filename: 'dist/clappr_ad_plugin.js', 15 | library: 'adPlugin' 16 | }, 17 | }; 18 | 19 | --------------------------------------------------------------------------------