<?php
/**
 * Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
 * License: GNU/GPL version 3.0
 *
 * This file is part of SexHackMe Wordpress Plugin.
 *
 * SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published 
 * by the Free Software Foundation, either version 3 of the License, 
 * or (at your option) any later version.
 *
 * SexHackMe Wordpress Plugin is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
 */

namespace wp_SexHackMe;

if(!class_exists('SexhackVideoJSPlayer')) {
   class SexhackVideoJSPlayer
   {
      public function __construct()
      {
         sexhack_log('SexhackVideoJSPlayer() Instanced');
         add_shortcode("sexvideo", array( $this, "sexvideo_shortcode"));
      }

      public function addPlayer($vurl, $posters="", $projection="180_LR")
      {
         $uid = uniqid('sexvideo_');
			//$uid = "antani";
			$html  = "<video id='$uid' class='video-js vjs-default-skin vjs-2-1 vjs-big-play-centered' style='width: 100%; height: 100%;' controls poster='$posters'>\n";
			//$html.= '<script src="https://s3.deovr.com/version/1/js/bundle.js" async></script>';
			//$html .= "<deo-video id='$uid'>\n";
  			//$html .= '	<source src="'.$vurl.'" quality="1080p" type="application/x-mpegURL">'."\n";
			$html .= '</video>'."\n";
			//$html .= "</deo-video>\n";
			$html .= "<script language='javascript'>\n";
			$html .= "$(window).on('load', function() {\n";
			//$html .= "   videojs.log.level('debug');\n";
			$html .= "   var player = videojs('$uid', {\n";
			$html .= "				html5: {\n";
    		$html .= "               vhs: {\n";
         $html .= "                overrideNative: !videojs.browser.IS_SAFARI\n";
   	   $html .= "               },\n";
         $html .= "           nativeAudioTracks: false,\n";
         $html .= "           nativeVideoTracks: false\n";
         $html .= "           }});\n";
         $html .= "   player.src({ src: '$vurl', type: 'application/x-mpegURL'});\n";
         //if($_GET['antani']) {
            $html .= "   player.xr();";
         //} else {
		   //   $html .= "   player.mediainfo = player.mediainfo || {};\n";
			//   $html .= "   player.mediainfo.projection = '$projection';\n";
         //   $html .= "   player.vr({projection: '$projection', debug: false, forceCardboard: true});\n";
         //}
			//$html .= "   player.xr();";
			$html .= '});'."\n";
			$html .= "</script>";
         return $html;
      }

      public function sexvideo_shortcode($attr, $cont)
      {
         extract( shortcode_atts(array(
            "url" => '',
            "posters" => '',
         ), $attr));
         return "<div class='sexvideo_videojs'>" . $this->addPlayer($url, $posters) . "</div>";
      }

   }
}




$SEXHACK_SECTION = array(
   'class' => 'SexhackVideoJSPlayer', 
   'description' => 'Add VideoJS Video Player', 
   'name' => 'sexhackme_videojs_player'
);

?>
