Last active
February 5, 2016 20:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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