diff --git a/resources/embed/embed.js b/resources/embed/embed.js
--- a/resources/embed/embed.js
+++ b/resources/embed/embed.js
#
@@ -65,7 +65,58 @@ function embedBensPlayer(vidurl,vidtype){
#
// We then trigger the next steps in stages to make sure everything that needs to be loaded, is
#
- loadVJS(vidid,playerSettings);
#
+ getBensToken(vidid,playerSettings);
#
+function getBensToken(vidid,playerSettings){
#
+ // VID-10 Tokenisation support
#
+ var ref = encodeURIComponent(window.location.href);
#
+ var vurl = encodeURIComponent(playerSettings['vidurl']);
#
+ var url = "https://videos.bentasker.co.uk/token_endpoint?ref="+ref+"&vidpath="+vurl;
#
+ if (window.XMLHttpRequest){
#
+ // code for IE7+, Firefox, Chrome, Opera, Safari
#
+ xmlhttp=new XMLHttpRequest();
#
+ // code for IE6, IE5 (why am I still supporting these? Die... Die.... Die....
#
+ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
#
+ xmlhttp.onreadystatechange=function(){
#
+ if (xmlhttp.readyState==4){
#
+ if(xmlhttp.status==200){
#
+ // OK, we've got a token back, so now we need to deal with it
#
+ var j = JSON.parse(xmlhttp.responseText);
#
+ console.log("Failed to retrieve token for video");
#
+ embedFailedNotif(vidid)
#
+ // Append the token onto the URL
#
+ playerSettings['vidurl'] += '?t=' + encodeURIComponent(j['token']) + '&e=' + encodeURIComponent(j['exp']);
#
+ // Trigger the next stage of loading
#
+ loadVJS(vidid,playerSettings);
#
+ console.log("Failed to retrieve token for video");
#
+ // Should probably write an error code into the player rather than just dying
#
+ embedFailedNotif(vidid)
#
+ xmlhttp.open("GET",url,true);
#
@@ -112,7 +163,7 @@ function writePlayer(vidid,playerSettings){
#
s.setAttribute('type','text/javascript');
#
ss = "window.player" + vidid +" = videojs('BensVideo" + vidid + "',\"{'fluid':true}\", function onPlayerReady(){console.log('Player Ready');});";
#
- ss += "window.player" + vidid + ".on('playing', function() { var i = document.createElement('img'); i.src = 'https://piwik.bentasker.co.uk/piwik.php?idsite=10&rec=1&new_visit=1&url=' + encodeURIComponent(window.player" + vidid+ ".currentSrc()) + '&urlref=' + encodeURIComponent(window.location.href); i.style='border:0';document.body.appendChild(i);});";
#
+ ss += "window.player" + vidid + ".on('playing', function() { var i = document.createElement('img'); i.src = 'https://piwik.bentasker.co.uk/piwik.php?idsite=10&rec=1&new_visit=1&url=' + encodeURIComponent(window.player" + vidid+ ".currentSrc().split('?')[0]) + '&urlref=' + encodeURIComponent(window.location.href); i.style='border:0';document.body.appendChild(i);});";
#
@@ -174,6 +225,18 @@ function fetchPage(url,callback,errcallback,storage){
#
+function embedFailedNotif(vidid){
#
+ s.setAttribute('src','https://videos.bentasker.co.uk/resources/embed/failed.png');
#
+ var c = document.getElementById('BensplayerWrapper'+vidid);
#
+ var width = c.parentNode.clientWidth
#
+ s.setAttribute('style','max-width: ' + width + 'px');
#
function BenswriteSchemaOrg(text,storage,url){