]> _ Git - fluidbook_tools.git/commitdiff
wait #6015 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Jun 2023 12:02:35 +0000 (14:02 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Jun 2023 12:02:35 +0000 (14:02 +0200)
.idea/deployment.xml
src/Links/VideoLink.php
src/Links/WebVideoLink.php

index 6f144a767c79d46a0afd5cd197ab13d864a0e9c9..ff7f409b9f5e5ad4eea579f0b1d4c4c796ade867 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="PublishConfigData" autoUpload="Always" serverName="toolbox.fluidbook.com" remoteFilesAllowedToDisappearOnAutoupload="false" confirmBeforeUploading="false" autoUploadExternalChanges="true" showAutoUploadSettingsWarning="false">
+  <component name="PublishConfigData" autoUpload="Always" serverName="dev.toolbox.fluidbook.com" remoteFilesAllowedToDisappearOnAutoupload="false" confirmBeforeUploading="false" autoUploadExternalChanges="true" showAutoUploadSettingsWarning="false">
     <option name="confirmBeforeUploading" value="false" />
     <serverData>
       <paths name="alphaville.cubedesigners.com">
index 63061337c8c123273f66fce3f363d19397f847d5..ed98e509467c84eb729c654e8953202e0eb5dedc 100644 (file)
@@ -7,31 +7,26 @@ use Cubist\Util\Url;
 use Fluidbook\Tools\Compiler\CompilerInterface;
 use Illuminate\Support\Facades\Cache;
 
