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);
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);
* @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;
}
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);
$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' => [
"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);
}
public function getHTMLContent() {
- if ($this->video_service != 0) {
+ if (!self::supportVideoJS($this->video_service)) {
return self::getEmbed($this);
}
}
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);
+ }
}