/* 80% width, centered canvas with rounded corners */
#videoCanvas {
width: 80%;
display: block;
margin: 0 auto;
border-radius: 10px;
background: #000;
}
.custom-video-controls {
display: flex;
justify-content: center;
margin-top: .5em;
}
.custom-video-controls button {
padding: .5em 1em;
font-size: 1rem;
cursor: pointer;
display: inline-block;
outline: 0;
border: 0;
cursor: pointer;
font-weight: 600;
color: rgb(72, 76, 122);
font-size: 14px;
height: 38px;
padding: 8px 24px;
border-radius: 50px;
background-image: linear-gradient(180deg,#fff,#f5f5fa);
box-shadow: 0 4px 11px 0 rgb(37 44 97 / 15%), 0 1px 3px 0 rgb(93 100 148 / 20%);
transition: all .2s ease-out;
:hover{
box-shadow: 0 8px 22px 0 rgb(37 44 97 / 15%), 0 4px 6px 0 rgb(93 100 148 / 20%);
}
}
document.addEventListener('DOMContentLoaded', function(){
const canvas = document.getElementById('videoCanvas');
const ctx = canvas.getContext('2d');
const btn = document.getElementById('togglePlay');
const streamURL = '/wp-admin/admin-ajax.php?action=serve_protected_video';
const logoutURL = '/wp-admin/admin-ajax.php?action=temp_user_logout';
const homeURL = 'https://vosyn.ai/';
let lastTime = 0;
let done = false;
if (!canvas || !btn) return;
// 1) Create hidden video for buffering & playback
const vid = document.createElement('video');
vid.preload = 'auto';
vid.crossOrigin = 'use-credentials';
vid.style.display= 'none';
document.body.appendChild(vid);
// 2) Paint loop: draw each frame to canvas
(function paint(){
if (!vid.paused && !vid.ended) {
ctx.drawImage(vid, 0, 0, canvas.width, canvas.height);
}
requestAnimationFrame(paint);
})();
// 3) Load the protected video via AJAX
fetch(streamURL, { credentials: 'same-origin' })
.then(r => {
if (!r.ok) throw new Error('Load failed: ' + r.status);
return r.blob();
})
.then(blob => {
const url = URL.createObjectURL(blob);
vid.src = url;
vid.load();
// Once metadata is ready, enable Play
vid.addEventListener('loadedmetadata', function onMeta(){
btn.disabled = false;
btn.textContent = 'Play';
vid.removeEventListener('loadedmetadata', onMeta);
// revoke blob URL for extra security
URL.revokeObjectURL(url);
});
})
.catch(err => {
console.error(err);
btn.textContent = 'Error';
});
// 4) Prevent seeking
vid.addEventListener('timeupdate', () => {
// if scrubbing to end, trigger logout
if (!done && vid.currentTime >= vid.duration - 0.1) {
doLogout();
}
lastTime = vid.currentTime;
});
vid.addEventListener('seeking', () => {
vid.currentTime = lastTime;
});
// 5) Play/Pause via custom button
btn.addEventListener('click', function(){
if (vid.paused) {
vid.play();
btn.textContent = 'Pause';
} else {
vid.pause();
btn.textContent = 'Play';
}
});
// 6) End‐of‐video: delete user & redirect
vid.addEventListener('ended', doLogout, { once: true });
function doLogout() {
if (done) return;
done = true;
fetch(logoutURL, { credentials: 'same-origin' })
.finally(()=> window.location = homeURL);
}
// 7) Block right-click & keyboard
canvas.addEventListener('contextmenu', e => e.preventDefault());
document.addEventListener('keydown', function(e){
if (document.activeElement === canvas) {
e.preventDefault();
e.stopPropagation();
}
});
});


