UNPKG

video-ad-sdk

Version:

VAST/VPAID SDK that allows video ads to be played on top of any player

22 lines (21 loc) 820 B
import { linearEvents } from '../../../../tracker'; import { volumeChanged } from '../../../adUnitEvents'; const { mute, unmute } = linearEvents; const isMuted = (videoElement) => videoElement.muted || videoElement.volume === 0; export const onVolumeChange = ({ videoElement }, callback) => { let wasMuted = isMuted(videoElement); const volumechangeHandler = () => { callback(volumeChanged); if (wasMuted && !isMuted(videoElement)) { callback(unmute); } else if (!wasMuted && isMuted(videoElement)) { callback(mute); } wasMuted = isMuted(videoElement); }; videoElement.addEventListener('volumechange', volumechangeHandler); return () => { videoElement.removeEventListener('volumechange', volumechangeHandler); }; };