From a46332b09c5c118c7f232f3ecbbc3f1299d2a700 Mon Sep 17 00:00:00 2001 From: Nicolas Siver Date: Sat, 2 Dec 2017 08:36:55 -0500 Subject: [PATCH] add build with new return object API --- build/can-autoplay.js | 21 +++++---------------- build/can-autoplay.min.js | 6 +++--- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/build/can-autoplay.js b/build/can-autoplay.js index a15e978..a9e74c0 100644 --- a/build/can-autoplay.js +++ b/build/can-autoplay.js @@ -1,6 +1,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.canAutoplay = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o { @@ -11,10 +10,6 @@ function audio (options) { }) } -function getError () { - return error -} - function setupDefaultValues (options) { return Object.assign({muted: false, timeout: 250}, options) } @@ -25,29 +20,23 @@ function startPlayback ({muted, timeout}, elementCallback) { let timeoutId let sendOutput - error = null - element.muted = muted element.src = source return new Promise(resolve => { playResult = element.play() timeoutId = setTimeout(() => { - error = new Error(`Timeout ${timeout} ms has been reached`) - sendOutput(false) + sendOutput(false, new Error(`Timeout ${timeout} ms has been reached`)) }, timeout) - sendOutput = result => { + sendOutput = (result, error = null) => { clearTimeout(timeoutId) - resolve(result) + resolve({result, error}) } if (playResult !== undefined) { playResult .then(() => sendOutput(true)) - .catch(playError => { - error = playError - sendOutput(false) - }) + .catch(playError => sendOutput(false, playError)) } else { sendOutput(true) } @@ -63,7 +52,7 @@ function video (options) { }) } -module.exports = {audio, getError, video} +module.exports = {audio, video} },{"./media":2}],2:[function(require,module,exports){ module.exports = { diff --git a/build/can-autoplay.min.js b/build/can-autoplay.min.js index 93504d4..3f2ebb2 100644 --- a/build/can-autoplay.min.js +++ b/build/can-autoplay.min.js @@ -1,5 +1,5 @@ -'use strict';(function(d){typeof exports==="object"&&typeof module!=="undefined"?module.exports=d():typeof define==="function"&&define.amd?define([],d):(typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:this).canAutoplay=d()})(function(){var d;return function m(f,c,k){function e(b,a){if(!c[b]){if(!f[b]){var h=typeof require=="function"&&require;if(!a&&h)return h(b,true);if(g)return g(b,true);a=Error("Cannot find module '"+b+"'");throw a.code="MODULE_NOT_FOUND", -a;}a=c[b]={exports:{}};f[b][0].call(a.exports,function(a){var c=f[b][1][a];return e(c?c:a)},a,a.exports,m,f,c,k)}return c[b].exports}for(var g=typeof require=="function"&&require,l=0;l{d=h.play();f=setTimeout(()=>{g=Error(`Timeout ${b} ms has been reached`);e(false)},b);e=(b)=>{clearTimeout(f);a(b)};d!==void 0?d.then(()=>{return e(true)}).catch((a)=> -{g=a;e(false)}):e(true)})}const e=f("./media");let g=null;c.exports={audio:function a(b){return d(Object.assign({muted:false,timeout:250},b),()=>{return{element:document.createElement("audio"),source:e.AUDIO}})},getError:function a(){return g},video:function n(c){return d(Object.assign({muted:false,timeout:250},c),()=>{return{element:document.createElement("video"),source:e.VIDEO}})}}},{"./media":2}],2:[function(d,c,k){c.exports={AUDIO:"data:audio/mpeg;base64,/+MYxAAAAANIAUAAAASEEB/jwOFM/0MM/90b/+RhST//w4NFwOjf///PZu////9lns5GFDv//l9GlUIEEIAAAgIg8Ir/JGq3/+MYxDsLIj5QMYcoAP0dv9HIjUcH//yYSg+CIbkGP//8w0bLVjUP///3Z0x5QCAv/yLjwtGKTEFNRTMuOTeqqqqqqqqqqqqq/+MYxEkNmdJkUYc4AKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", +'use strict';(function(d){typeof exports==="object"&&typeof module!=="undefined"?module.exports=d():typeof define==="function"&&define.amd?define([],d):(typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:this).canAutoplay=d()})(function(){var d;return function k(e,g,h){function f(a,b){if(!g[a]){if(!e[a]){var c=typeof require=="function"&&require;if(!b&&c)return c(a,true);if(d)return d(a,true);b=Error("Cannot find module '"+a+"'");throw b.code="MODULE_NOT_FOUND", +b;}b=g[a]={exports:{}};e[a][0].call(b.exports,function(b){var c=e[a][1][b];return f(c?c:b)},b,b.exports,k,e,g,h)}return g[a].exports}for(var d=typeof require=="function"&&require,c=0;c{e=b.play();g=setTimeout(()=>{f(false,Error(`Timeout ${c} ms has been reached`))},c);f=(b,c=null)=>{clearTimeout(g);a({result:b,error:c})};e!==void 0?e.then(()=> +{return f(true)}).catch((a)=>{return f(false,a)}):f(true)})}const f=d("./media");g.exports={audio:function a(c){return e(Object.assign({muted:false,timeout:250},c),()=>{return{element:document.createElement("audio"),source:f.AUDIO}})},video:function b(a){return e(Object.assign({muted:false,timeout:250},a),()=>{return{element:document.createElement("video"),source:f.VIDEO}})}}},{"./media":2}],2:[function(e,d,h){d.exports={AUDIO:"data:audio/mpeg;base64,/+MYxAAAAANIAUAAAASEEB/jwOFM/0MM/90b/+RhST//w4NFwOjf///PZu////9lns5GFDv//l9GlUIEEIAAAgIg8Ir/JGq3/+MYxDsLIj5QMYcoAP0dv9HIjUcH//yYSg+CIbkGP//8w0bLVjUP///3Z0x5QCAv/yLjwtGKTEFNRTMuOTeqqqqqqqqqqqqq/+MYxEkNmdJkUYc4AKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", VIDEO:"data:video/mp4;base64,AAAAHGZ0eXBpc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