Skip to content

Instantly share code, notes, and snippets.

@jramsahai
Last active February 5, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jramsahai/a13ab27abcc6969bfaa8 to your computer and use it in GitHub Desktop.
Save jramsahai/a13ab27abcc6969bfaa8 to your computer and use it in GitHub Desktop.
With the new Vidyard Events functionality, we're starting to see some fun, new use cases. In this example, we display a full screen event for a few seconds, then automatically dismiss it and resume video playback.
<!-- Include this below all other code in your event -->
<script type='text/javascript'>
window.addEventListener("message", function(event) {
var ctaId = window.frameElement.id.split('_')[1];
var playerId = window.frameElement.src.split('/');
playerId = playerId[playerId.length-3];
// only allow from domains that end in allowedDomains
if (!event.origin.match(/vidyard\.(dev|com)$/)) { return; }
if (typeof event.data !== 'string') { return; }
try {
var data = JSON.parse(event.data);
} catch (e) {
return;
}
if (typeof data.event !== 'string') { return; }
if (data.event !== 'showCta' || data.id !== parseInt(ctaId)) { return; }
// Start countdown to closing event
setTimeout(function() {
var playerData = {uuid: playerId, event: 'closeCta', id: ctaId,forceClose: true};
window.parent.postMessage(JSON.stringify(playerData), '*');
}, 3000);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment