UNPKG

@aigamo/nostalgic-diva

Version:

React function components for imperatively controlling embedded players (audio, Niconico, SoundCloud and YouTube) using refs.

3 lines (2 loc) 1.1 kB
"use strict";const t=require("react"),i=require("./index-vLjOJb_8.cjs");function v(){const e=t.useRef(!0);return e.current?(e.current=!1,!0):e.current}const d=(e,r)=>e===r;function q(e,r=d){const n=t.useRef(),u=t.useRef(e);return!v()&&!r(u.current,e)&&(n.current=u.current,u.current=e),n.current}const F=({logger:e,type:r,loadScript:n,playerFactory:u,onControllerChange:f,videoId:c,options:R,controllerFactory:P,children:h})=>{e.log(i.LogLevel.Debug,"PlayerContainer");const l=t.useRef(c),E=t.useRef(void 0),[a,m]=t.useState(),[o,y]=t.useState(i.nullPlayerController);t.useEffect(()=>{f?.(o)},[o,f]),t.useEffect(()=>{(n?.()??Promise.resolve()).then(()=>{u(E.current,l.current).then(s=>{m(s)})})},[n,u]),t.useEffect(()=>{if(a===void 0)return;const s=new i.PlayerController(e,r,a,R,P);return s.attach(l.current).then(()=>y(s)),()=>{s.detach().finally(()=>y(i.nullPlayerController))}},[e,r,n,a,R,P]);const C=q(c);return t.useEffect(()=>{C!==void 0&&o.loadVideo(c)},[C,c,o]),t.createElement(t.Fragment,null,h(E,l.current))};exports.PlayerContainer=F; //# sourceMappingURL=PlayerContainer-BUISWNY1.cjs.map