MODULE = 'bx_stream'; parent::__construct($oConfig, $oDb); } public function getLiveBadge ($aContentInfo) { $CNF = &$this->getModule()->_oConfig->CNF; if (!$aContentInfo || $aContentInfo[$CNF['FIELD_STATUS']] != 'active') return ''; return $this->parseHtmlByName('stream_badge.html', array( 'label' => _t('_bx_stream_txt_live_now'), )); } public function entryStreamBroadcast ($aContentInfo) { $oEngine = $this->getModule()->getStreamEngine(); if (!$oEngine->isSreamFromBrowser()) return MsgBox(_t('_bx_stream_from_webcam_not_supported')); $mixedMsg = $this->getModule()->checkAllowedAdd (false); if ($mixedMsg !== CHECK_ACTION_RESULT_ALLOWED) return MsgBox($mixedMsg); $CNF = &$this->getModule()->_oConfig->CNF; $aAspect = preg_split("/[\/:]+/", trim(getParam('bx_stream_aspect_ratio')), 2, PREG_SPLIT_NO_EMPTY); return $this->parseHtmlByName('stream_broadcast_ome.html', array( 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]), 'broadcast_url' => $oEngine->getWebrtcIngestUrl($aContentInfo[$CNF['FIELD_KEY']]), 'aspect_ratio' => $aAspect && is_array($aAspect) && $aAspect[0] && $aAspect[1] ? $aAspect[0] / $aAspect[1] : 0, 'popup_share' => $this->popupShare($aContentInfo), 'popup_settings' => $this->popupSettings($aContentInfo), )); } public function popupShare ($aContentInfo) { $CNF = &$this->getModule()->_oConfig->CNF; $sUrlViewStream = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . (int)$aContentInfo['id']; $sUrlViewStream = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($sUrlViewStream)); $sUrlEmbed = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'embed/' . (int)$aContentInfo['id']; $aForm = array( 'form_attrs' => array( 'name' => 'bx-stream-form-share', 'class' => 'bx-def-margin', ), 'inputs' => array( 'url' => array( 'type' => 'text', 'name' => 'url'.time(), 'caption' => _t('_bx_stream_field_link'), 'value' => $sUrlViewStream, 'attrs' => array('readonly' => 'readonly'), ), 'embed' => array( 'type' => 'text', 'name' => 'embed'.time(), 'caption' => _t('_bx_stream_field_embed'), 'value' => '', 'attrs' => array('readonly' => 'readonly'), ), ), ); $oForm = new BxTemplFormView ($aForm); return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-share', _t('_bx_stream_popup_share'), $oForm->getCode(), true); } public function popupSettings ($aContentInfo) { $CNF = &$this->getModule()->_oConfig->CNF; $aForm = array( 'form_attrs' => array( 'name' => 'bx-stream-form-settings', 'onsubmit' => 'return false', 'onreset' => 'return false', ), 'inputs' => array( 'audio' => array( 'type' => 'select', 'name' => 'audio', 'caption' => _t('_bx_stream_field_audio_source'), 'value' => '', ), 'video' => array( 'type' => 'select', 'name' => 'video', 'caption' => _t('_bx_stream_field_video_source'), 'value' => '', ), ), ); $oForm = new BxTemplFormView ($aForm); return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-settings', _t('_bx_stream_popup_settings'), $oForm->getCode(), true); } public function entryStreamViewers ($aContentInfo) { $CNF = &$this->getModule()->_oConfig->CNF; return $this->parseHtmlByName('stream_viewers.html', array( 'viewers' => _t('_bx_stream_txt_wait_for_stream'), 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]), 'url' => BX_DOL_URL_MODULES . '?r=' . $this->getModule()->_oConfig->getUri() . '/stream_viewers/' . $aContentInfo[$CNF['FIELD_ID']] )); } public function entryStreamPlayer ($aContentInfo, $aOptions = []) { $CNF = &$this->getModule()->_oConfig->CNF; $sSources = getParam('bx_stream_sources_pattern'); $sHost = getParam('bx_stream_server_host'); $sApp = getParam('bx_stream_app'); if (!$sSources || !$sHost) return MsgBox(_t('_bx_stream_txt_no_config')); $sSources = str_replace( ['{host}', '{app}', '{key}', '{params}'], [$sHost, $sApp, $aContentInfo[$CNF['FIELD_KEY']], ''], $sSources ); $this->addJs('ovenplayer/ovenplayer.js'); if (getParam('bx_stream_dash_enabled')) $this->addJs('ovenplayer/dash.all.min.js'); if (getParam('bx_stream_hls_enabled')) $this->addJs('ovenplayer/hls.min.js'); $this->addJsTranslation('_bx_stream_txt_wait_for_stream'); $sImage = ''; $mixedImage = $this->_getHeaderImage($aContentInfo); if($mixedImage !== false) { if($o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder'])) $sImage = $o->getFileUrlById($mixedImage['id']); } if (!isset($aOptions['mute'])) $aOptions['mute'] = getParam('bx_stream_mute') ? 1 : 0; if (isset($aOptions['autostart'])) $aOptions['autostart'] = $aOptions['autostart'] ? 1 : 0; else $aOptions['autostart'] = 1; return $this->parseHtmlByName('stream_player.html', array( 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]), 'sources' => $sSources, 'mute' => $aOptions['mute'], 'image' => $sImage, 'autostart' => $aOptions['autostart'], )); } public function embedStream($aContentInfo) { $CNF = &$this->getModule()->_oConfig->CNF; // TODO: visibility and other checks $sCode = $this->parseHtmlByName('stream_embed.html', array( 'player' => $this->entryStreamPlayer ($aContentInfo, [ 'mute' => getParam('bx_stream_mute_embed') ? 1 : 0, 'autostart' => 0, ]), 'viewers' => $this->entryStreamViewers ($aContentInfo), )); $this->addCss('main.css'); // display page $oTemplate = BxDolTemplate::getInstance(); $oTemplate->setPageNameIndex (BX_PAGE_EMBED); $oTemplate->setPageHeader ($aContentInfo[$CNF['FIELD_TITLE']]); $oTemplate->setPageContent ('page_main_code', $sCode); $oTemplate->getPageCode(); exit; } /** * Use Gallery image for both because currently there is no Unit types with small thumbnails. */ protected function getUnitThumbAndGallery ($aData) { list($sPhotoThumb, $sPhotoGallery) = parent::getUnitThumbAndGallery($aData); return array($sPhotoGallery, $sPhotoGallery); } public function getTmplVarsText($aData) { $a = parent::getTmplVarsText($aData); $a['bx_if:show_image']['condition'] = false; return $a; } } /** @} */