Socket
Socket
Sign inDemoInstall

react-use-audio-player

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-audio-player - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

26

dist/react-use-audio-player.cjs.development.js

@@ -22,2 +22,14 @@ 'use strict';

}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}

@@ -63,3 +75,3 @@ var ActionTypes = {

volume: howl.volume(),
muted: false,
muted: howl.mute(),
playing: playing,

@@ -250,2 +262,3 @@ paused: !playing,

var _excluded = ["initialVolume", "initialRate", "initialMute"];
var HowlInstanceManager = /*#__PURE__*/function () {

@@ -276,3 +289,12 @@ function HowlInstanceManager() {

this.options = options;
var newHowl = new howler.Howl(options);
var _this$options = this.options,
initialVolume = _this$options.initialVolume,
initialRate = _this$options.initialRate,
initialMute = _this$options.initialMute,
rest = _objectWithoutPropertiesLoose(_this$options, _excluded);
var newHowl = new howler.Howl(_extends({
mute: initialMute,
volume: initialVolume,
rate: initialRate
}, rest));
this.callbacks.forEach(function (cb) {

@@ -279,0 +301,0 @@ return cb({

2

dist/react-use-audio-player.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),o=require("howler");function t(){return(t=Object.assign?Object.assign.bind():function(e){for(var o=1;o<arguments.length;o++){var t=arguments[o];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function n(e){if(void 0===e)return{src:null,isReady:!1,looping:!1,duration:0,rate:1,volume:1,muted:!1,playing:!1,paused:!1,stopped:!1,error:null};var o=e.seek(),t=e.playing();return{isReady:"loaded"===e.state(),src:e._src,looping:e.loop(),duration:e.duration(),rate:e.rate(),volume:e.volume(),muted:!1,playing:t,paused:!t,stopped:!t&&0===o,error:null}}function l(e,o){switch(o.type){case"START_LOAD":return e;case"ON_LOAD":return"unloaded"===o.howl.state()?e:n(o.howl);case"ON_ERROR":return t({},n(),{error:o.message});case"ON_PLAY":return t({},e,{playing:!0,paused:!1,stopped:!1});case"ON_PAUSE":return t({},e,{playing:!1,paused:!0});case"ON_STOP":return t({},e,{playing:!1,paused:!1,stopped:!0});case"ON_END":return t({},e,{playing:e.looping,stopped:!e.looping});case"ON_MUTE":var l;return t({},e,{muted:null!==(l=o.howl.mute())&&void 0!==l&&l});case"ON_RATE":var r,u;return t({},e,{rate:null!==(r=null===(u=o.howl)||void 0===u?void 0:u.rate())&&void 0!==r?r:1});case"ON_VOLUME":var a,i;return t({},e,{volume:null!==(a=null===(i=o.howl)||void 0===i?void 0:i.volume())&&void 0!==a?a:1});case"ON_LOOP":var s=o.toggleValue,c=void 0!==s&&s;return o.howl.loop(c),t({},e,{looping:c});default:return e}}function r(o,t){var n=t[0],l=t[1],r=e.useCallback((function(){var e=o.getHowl();l({type:"ON_LOAD",howl:e})}),[l,o]),u=e.useCallback((function(e,o){l({type:"ON_ERROR",message:o})}),[l]),a=e.useCallback((function(){var e=o.getHowl();l({type:"ON_PLAY",howl:e})}),[l,o]),i=e.useCallback((function(){var e=o.getHowl();l({type:"ON_PAUSE",howl:e})}),[l,o]),s=e.useCallback((function(){var e=o.getHowl();l({type:"ON_END",howl:e})}),[l,o]),c=e.useCallback((function(){var e=o.getHowl();l({type:"ON_STOP",howl:e})}),[l,o]),f=e.useCallback((function(){var e=o.getHowl();l({type:"ON_MUTE",howl:e})}),[l,o]),v=e.useCallback((function(){var e=o.getHowl();l({type:"ON_VOLUME",howl:e})}),[l,o]),p=e.useCallback((function(){var e=o.getHowl();l({type:"ON_RATE",howl:e})}),[l,o]);return e.useEffect((function(){return function(){var e=o.getHowl();null==e||e.off("loaderror",u),null==e||e.off("playerror",u),null==e||e.off("play",a),null==e||e.off("pause",i),null==e||e.off("end",s),null==e||e.off("stop",c),null==e||e.off("mute",f),null==e||e.off("volume",v),null==e||e.off("rate",p)}}),[]),[n,e.useRef((function(e){if("START_LOAD"===e.type){var o=e.howl;o.once("load",r),o.on("loaderror",u),o.on("playerror",u),o.on("play",a),o.on("pause",i),o.on("end",s),o.on("stop",c),o.on("mute",f),o.on("volume",v),o.on("rate",p)}l(e)})).current]}var u=function(){function e(){this.callbacks=new Map,this.howl=void 0,this.options={},this.subscriptionIndex=0}var t=e.prototype;return t.subscribe=function(e){var o=(this.subscriptionIndex++).toString();return this.callbacks.set(o,e),o},t.unsubscribe=function(e){this.callbacks.delete(e)},t.getHowl=function(){return this.howl},t.getNumberOfConnections=function(){return this.callbacks.size},t.createHowl=function(e){this.destroyHowl(),this.options=e;var t=new o.Howl(e);return this.callbacks.forEach((function(e){return e({type:"START_LOAD",howl:t})})),this.howl=t,t},t.destroyHowl=function(){var e,o,t,n,l,r;this.options.onload&&(null===(o=this.howl)||void 0===o||o.off("load",this.options.onload)),this.options.onend&&(null===(t=this.howl)||void 0===t||t.off("end",this.options.onend)),this.options.onplay&&(null===(n=this.howl)||void 0===n||n.off("play",this.options.onplay)),this.options.onpause&&(null===(l=this.howl)||void 0===l||l.off("pause",this.options.onpause)),this.options.onstop&&(null===(r=this.howl)||void 0===r||r.off("stop",this.options.onstop)),null===(e=this.howl)||void 0===e||e.unload()},t.broadcast=function(e){this.callbacks.forEach((function(o){return o(e)}))},e}(),a=function(){function e(){}return e.getInstance=function(){return void 0===this.instance&&(e.instance=new u),e.instance},e}();a.instance=void 0,exports.useAudioPlayer=function(){var o=e.useRef(new u),a=r(o.current,e.useReducer(l,o.current.getHowl(),n)),i=a[0],s=a[1];e.useEffect((function(){return function(){o.current.destroyHowl()}}),[]);var c=e.useCallback((function(){for(var e=arguments.length,n=new Array(e),l=0;l<e;l++)n[l]=arguments[l];var r=n[0],u=n[1],a=void 0===u?{}:u,i=o.current.createHowl(t({src:r},a));s({type:"START_LOAD",howl:i})}),[]),f=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.seek(e)}),[]),v=e.useCallback((function(){var e,t=o.current.getHowl();return void 0===t?0:null!==(e=t.seek())&&void 0!==e?e:0}),[]),p=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.play()}),[]),d=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.pause()}),[]),w=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&(i.playing?e.pause():e.play())}),[i]),g=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.stop()}),[]),h=e.useCallback((function(e,t,n){var l=o.current.getHowl();void 0!==l&&l.fade(e,t,n)}),[]),b=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.rate(e)}),[]),y=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.volume(e)}),[]),O=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.mute(e)}),[]),k=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&s({type:"ON_LOOP",howl:t,toggleValue:e})}),[]);return t({},i,{load:c,seek:f,getPosition:v,play:p,pause:d,togglePlayPause:w,stop:g,mute:O,fade:h,setRate:b,setVolume:y,loop:k})},exports.useGlobalAudioPlayer=function(){var o=e.useRef(a.getInstance()),u=r(o.current,e.useReducer(l,o.current.getHowl(),n)),i=u[0],s=u[1];e.useEffect((function(){var e=o.current.getHowl();void 0!==e&&(s({type:"START_LOAD",howl:e}),"loaded"===e.state()&&s({type:"ON_LOAD",howl:e}));var t=o.current.subscribe((function(e){s(e)}));return function(){o.current.unsubscribe(t)}}),[]);var c=e.useCallback((function(){for(var e=arguments.length,n=new Array(e),l=0;l<e;l++)n[l]=arguments[l];var r=n[0],u=n[1],a=void 0===u?{}:u;o.current.createHowl(t({src:r},a))}),[]),f=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.seek(e)}),[]),v=e.useCallback((function(){var e,t=o.current.getHowl();return void 0===t?0:null!==(e=t.seek())&&void 0!==e?e:0}),[]),p=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.play()}),[]),d=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.pause()}),[]),w=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&(i.playing?e.pause():e.play())}),[i]),g=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.stop()}),[]),h=e.useCallback((function(e,t,n){var l=o.current.getHowl();void 0!==l&&l.fade(e,t,n)}),[]),b=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.rate(e)}),[]),y=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.volume(e)}),[]),O=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.mute(e)}),[]),k=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&o.current.broadcast({type:"ON_LOOP",howl:t,toggleValue:e})}),[]);return t({},i,{load:c,seek:f,getPosition:v,play:p,pause:d,togglePlayPause:w,stop:g,mute:O,fade:h,setRate:b,setVolume:y,loop:k})};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("howler");function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e}).apply(this,arguments)}function n(e){if(void 0===e)return{src:null,isReady:!1,looping:!1,duration:0,rate:1,volume:1,muted:!1,playing:!1,paused:!1,stopped:!1,error:null};var t=e.seek(),o=e.playing();return{isReady:"loaded"===e.state(),src:e._src,looping:e.loop(),duration:e.duration(),rate:e.rate(),volume:e.volume(),muted:e.mute(),playing:o,paused:!o,stopped:!o&&0===t,error:null}}function l(e,t){switch(t.type){case"START_LOAD":return e;case"ON_LOAD":return"unloaded"===t.howl.state()?e:n(t.howl);case"ON_ERROR":return o({},n(),{error:t.message});case"ON_PLAY":return o({},e,{playing:!0,paused:!1,stopped:!1});case"ON_PAUSE":return o({},e,{playing:!1,paused:!0});case"ON_STOP":return o({},e,{playing:!1,paused:!1,stopped:!0});case"ON_END":return o({},e,{playing:e.looping,stopped:!e.looping});case"ON_MUTE":var l;return o({},e,{muted:null!==(l=t.howl.mute())&&void 0!==l&&l});case"ON_RATE":var r,u;return o({},e,{rate:null!==(r=null===(u=t.howl)||void 0===u?void 0:u.rate())&&void 0!==r?r:1});case"ON_VOLUME":var a,i;return o({},e,{volume:null!==(a=null===(i=t.howl)||void 0===i?void 0:i.volume())&&void 0!==a?a:1});case"ON_LOOP":var s=t.toggleValue,c=void 0!==s&&s;return t.howl.loop(c),o({},e,{looping:c});default:return e}}function r(t,o){var n=o[0],l=o[1],r=e.useCallback((function(){var e=t.getHowl();l({type:"ON_LOAD",howl:e})}),[l,t]),u=e.useCallback((function(e,t){l({type:"ON_ERROR",message:t})}),[l]),a=e.useCallback((function(){var e=t.getHowl();l({type:"ON_PLAY",howl:e})}),[l,t]),i=e.useCallback((function(){var e=t.getHowl();l({type:"ON_PAUSE",howl:e})}),[l,t]),s=e.useCallback((function(){var e=t.getHowl();l({type:"ON_END",howl:e})}),[l,t]),c=e.useCallback((function(){var e=t.getHowl();l({type:"ON_STOP",howl:e})}),[l,t]),f=e.useCallback((function(){var e=t.getHowl();l({type:"ON_MUTE",howl:e})}),[l,t]),v=e.useCallback((function(){var e=t.getHowl();l({type:"ON_VOLUME",howl:e})}),[l,t]),p=e.useCallback((function(){var e=t.getHowl();l({type:"ON_RATE",howl:e})}),[l,t]);return e.useEffect((function(){return function(){var e=t.getHowl();null==e||e.off("loaderror",u),null==e||e.off("playerror",u),null==e||e.off("play",a),null==e||e.off("pause",i),null==e||e.off("end",s),null==e||e.off("stop",c),null==e||e.off("mute",f),null==e||e.off("volume",v),null==e||e.off("rate",p)}}),[]),[n,e.useRef((function(e){if("START_LOAD"===e.type){var t=e.howl;t.once("load",r),t.on("loaderror",u),t.on("playerror",u),t.on("play",a),t.on("pause",i),t.on("end",s),t.on("stop",c),t.on("mute",f),t.on("volume",v),t.on("rate",p)}l(e)})).current]}var u=["initialVolume","initialRate","initialMute"],a=function(){function e(){this.callbacks=new Map,this.howl=void 0,this.options={},this.subscriptionIndex=0}var n=e.prototype;return n.subscribe=function(e){var t=(this.subscriptionIndex++).toString();return this.callbacks.set(t,e),t},n.unsubscribe=function(e){this.callbacks.delete(e)},n.getHowl=function(){return this.howl},n.getNumberOfConnections=function(){return this.callbacks.size},n.createHowl=function(e){this.destroyHowl(),this.options=e;var n=this.options,l=n.initialVolume,r=n.initialRate,a=n.initialMute,i=function(e,t){if(null==e)return{};var o,n,l={},r=Object.keys(e);for(n=0;n<r.length;n++)t.indexOf(o=r[n])>=0||(l[o]=e[o]);return l}(n,u),s=new t.Howl(o({mute:a,volume:l,rate:r},i));return this.callbacks.forEach((function(e){return e({type:"START_LOAD",howl:s})})),this.howl=s,s},n.destroyHowl=function(){var e,t,o,n,l,r;this.options.onload&&(null===(t=this.howl)||void 0===t||t.off("load",this.options.onload)),this.options.onend&&(null===(o=this.howl)||void 0===o||o.off("end",this.options.onend)),this.options.onplay&&(null===(n=this.howl)||void 0===n||n.off("play",this.options.onplay)),this.options.onpause&&(null===(l=this.howl)||void 0===l||l.off("pause",this.options.onpause)),this.options.onstop&&(null===(r=this.howl)||void 0===r||r.off("stop",this.options.onstop)),null===(e=this.howl)||void 0===e||e.unload()},n.broadcast=function(e){this.callbacks.forEach((function(t){return t(e)}))},e}(),i=function(){function e(){}return e.getInstance=function(){return void 0===this.instance&&(e.instance=new a),e.instance},e}();i.instance=void 0,exports.useAudioPlayer=function(){var t=e.useRef(new a),u=r(t.current,e.useReducer(l,t.current.getHowl(),n)),i=u[0],s=u[1];e.useEffect((function(){return function(){t.current.destroyHowl()}}),[]);var c=e.useCallback((function(){for(var e=arguments.length,n=new Array(e),l=0;l<e;l++)n[l]=arguments[l];var r=n[0],u=n[1],a=void 0===u?{}:u,i=t.current.createHowl(o({src:r},a));s({type:"START_LOAD",howl:i})}),[]),f=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.seek(e)}),[]),v=e.useCallback((function(){var e,o=t.current.getHowl();return void 0===o?0:null!==(e=o.seek())&&void 0!==e?e:0}),[]),p=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.play()}),[]),d=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.pause()}),[]),w=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&(i.playing?e.pause():e.play())}),[i]),g=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.stop()}),[]),h=e.useCallback((function(e,o,n){var l=t.current.getHowl();void 0!==l&&l.fade(e,o,n)}),[]),b=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.rate(e)}),[]),y=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.volume(e)}),[]),O=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.mute(e)}),[]),k=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&s({type:"ON_LOOP",howl:o,toggleValue:e})}),[]);return o({},i,{load:c,seek:f,getPosition:v,play:p,pause:d,togglePlayPause:w,stop:g,mute:O,fade:h,setRate:b,setVolume:y,loop:k})},exports.useGlobalAudioPlayer=function(){var t=e.useRef(i.getInstance()),u=r(t.current,e.useReducer(l,t.current.getHowl(),n)),a=u[0],s=u[1];e.useEffect((function(){var e=t.current.getHowl();void 0!==e&&(s({type:"START_LOAD",howl:e}),"loaded"===e.state()&&s({type:"ON_LOAD",howl:e}));var o=t.current.subscribe((function(e){s(e)}));return function(){t.current.unsubscribe(o)}}),[]);var c=e.useCallback((function(){for(var e=arguments.length,n=new Array(e),l=0;l<e;l++)n[l]=arguments[l];var r=n[0],u=n[1],a=void 0===u?{}:u;t.current.createHowl(o({src:r},a))}),[]),f=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.seek(e)}),[]),v=e.useCallback((function(){var e,o=t.current.getHowl();return void 0===o?0:null!==(e=o.seek())&&void 0!==e?e:0}),[]),p=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.play()}),[]),d=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.pause()}),[]),w=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&(a.playing?e.pause():e.play())}),[a]),g=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.stop()}),[]),h=e.useCallback((function(e,o,n){var l=t.current.getHowl();void 0!==l&&l.fade(e,o,n)}),[]),b=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.rate(e)}),[]),y=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.volume(e)}),[]),O=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.mute(e)}),[]),k=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&t.current.broadcast({type:"ON_LOOP",howl:o,toggleValue:e})}),[]);return o({},a,{load:c,seek:f,getPosition:v,play:p,pause:d,togglePlayPause:w,stop:g,mute:O,fade:h,setRate:b,setVolume:y,loop:k})};
//# sourceMappingURL=react-use-audio-player.cjs.production.min.js.map

