$(document).ready(function() { window.onload = function() { $(document).on('keydown', function(e) { switch(e.which){ //w case 87: if(window._vtLogicController.lastConfirmedContent != ""){ var matchData = window._vtStorageController.getEvent(window._vtLogicController.lastConfirmedContent); var intops = matchData.intops; for(var i=0; i < intops.length; i++){ if (intops[i].type === 'metadata') { if (intops[i].metadata.type !== 'ad') { window._vtAPI.sendIntopToClient(intops[i]); } } } } break; case 81: //q var blurIntop = {'type': 'blur', 'start_pos': '0', 'end_pos': '20'}; window._vtAPI.sendIntopToClient(blurIntop); break; case 69: //e var intop = {"type": "purchase", "theme": "pizzahut", "text": "Does this scene make you hungry?", "logo": "assets/pizzahut.svg", "image_url": "http://i.imgur.com/Iq81zPM.gif", "text_expanded1": "Pepperoni Lover's", "text_expanded2": "Order now for $14.99", "tabs": [{ "name": "Pizza", "items": [{"description": "SUPREME", "price": "$14.99", "item_url": "http://imgur.com/W43VcYQ.png"} ,{"description": "BBQ LOVERS", "price": "$14.99", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/BBQ_Lovers_PIzza.png"} ,{"description": "MEAT LOVER'S", "price": "$14.99", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/Classic_Meat_Lovers_Pizza.png"} ,{"description": "VEGGIE LOVER'S", "price": "$14.99", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/Classic_Veggie_Lovers_Pizza.png"} ,{"description": "PEPPERONI LOVER'S", "price": "$14.99", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/Pepperoni_Lovers_Pizza.png"} ] } ,{ "name": "Pasta", "items": [{"description": "MEATY MARINARA FAMILY", "price": "$13.00", "item_url": "http://imgur.com/4BVSGPY.png"} ,{"description": "MEATY MARINARA", "price": "$8.00", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/pasta-meaty-marinara.png"} ,{"description": "CHICKEN ALFREDO", "price": "$8.00", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/pasta-chicken-alfredo.png"} ,{"description": "CHICKEN ALFREDO FAMILY", "price": "$13.00", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/pasta-chicken-alfredo-family.png"} ] } , { "name": "Wings", "items": [{"description": "TRADITIONAL BONE-IN 16PC.", "price": "$13.00", "item_url": "http://imgur.com/KNhzMxy.png"} ,{"description": "BREADED BONE-IN 8PC.", "price": "$7.00", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/wings-breaded-bone-in.png"} ,{"description": "BREADED BONE-OUT 8PC.", "price": "$7.00", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/wings-breaded-bone-out.png"} ,{"description": "DIP", "price": "$0.50", "item_url": "https://www.pizzahut.com/assets/w/tile/thor/sauce-bluecheese.png"} ] } ] }; window._vtAPI.sendIntopToClient(intop); break; case 84: //t //voting - got var intop = { "type": "voting", "text": "Who will win the tournament?", "image_url": "assets/gotlogo.png", "theme": "got", "choices": [ { "choice": "A", "description": "Loras Tyrell", "image_url": "assets/loras.png" }, { "choice": "B", "description": "The Mountain", "image_url": "assets/mountain.png" }] }; window._vtAPI.sendIntopToClient(intop); break; case 68: //d //voting - the voice var intop = { "type": "voting", "text": "Who should win the final?", "image_url": "assets/voicelogo.png", "theme": "voice", "choices": [ { "choice": "A", "description": "Craig", "image_url": "assets/craig.png" }, { "choice": "B", "description": "Chris", "image_url": "assets/chris.png" }, { "choice": "C", "description": "Damien", "image_url": "assets/damien.png" }, { "choice": "D", "description": "Matt", "image_url": "assets/matt.png" } ] }; window._vtAPI.sendIntopToClient(intop); break; case 70: //f var intop = { "type": "general", "theme": "cactus", "poster_url": "http://mudec.weebly.com/uploads/2/2/7/9/22794876/8661255_orig.jpg", "external_url": "http://www.cactus.lu/en/cactus-card/cactus-loyalty-card", "pos": "0", "text": "on your next purchase", "header": "Get double points" }; window._vtAPI.sendIntopToClient(intop); break; case 67: //c //put controls on tv if($("#v").attr("controls")){ $("#v").removeAttr("controls"); } else { $("#v").attr("controls", true); } break; default: return; } e.preventDefault(); // prevent the default action (scroll / move caret) }); //for channel selecting. var streams = {}; var currentStream = -1; var tvOn = false; var feedboxAddr = 'feedbox.demo.videntifier.com'; var videoElement = document.getElementById('v'); startLocation = 0; videoElement.addEventListener('play', function(){ queryhtml5vid(videoElement); },false); $('#top_ch_div').on('click', function(){ if(!tvOn){ return;} currentStream++; if(currentStream > streams.length-1){ currentStream = 0; } index = streams[currentStream].ID; playStream(index); }); $('#bot_ch_div').on('click', function(){ if(!tvOn){ return;} currentStream--; if(currentStream < 0){ currentStream = streams.length-1; } index = streams[currentStream].ID; playStream(index); }); var source = document.createElement('source'); videoElement.appendChild(source); videoElement.autoplay = true; window._vtAPI.on("intopReady", function(intop){ //ijson.setIntop(intop); window._vtInterface.set(intop); }) function playStream(numberStream){ videoElement.pause(); source.setAttribute('src', 'http://'+feedboxAddr+'/feed'+numberStream+'.webm'); videoElement.style.visibility='visible'; videoElement.setAttribute('poster', ''); videoElement.style.background = 'black'; videoElement.load(); //if we change channels we dont want metadata for other channel. window._vtInterface.removeOverlay(); } $.ajax({ dataType: 'json', url: 'http://'+feedboxAddr+'/json', success: function(data){ //streamdiv.style.visibility='visible'; //populateStreams(data.Data); streams = data.Data; } }); var obj = $("#v"); obj.one('click', function(){ if(Object.keys(streams).length === 0){ return; } tvOn = true; currentStream = 0; index = streams[currentStream].ID; playStream(index); }); obj.on('dragenter', function(e) { e.stopPropagation(); e.preventDefault(); }); obj.on('dragover', function(e) { e.stopPropagation(); e.preventDefault(); }); obj.on('drop', function(e) { e.preventDefault(); var files = e.originalEvent.dataTransfer.files; var file = URL.createObjectURL(files[0]); var ext = files[0].type; videoElement.pause(); source.setAttribute('src', URL.createObjectURL(files[0])); videoElement.setAttribute('poster', ''); videoElement.style.background = 'black'; videoElement.load(); //if we change channels we dont want metadata for other channel. window._vtInterface.removeOverlay(); if (files.length > 10000) { alert("Maximum 10.000 files can be uploaded at a time (you dropped " + files.length + " files)") return; } if (files.length <= 0) { alert("No files found"); return; } }); $(document).on('dragenter', function(e) { e.stopPropagation(); e.preventDefault(); }); $(document).on('dragover', function(e) { e.stopPropagation(); e.preventDefault(); }); $(document).on('drop', function(e) { e.stopPropagation(); e.preventDefault(); }); }}); //TODO: create uint8array view for the canvas data buffer, // much faster assigning than clampedarray. function queryhtml5vid(videoElement) { if(videoElement.paused || videoElement.ended) return false; //if(videoElement.ended) return false; //1. Create a paintable canvas. var canvas = document.createElement('canvas'); ctx = canvas.getContext("2d"); //2. Adjust width/height var width = videoElement.videoWidth; var height = videoElement.videoHeight; var w = width; var h = height; if(width < 64 || height < 48){ setTimeout(queryhtml5vid,500,videoElement); return; } var scaleBy = 360; if( w > scaleBy || h > scaleBy ) { if( width > height ) { w = scaleBy; h = Math.round((scaleBy*height)/width); } else { h = scaleBy; w = Math.round((scaleBy*width)/height); } } //3. Paint the video on the canvas. canvas.width = w; canvas.height = h; ctx.drawImage(videoElement, 0, 0, w, h); var imgd = ctx.getImageData(0, 0, w, h).data; window._vtAPI.identify(imgd, "video", 0, w, h, startLocation, startLocation+500); startLocation +=500; setTimeout(queryhtml5vid,500,videoElement); }