import { ComponentInterface } from '@stencil/core' ; import { openWormhole } from 'stencil-wormhole' ; import { listen } from '../../../utils/dom' ; import { isUndefined } from '../../../utils/unit' ; import { findPlayer } from './findPlayer' ; import { getEventName } from './PlayerEvents' ; import { PlayerProp , PlayerProps } from './PlayerProps' ; param component param props export const withPlayerContext = ( component , props ) : void => openWormhole ( component , props ) ; param ref param props param updater export const usePlayerContext = async ( ref , props , updater , playerRef ? ) : Promise < ( ) => void > => { const player = playerRef ?? ( await findPlayer ( ref ) ) ; const listeners = ! isUndefined ( player ) ? props . map ( prop => { const event = getEventName ( prop ) ; return listen ( player , event , ( ) => { updater ( prop , player [ prop ] ) ; } ) ; } ) : [ ] ; return ( ) => { listeners . forEach ( off => off ( ) ) ; } ; } ;