@@ -18,2 +18,14 @@ import { useCallback, useEffect, useRef, useReducer } from 'react';

}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}

@@ -59,3 +71,3 @@ var ActionTypes = {

volume: howl.volume(),
muted: false,
muted: howl.mute(),
playing: playing,

@@ -246,2 +258,3 @@ paused: !playing,

var _excluded = ["initialVolume", "initialRate", "initialMute"];
var HowlInstanceManager = /*#__PURE__*/function () {

@@ -272,3 +285,12 @@ function HowlInstanceManager() {

this.options = options;
var newHowl = new Howl(options);
var _this$options = this.options,
initialVolume = _this$options.initialVolume,
initialRate = _this$options.initialRate,
initialMute = _this$options.initialMute,
rest = _objectWithoutPropertiesLoose(_this$options, _excluded);
var newHowl = new Howl(_extends({
mute: initialMute,
volume: initialVolume,
rate: initialRate
}, rest));
this.callbacks.forEach(function (cb) {

@@ -275,0 +297,0 @@ return cb({

@@ -27,3 +27,3 @@ import { AudioPlayerState } from "./audioPlayerState";

initialVolume?: number;
initialMute?: number;
initialMute?: boolean;
initialRate?: number;

@@ -30,0 +30,0 @@ format?: string;

{
"name": "react-use-audio-player",
"version": "2.0.0",
"version": "2.0.1",
"description": "React hook for building custom audio playback controls",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc