UNPKG

@theoplayer/react-native-analytics-comscore

Version:
33 lines 1.1 kB
import { PlayerEventType } from 'react-native-theoplayer'; import { useEffect, useRef } from 'react'; import { ComscoreConnector } from '@theoplayer/react-native-analytics-comscore'; export function useComscore(metadata, config) { const connector = useRef(); const theoPlayer = useRef(); const initialize = player => { // Optionally destroy existent connector onDestroy(); theoPlayer.current = player; if (player) { connector.current = new ComscoreConnector(player, metadata, config); player.addEventListener(PlayerEventType.DESTROY, onDestroy); } else { throw new Error('Invalid THEOplayer instance'); } }; const onDestroy = () => { if (connector.current) { if (!theoPlayer.current) { throw new Error('Invalid THEOplayer instance'); } theoPlayer.current.removeEventListener(PlayerEventType.DESTROY, onDestroy); connector.current.destroy(); connector.current = undefined; } }; useEffect(() => { return onDestroy; }, []); return [connector, initialize]; } //# sourceMappingURL=useComscore.js.map