From a71c6150effb826213cbf477e2485d0e0e261f67 Mon Sep 17 00:00:00 2001 From: Olivier Lando Date: Tue, 2 Feb 2021 09:28:19 +0100 Subject: [PATCH] Use promises in SDK, add some tests --- .npmignore | 6 + CHANGELOG.md | 4 + README.md | 19 +- dist/index.d.ts | 12 +- dist/index.js | 2 +- index.ts | 121 +- package-lock.json | 10621 +++++++++++++++++++++++++++++++++++++++---- package.json | 29 +- test/index.test.ts | 81 + tsconfig.json | 1 + tslint.json | 9 + webpack.config.js | 4 +- 12 files changed, 9988 insertions(+), 921 deletions(-) create mode 100644 .npmignore create mode 100644 test/index.test.ts create mode 100644 tslint.json diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..2f5c8e1 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +tsconfig.json +tslint.json +webpack.config.js +node_modules +test +dist/test \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b1b46f7..f17efd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog All changes to this project will be documented in this file. +## [1.2.2] - 2021-02-02 +- getPaused, getMuted, getDuration, getCurrentTime, getVolume and getLoop now return promises +- Add some unit test + ## [1.2.1] - 2021-01-15 - Add the possibility to specify metadata \ No newline at end of file diff --git a/README.md b/README.md index f7d2900..6a1d4a8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ![](https://github.com/apivideo/API_OAS_file/blob/master/apivideo_banner.png) -# player-sdk +# api.video player SDK + SDK to control and interact with the api.video HTML5 Player # SDK usage @@ -28,14 +29,12 @@ And then include the SDK with a simple `import { PlayerSdk } from '@api.video/pl ## Simple include in a javascript project -Download [the SDK from the github repository](https://github.com/apivideo/player-sdk) - Include the SDK in your HTML file like so: ```html ... - + ``` @@ -96,17 +95,17 @@ Example: player.volume(0.75); // Set the volume to 75% ``` -#### `getPaused(callback: (paused: Boolean) => void)` +#### `getPaused(callback?: (paused: boolean) => void): Promise` Check weither the video is paused. -#### `getMuted(callback: (muted: Boolean) => void)` +#### `getMuted(callback?: (muted: boolean) => void): Promise` Check weither the video is muted. -#### `getDuration(callback: (duration: Number) => void)` +#### `getDuration(callback?: (duration: number) => void): Promise` Retrieve the duration of the video. -#### `getCurrentTime(callback: (currentTime: Number) => void)` +#### `getCurrentTime(callback?: (currentTime: number) => void): Promise` Retrieve the current playback time of the video. -#### `getVolume(callback: (volume: Number) => void)` +#### `getVolume(callback?: (volume: number) => void): Promise` Retrieve the current volume. -#### `getLoop(callback: (loop: Boolean) => void)` +#### `getLoop(callback?: (loop: boolean) => void): Promise` Check weither the video is in loop mode. #### `destroy()` diff --git a/dist/index.d.ts b/dist/index.d.ts index c3d399a..2a36048 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -23,12 +23,12 @@ export declare class PlayerSdk { setCurrentTime(time: number): void; setVolume(volume: number): void; setLoop(loop: boolean): void; - getPaused(callback: (paused: Boolean) => void): void; - getMuted(callback: (muted: Boolean) => void): void; - getDuration(callback: (duration: Number) => void): void; - getCurrentTime(callback: (currentTime: Number) => void): void; - getVolume(callback: (volume: Number) => void): void; - getLoop(callback: (loop: Boolean) => void): void; + getPaused(callback?: (paused: boolean) => void): Promise; + getMuted(callback?: (muted: boolean) => void): Promise; + getDuration(callback?: (duration: number) => void): Promise; + getCurrentTime(callback?: (currentTime: number) => void): Promise; + getVolume(callback?: (volume: number) => void): Promise; + getLoop(callback?: (loop: boolean) => void): Promise; addEventListener(event: string, callback: () => void): void; destroy(): void; private urlParametersFromOptions; diff --git a/dist/index.js b/dist/index.js index 9661456..cd55d22 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){r(1),e.exports=r(3)},function(e,t,r){(function(e){!function(e){var t=function(){try{return!!Symbol.iterator}catch(e){return!1}}(),r=function(e){var r={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return t&&(r[Symbol.iterator]=function(){return r}),r},n=function(e){return encodeURIComponent(e).replace(/%20/g,"+")},o=function(e){return decodeURIComponent(String(e).replace(/\+/g," "))};(function(){try{var t=e.URLSearchParams;return"a=1"===new t("?a=1").toString()&&"function"==typeof t.prototype.set&&"function"==typeof t.prototype.entries}catch(e){return!1}})()||function(){var o=function(e){Object.defineProperty(this,"_entries",{writable:!0,value:{}});var t=typeof e;if("undefined"===t);else if("string"===t)""!==e&&this._fromString(e);else if(e instanceof o){var r=this;e.forEach((function(e,t){r.append(t,e)}))}else{if(null===e||"object"!==t)throw new TypeError("Unsupported input's type for URLSearchParams");if("[object Array]"===Object.prototype.toString.call(e))for(var n=0;nt[0]?1:0})),e._entries&&(e._entries={});for(var r=0;r1?o(n[1]):"")}})}(void 0!==e?e:"undefined"!=typeof window?window:"undefined"!=typeof self?self:this),function(e){if(function(){try{var t=new e.URL("b","http://a");return t.pathname="c d","http://a/c%20d"===t.href&&t.searchParams}catch(e){return!1}}()||function(){var t=e.URL,r=function(t,r){"string"!=typeof t&&(t=String(t)),r&&"string"!=typeof r&&(r=String(r));var n,o=document;if(r&&(void 0===e.location||r!==e.location.href)){r=r.toLowerCase(),(n=(o=document.implementation.createHTMLDocument("")).createElement("base")).href=r,o.head.appendChild(n);try{if(0!==n.href.indexOf(r))throw new Error(n.href)}catch(e){throw new Error("URL unable to set base "+r+" due to "+e)}}var i=o.createElement("a");i.href=t,n&&(o.body.appendChild(i),i.href=i.href);var a=o.createElement("input");if(a.type="url",a.value=t,":"===i.protocol||!/:/.test(i.href)||!a.checkValidity()&&!r)throw new TypeError("Invalid URL");Object.defineProperty(this,"_anchorElement",{value:i});var s=new e.URLSearchParams(this.search),c=!0,u=!0,f=this;["append","delete","set"].forEach((function(e){var t=s[e];s[e]=function(){t.apply(s,arguments),c&&(u=!1,f.search=s.toString(),u=!0)}})),Object.defineProperty(this,"searchParams",{value:s,enumerable:!0});var h=void 0;Object.defineProperty(this,"_updateSearchParams",{enumerable:!1,configurable:!1,writable:!1,value:function(){this.search!==h&&(h=this.search,u&&(c=!1,this.searchParams._fromString(this.search),c=!0))}})},n=r.prototype;["hash","host","hostname","port","protocol"].forEach((function(e){!function(e){Object.defineProperty(n,e,{get:function(){return this._anchorElement[e]},set:function(t){this._anchorElement[e]=t},enumerable:!0})}(e)})),Object.defineProperty(n,"search",{get:function(){return this._anchorElement.search},set:function(e){this._anchorElement.search=e,this._updateSearchParams()},enumerable:!0}),Object.defineProperties(n,{toString:{get:function(){var e=this;return function(){return e.href}}},href:{get:function(){return this._anchorElement.href.replace(/\?$/,"")},set:function(e){this._anchorElement.href=e,this._updateSearchParams()},enumerable:!0},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(e){this._anchorElement.pathname=e},enumerable:!0},origin:{get:function(){var e={"http:":80,"https:":443,"ftp:":21}[this._anchorElement.protocol],t=this._anchorElement.port!=e&&""!==this._anchorElement.port;return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(t?":"+this._anchorElement.port:"")},enumerable:!0},password:{get:function(){return""},set:function(e){},enumerable:!0},username:{get:function(){return""},set:function(e){},enumerable:!0}}),r.createObjectURL=function(e){return t.createObjectURL.apply(t,arguments)},r.revokeObjectURL=function(e){return t.revokeObjectURL.apply(t,arguments)},e.URL=r}(),void 0!==e.location&&!("origin"in e.location)){var t=function(){return e.location.protocol+"//"+e.location.hostname+(e.location.port?":"+e.location.port:"")};try{Object.defineProperty(e.location,"origin",{get:t,enumerable:!0})}catch(r){setInterval((function(){e.location.origin=t()}),100)}}}(void 0!==e?e:"undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}).call(this,r(2))},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;rl;l++)if((v=O(t[l]))&&v instanceof s)return v;return new s(!1)}f=p.call(t)}for(d=f.next;!(y=d.call(f)).done;){try{v=O(y.value)}catch(t){throw u(f),t}if("object"==typeof v&&v&&v instanceof s)return v}return new s(!1)}},function(t,e,n){"use strict";var r=n(12),o=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=r(e),this.reject=r(n)};t.exports.f=function(t){return new o(t)}},function(t,e,n){var r=n(9),o=n(63),i=n(15),a=n(16),c=n(39),u=n(3),s=n(40),f=Object.getOwnPropertyDescriptor;e.f=r?f:function(t,e){if(t=a(t),e=c(e,!0),s)try{return f(t,e)}catch(t){}if(u(t,e))return i(!o.f.call(t,e),t[e])}},function(t,e){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},function(t,e){t.exports=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){var r=n(0),o=n(6),i=r.document,a=o(i)&&o(i.createElement);t.exports=function(t){return a?i.createElement(t):{}}},function(t,e,n){var r=n(0),o=n(5);t.exports=function(t,e){try{o(r,t,e)}catch(n){r[t]=e}return e}},function(t,e,n){var r=n(26),o=Function.toString;"function"!=typeof r.inspectSource&&(r.inspectSource=function(t){return o.call(t)}),t.exports=r.inspectSource},function(t,e,n){var r=n(0),o=n(24),i=r["__core-js_shared__"]||o("__core-js_shared__",{});t.exports=i},function(t,e,n){var r=n(41),o=n(42),i=r("keys");t.exports=function(t){return i[t]||(i[t]=o(t))}},function(t,e){t.exports={}},function(t,e){var n=Math.ceil,r=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?r:n)(t)}},function(t,e){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},function(t,e,n){var r=n(3),o=n(72),i=n(27),a=n(73),c=i("IE_PROTO"),u=Object.prototype;t.exports=a?Object.getPrototypeOf:function(t){return t=o(t),r(t,c)?t[c]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?u:null}},function(t,e,n){var r,o=n(4),i=n(75),a=n(30),c=n(28),u=n(48),s=n(23),f=n(27),p=f("IE_PROTO"),l=function(){},h=function(t){return"