-class VideoLink extends Link
-{
+class VideoLink extends Link {
     public $defaultZIndex = 50;
     public $backgroundColor = '#000000';
 
 
-    public static function addVideoJS($compiler)
-    {
+    public static function addVideoJS($compiler) {
         $compiler->addVideoJs();
     }
 
-    public function getClasses()
-    {
+    public function getClasses() {
         return array_merge(['videoLink'], parent::getClasses());
     }
 
-    public function getCSS()
-    {
+    public function getCSS() {
         $res = parent::getCSS();
         $res .= 'background-color:' . $this->backgroundColor . ';';
         return $res;
     }
 
-    public function getHTMLContent()
-    {
+    public function getHTMLContent() {
         if (!Url::isDistant($this->to)) {
             $this->copyExternalFile($this->to, true);
 
@@ -47,8 +42,7 @@ class VideoLink extends Link
         return self::makeVideoTag($this, $w, $h, $this->compiler);
     }
 
-    public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null)
-    {
+    public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null) {
         static::addVideoJS($compiler);
 
         $attributes = static::getVideoAttributes($linkDatas, $w, $h, $compiler);
@@ -70,9 +64,10 @@ class VideoLink extends Link
      * @param $compiler CompilerInterface
      * @return array
      */
-    public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null)
-    {
+    public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) {
         $attr['name'] = VideoPopupLink::getBasename($data->to);
+        $attr['stats-name'] = $attr['name'];
+        $attr['stats-type'] = 'video';
         if (Url::isDistant($data->to)) {
             $attr['url'] = $data->to;
         }
index be795954c88ed267511bcce56c9f67868943341f..86d230fb06c416f6851e6184073313b2ab6f7481 100644 (file)
@@ -4,6 +4,8 @@ namespace Fluidbook\Tools\Links;
 
 class WebVideoLink extends VideoLink {
 
+    protected static $_useVideoJS = ['youtube', 'dailymotion', 'vimeo'];
+
     public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) {
         $attributes = parent::getVideoAttributes($data, $w, $h, $compiler);
 
@@ -11,21 +13,35 @@ class WebVideoLink extends VideoLink {
         $attributes['controls'] = '1';
         $attributes['sound'] = '1';
         $attributes['setup'] = static::getVideoSetup($data, $compiler);
+        $attributes['stats-type'] = self::_normalizeVideoService($data->video_service);
+        $attributes['stats-name'] = $data->to;
 
         return $attributes;
     }
 
+    protected static function _normalizeVideoService($vs) {
+        if ($vs == 0) {
+            return 'youtube';
+        } else if ($vs == 1) {
+            return 'dailymotion';
+        } else if ($vs == 2) {
+            return 'vimeo';
+        }
+        return $vs;
+    }
+
     /**
      * @throws \JsonException
      */
     public static function getVideoSetup($data, $compiler) {
-        static::addVideoJS($compiler); // Ensure videoJS core is included first
+        if (!self::supportVideoJS($data->video_service)) {
+            return '[]';
+        }
+        static::addVideoJS($compiler);
 
-        switch ($data->video_service) {
-            case 0: // YouTube
+        switch (self::_normalizeVideoService($data->video_service)) {
             case 'youtube':
                 $compiler->addJsLib('videojs-youtube', 'js/libs/videojs/Youtube.js');
-                //                $compiler->addJs('https://rawgit.com/videojs/videojs-youtube/master/dist/Youtube.js');
                 $setup = [
                     'techOrder' => ['youtube'],
                     'sources' => [
@@ -37,37 +53,32 @@ class WebVideoLink extends VideoLink {
                     "youtube" => ["loop" => $data->video_loop, 'showinfo' => '0'],
                 ];
                 break;
-            case 1: // Dailymotion
             case 'dailymotion':
-                // Todo: add local version of script...
-                // Note: this plugin doesn't seem to work currently so it is not included
-                //$compiler->addJs('https://rawgit.com/benjipott/video.js-dailymotion/master/dist-test/videojs-dailymotion.js');
+                $compiler->addJsLib('videojs-dailymotion', 'js/libs/videojs/Dailymotion.js');
                 $setup = [
-                    //                    'techOrder' => ['dailymotion'],
-                    //                    'sources' => [
-                    //                        [
-                    //                            'src' => 'http://www.dailymotion.com/video/' . $data->to
-                    //                        ]
-                    //                    ]
+                    'techOrder' => ['dailymotion'],
+                    'sources' => [
+                        [
+                            'type' => 'video/dailymotion',
+                            'src' => 'https://www.dailymotion.com/video/' . $data->to
+                        ]
+                    ],
+                    'dailymotion' => ["loop" => $data->video_loop,],
                 ];
                 break;
-            case 2: // Vimeo
             case 'vimeo':
-                // Todo: add local version of script...
-                // Note: Vimeo plugin doesn't seem to be working currently - might need updates to work with latest VideoJS module
-                //$compiler->addJs('https://rawgit.com/videojs/videojs-vimeo/master/dist/videojs-vimeo.min.js');
+                $compiler->addJsLib('videojs-vimeo', 'js/libs/videojs/Vimeo.js');
                 $setup = [
-                    //                    'techOrder' => ['vimeo'],
-                    //                    'sources' => [
-                    //                        [
-                    //                            'type' => 'vimeo/vimeo',
-                    //                            'src' => 'https://www.vimeo.com/' . $data->to
-                    //                        ]
-                    //                    ]
+                    'techOrder' => ['vimeo'],
+                    'sources' => [
+                        [
+                            'type' => 'video/vimeo',
+                            'src' => 'https://www.vimeo.com/' . $data->to
+                        ]
+                    ],
+                    'vimeo' => ["loop" => $data->video_loop,],
                 ];
                 break;
-            default:
-                $setup = [];
         }
 
         return json_encode($setup, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
@@ -75,7 +86,7 @@ class WebVideoLink extends VideoLink {
     }
 
     public function getHTMLContent() {
-        if ($this->video_service != 0) {
+        if (!self::supportVideoJS($this->video_service)) {
             return self::getEmbed($this);
         }
 
@@ -96,30 +107,30 @@ class WebVideoLink extends VideoLink {
     }
 
     public static function getEmbedURL($data) {
-        $sound = $data->video_sound_on ? '1' : '0';
         $muted = (!$data->video_sound_on) ? '1' : '0';
         $autoplay = $data->video_auto_start ? '1' : '0';
         $loop = $data->video_loop ? '1' : '0';
-        switch ($data->video_service) {
-            case 0:
+        switch (self::_normalizeVideoService($data->video_service)) {
             case 'youtube':
                 return 'https://www.youtube.com/embed/' . $data->to . '?html5=1';
-            case 1:
             case 'dailymotion':
                 return 'https://www.dailymotion.com/embed/video/' . $data->to;
-            case 2:
             case 'vimeo':
                 return 'https://player.vimeo.com/video/' . $data->to . '?autoplay=' . $autoplay . '&loop=' . $loop . '&muted=' . $muted;
-            case 3:
             default:
                 return $data->to;
         }
     }
 
     public static function makeVideoTag($link, $width = null, $height = null, $compiler = null) {
-        if ($link->video_service == 0 || $link->video_service == 'youtube') {
+
+        if (self::supportVideoJS($link->video_service)) {
             return parent::makeVideoTag($link, $width, $height, $compiler);
         }
         return self::getEmbed($link);
     }
+
+    protected static function supportVideoJS($service) {
+        return in_array(self::_normalizeVideoService($service), self::$_useVideoJS);
+    }
 }