From 510e6cdbf2f073693cec5831795001d33122b112 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 28 Feb 2015 20:50:25 +0100 Subject: generate switcher based on config --- lib/helper.php | 58 ++++++++++++++++++- pages/room.php | 47 +++++++++++---- template/assemblies/desktop-player.phtml | 6 +- template/assemblies/switcher/video.phtml | 98 ++++++++++++++++---------------- 4 files changed, 144 insertions(+), 65 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index 87bd6c5..647d657 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -14,9 +14,9 @@ function link_room($room) function link_player($room, $format = 'hd', $translated = false) { - $isDefaultFormat = in_array($format, array('hd', 'video')); + $defaultformat = room_has_hd($room) ? 'hd' : 'sd'; - return rawurlencode($room).'/'.($isDefaultFormat ? '' : rawurlencode($format).'/').($translated ? 'translated/' : ''); + return rawurlencode($room).'/'.($defaultformat == $format ? '' : rawurlencode($format).'/').($translated ? 'translated/' : ''); } function link_stream($protocol, $room, $format, $translated = false) @@ -134,3 +134,57 @@ function _get($array, $keychain, $default) return _get($array[$key], array_slice($keychain, 1), $default); } + + + +function room_has_hd($room) +{ + $formats = get("ROOMS.$room.FORMATS"); + return count(array_intersect(array('rtmp-hd', 'hls-hd', 'webm-hd'), $formats)) > 0; +} + +function room_has_sd($room) +{ + $formats = get("ROOMS.$room.FORMATS"); + return count(array_intersect(array('rtmp-sd', 'hls-sd', 'webm-sd'), $formats)) > 0; +} + +function room_has_video($room) +{ + return room_has_hd($room) || room_has_sd($room); +} + +function room_has_audio($room) +{ + $formats = get("ROOMS.$room.FORMATS"); + return count(array_intersect(array('audio-mp3', 'audio-opus'), $formats)) > 0; +} + +function room_has_slides($room) +{ + $formats = get("ROOMS.$room.FORMATS"); + return count(array_intersect(array('slides'), $formats)) > 0; +} + +function room_has_rtmp($room) +{ + $formats = get("ROOMS.$room.FORMATS"); + return count(array_intersect(array('rtmp-hd', 'rtmp-sd'), $formats)) > 0; +} + +function room_has_webm($room) +{ + $formats = get("ROOMS.$room.FORMATS"); + return count(array_intersect(array('webm-hd', 'webm-sd'), $formats)) > 0; +} + +function room_has_hls($room) +{ + $formats = get("ROOMS.$room.FORMATS"); + return count(array_intersect(array('hls-hd', 'hls-sd'), $formats)) > 0; +} + +function startswith($needle, $haystack) +{ + return substr($haystack, 0, strlen($needle)) == $needle; +} diff --git a/pages/room.php b/pages/room.php index ba4e35b..526aabd 100644 --- a/pages/room.php +++ b/pages/room.php @@ -8,35 +8,47 @@ $language = $_GET['language']; $selection = $_GET['selection']; $formats = get("ROOMS.$room.FORMATS"); +$has_translation = get("ROOMS.$room.TRANSLATION"); +$protos = array(); $selections = array(); $tabs = array(); +$videores = array(); +if(room_has_hd($room)) + $selections[] = $videores[] = 'hd'; -if(count(array_intersect(array('rtmp-hd', 'hls-hd', 'webm-hd'), $formats)) > 0) - $selections[] = 'hd'; +if(room_has_sd($room)) + $selections[] = $videores[] = 'sd'; -if(count(array_intersect(array('rtmp-sd', 'hls-sd', 'webm-sd'), $formats)) > 0) - $selections[] = 'sd'; - -if(count(array_intersect(array('rtmp-sd', 'rtmp-hd', 'hls-sd', 'hls-hd', 'webm-sd', 'webm-hd'), $formats)) > 0) +if(room_has_video($room)) $tabs[] = 'video'; -if(count(array_intersect(array('audio-mp3', 'audio-opus'), $formats)) > 0) + +if(room_has_audio($room)) $selections[] = $tabs[] = 'audio'; -if(count(array_intersect(array('slides'), $formats)) > 0) +if(room_has_slides($room)) $selections[] = $tabs[] = 'slides'; +if(room_has_rtmp($room)) + $protos[] = 'rtmp'; + +if(room_has_webm($room)) + $protos[] = 'webm'; + +if(room_has_hls($room)) + $protos[] = 'hls'; + + // default page if(!$selection) $selection = $selections[0]; -if(!in_array($selection, $selections)) { - include('404.php'); - exit; -} +if(!in_array($selection, $selections)) + return include('404.php'); + switch($selection) { @@ -53,6 +65,8 @@ switch($selection) { case 'slides': $tab = 'slides'; $title = 'Slides'; + $width = 1024; + $height = 576; break; case 'hd': @@ -71,7 +85,12 @@ switch($selection) { } if($language == 'translated') +{ + if(!$has_translation) + return include('404.php'); + $title = 'Translated '.$title; +} echo $tpl->render(array( 'page' => 'room', @@ -90,5 +109,9 @@ echo $tpl->render(array( 'translated' => ($language == 'translated'), 'selection' => $selection, 'hlsformat' => ($selection == 'hd' ? 'auto' : $selection), + + 'has_translation' => $has_translation, 'formats' => $formats, + 'protos' => $protos, + 'videores' => $videores, )); diff --git a/template/assemblies/desktop-player.phtml b/template/assemblies/desktop-player.phtml index 5836f90..b317abd 100644 --- a/template/assemblies/desktop-player.phtml +++ b/template/assemblies/desktop-player.phtml @@ -1,2 +1,4 @@ -

Use a Desktop-Player!

-

Browsers and Video doesn't go together well, even in 2014 and especially when it's live. So for your best viewing-experience please use a Desktop-Player like VLC or mplayer.

+
+

Use a Desktop-Player!

+

Browsers and Video doesn't go together well, even in 2014 and especially when it's live. So for your best viewing-experience please use a Desktop-Player like VLC or mplayer.

+
diff --git a/template/assemblies/switcher/video.phtml b/template/assemblies/switcher/video.phtml index e4fcc5b..a4ac907 100644 --- a/template/assemblies/switcher/video.phtml +++ b/template/assemblies/switcher/video.phtml @@ -1,64 +1,64 @@

Formats

-