diff --git a/plugin/Live/Objects/LiveTransmitionHistory.php b/plugin/Live/Objects/LiveTransmitionHistory.php index fd96f7a50..2c3c78855 100644 --- a/plugin/Live/Objects/LiveTransmitionHistory.php +++ b/plugin/Live/Objects/LiveTransmitionHistory.php @@ -1,441 +1,448 @@ id; } function getTitle() { return $this->title; } function getDescription() { return $this->description; } function getKey() { return $this->key; } function getCreated() { return $this->created; } function getModified() { return $this->modified; } function getUsers_id() { return $this->users_id; } function setId($id) { $this->id = $id; } function getFinished() { return $this->finished; } function setTitle($title) { global $global; $title = $global['mysqli']->real_escape_string($title); $this->title = $title; } function setDescription($description) { global $global; $description = $global['mysqli']->real_escape_string($description); $this->description = $description; } function setKey($key) { $this->key = $key; } function setCreated($created) { $this->created = $created; } function setModified($modified) { $this->modified = $modified; } function setUsers_id($users_id) { $this->users_id = $users_id; } function getLive_servers_id() { return intval($this->live_servers_id); } function getLive_index() { if(empty($this->key)){ return ''; } $parameters = Live::getLiveParametersFromKey($this->key); return $parameters['live_index']; } function getLive_cleanKey() { if(empty($this->key)){ return ''; } $parameters = Live::getLiveParametersFromKey($this->key); return $parameters['cleanKey']; } static function getApplicationObject($liveTransmitionHistory_id) { global $global; $lth = new LiveTransmitionHistory($liveTransmitionHistory_id); $lt = LiveTransmition::getFromDbByUser($lth->getUsers_id()); $liveUsersEnabled = AVideoPlugin::isEnabledByName("LiveUsers"); $p = AVideoPlugin::loadPlugin("Live"); $obj = new stdClass(); $users_id = $lth->getUsers_id(); $u = new User($users_id); $live_servers_id = $lth->getLive_servers_id(); if(empty($live_servers_id) && !empty($_REQUEST['live_servers_id'])){ $live_servers_id = $_REQUEST['live_servers_id']; } $key = $lth->getKey(); $title = $lth->getTitle(); $photo = $u->getPhotoDB(); $m3u8 = Live::getM3U8File($key); $playlists_id_live = 0; if (preg_match("/.*_([0-9]+)/", $key, $matches)) { if (!empty($matches[1])) { $_REQUEST['playlists_id_live'] = intval($matches[1]); $playlists_id_live = $_REQUEST['playlists_id_live']; $photo = PlayLists::getImage($_REQUEST['playlists_id_live']); $title = PlayLists::getNameOrSerieTitle($_REQUEST['playlists_id_live']); } } $obj->UserPhoto = $u->getPhotoDB(); $obj->isAdaptive = Live::isAdaptive($key); $obj->photo = $photo; $obj->channelName = $u->getChannelName(); $obj->live_index = $lth->getLive_index(); $obj->live_cleanKey = $lth->getLive_cleanKey(); $obj->live_servers_id = $live_servers_id; $obj->href = Live::getLinkToLiveFromUsers_idAndLiveServer($users_id, $live_servers_id, $obj->live_index); $obj->key = $key; $obj->isPrivate = Live::isAPrivateLiveFromLiveKey($obj->key); $obj->link = addQueryStringParameter($obj->href, 'embed', 1); $obj->name = $u->getNameIdentificationBd(); $obj->playlists_id_live = $playlists_id_live; $obj->poster = $p->getLivePosterImage($users_id, $live_servers_id, $playlists_id_live, $lth->getLive_index()); $obj->imgGif = $p->getLivePosterImage($users_id, $live_servers_id, $playlists_id_live, $lth->getLive_index(), 'webp'); $obj->title = $title; $obj->user = $u->getUser(); $obj->categories_id = intval($lt['categories_id']); $obj->className = "live_{$obj->live_servers_id}_{$obj->key}"; $users = false; if ($liveUsersEnabled) { $filename = $global['systemRootPath'] . 'plugin/LiveUsers/Objects/LiveOnlineUsers.php'; if (file_exists($filename)) { require_once $filename; $liveUsers = new LiveOnlineUsers(0); $users = $liveUsers->getUsersFromTransmitionKey($key, $live_servers_id); } } $obj->users = $users; $obj->m3u8 =$m3u8; $obj->isURL200 = isURL200($m3u8); $obj->users_id = $users_id; return $obj; } static function getStatsAndAddApplication($liveTransmitionHistory_id) { $stats = getStatsNotifications(); $lth = new LiveTransmitionHistory($liveTransmitionHistory_id); $key = $lth->getKey(); if(!empty($stats['applications'])){ foreach ($stats['applications'] as $value) { if(empty($value['key'])){ continue; } $value = object_to_array($value); $value['key']= self::getCleankeyName($value['key']); if(!empty($value['key']) && $value['key']==$key){ // application is already in the list return $stats; } } } if(!empty($stats['hidden_applications'])){ foreach ($stats['hidden_applications'] as $value) { if(empty($value['key'])){ continue; } $value = object_to_array($value); $value['key']= self::getCleankeyName($value['key']); if($value['key']==$key){ // application is already in the list return $stats; } } } $application = self::getApplicationObject($liveTransmitionHistory_id); if ($application->isPrivate) { $stats['hidden_applications'][] = $application; } else { $stats['applications'][] = $application; } $stats['countLiveStream']++; $cacheName = "getStats" . DIRECTORY_SEPARATOR . "getStatsNotifications"; $cache = ObjectYPT::setCache($cacheName, $stats); // update the cache //_error_log("NGINX getStatsAndAddApplication ". json_encode($stats)); //_error_log("NGINX getStatsAndAddApplication ". json_encode($cache)); return $stats; } static function getCleankeyName($key){ $parts = explode("_", $key); if(!empty($parts[1])){ $adaptive = array('hi', 'low', 'mid'); if(in_array($parts[1], $adaptive)){ return $parts[0]; } } return $key; } static function getStatsAndRemoveApplication($liveTransmitionHistory_id) { $stats = getStatsNotifications(); $lth = new LiveTransmitionHistory($liveTransmitionHistory_id); $key = $lth->getKey(); foreach ($stats['applications'] as $k => $value) { $value = object_to_array($value); if(!empty($value['key']) && $value['key']==$key){ // application is already in the list unset($stats['applications'][$k]); $stats['countLiveStream']--; } } if(empty($stats['hidden_applications'])){ $stats['hidden_applications'] = array(); }else{ foreach ($stats['hidden_applications'] as $k => $value) { $value = object_to_array($value); if($value['key']==$key){ // application is already in the list unset($stats['hidden_applications'][$k]); } } } $cacheName = "getStats" . DIRECTORY_SEPARATOR . "getStatsNotifications"; $cache = ObjectYPT::setCache($cacheName, $stats); // update the cache return $stats; } function setLive_servers_id($live_servers_id) { $this->live_servers_id = intval($live_servers_id); } static function getAllFromUser($users_id) { global $global; $sql = "SELECT * FROM " . static::getTableName() . " WHERE users_id = ? "; $sql .= self::getSqlFromPost(); $res = sqlDAL::readSql($sql, "i", array($users_id)); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $rows = array(); if ($res != false) { foreach ($fullData as $row) { $log = LiveTransmitionHistoryLog::getAllFromHistory($row['id']); $row['totalUsers'] = count($log); $rows[] = $row; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $rows; } static function getLatest($key, $live_servers_id=null) { global $global; - $sql = "SELECT * FROM " . static::getTableName() . " WHERE `key` = ? "; + + $key = $global['mysqli']->real_escape_string($key); + + if(empty($key)){ + return false; + } + + $sql = "SELECT * FROM " . static::getTableName() . " WHERE `key` LIKE '{$key}%' "; if(isset($live_servers_id)){ $sql .= " AND live_servers_id = ".intval($live_servers_id); } $sql .= " ORDER BY created DESC LIMIT 1"; - // I had to add this because the about from customize plugin was not loading on the about page http://127.0.0.1/AVideo/about + //var_dump($sql, $key);exit; - $res = sqlDAL::readSql($sql, "s", array($key)); + $res = sqlDAL::readSql($sql); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data; } else { $row = false; } return $row; } static function finish($key) { $row = self::getLatest($key); if(empty($row) || empty($row['id']) || !empty($row['finished'])){ return false; } return self::finishFromTransmitionHistoryId($row['id']); } static function finishFromTransmitionHistoryId($live_transmitions_history_id) { $live_transmitions_history_id = intval($live_transmitions_history_id); if(empty($live_transmitions_history_id)){ return false; } $sql = "UPDATE " . static::getTableName() . " SET finished = now() WHERE id = {$live_transmitions_history_id} "; $insert_row = sqlDAL::writeSql($sql); return $insert_row; } static function getLatestFromUser($users_id) { $rows = self::getLastsLiveHistoriesFromUser($users_id, 1); return @$rows[0]; } static function getLatestFromKey($key) { global $global; $parts = Live::getLiveParametersFromKey($key); $key = $parts['cleanKey']; $sql = "SELECT * FROM " . static::getTableName() . " WHERE `key` LIKE '{$key}%' "; $sql .= " ORDER BY created DESC LIMIT 1"; $res = sqlDAL::readSql($sql); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data; } else { $row = false; } return $row; } static function getLatestIndexFromKey($key) { $row = self::getLatestFromKey($key); return Live::getLiveIndexFromKey(@$row['key']); } static function getLastsLiveHistoriesFromUser($users_id, $count=10) { global $global; $sql = "SELECT * FROM " . static::getTableName() . " WHERE `users_id` = ? ORDER BY created DESC LIMIT ?"; $res = sqlDAL::readSql($sql, "ii", array($users_id, $count)); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $rows = array(); if ($res != false) { foreach ($fullData as $row) { $log = LiveTransmitionHistoryLog::getAllFromHistory($row['id']); $row['totalUsers'] = count($log); $rows[] = $row; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $rows; } static function getActiveLiveFromUser($users_id, $live_servers_id='', $key='') { global $global; $sql = "SELECT * FROM " . static::getTableName() . " WHERE finished IS NULL "; $formats = ""; $values = array(); if(!empty($users_id)){ $sql .= ' AND `users_id` = ? '; $formats .= "i"; $values[] = $users_id; } if(!empty($live_servers_id)){ $sql .= ' AND `live_servers_id` = ? '; $formats .= "i"; $values[] = $live_servers_id; } if(!empty($key)){ $sql .= ' AND `key` = ? '; $formats .= "s"; $values[] = $key; } $sql .= " ORDER BY created DESC LIMIT 1"; $res = sqlDAL::readSql($sql, $formats, $values); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data; } else { $row = false; } if(empty($row)){ _error_log('LiveTransmitionHistory::getActiveLiveFromUser: '.$sql); } return $row; } public function save() { if (empty($this->live_servers_id)) { $this->live_servers_id = 'NULL'; } return parent::save(); } static function deleteAllFromLiveServer($live_servers_id) { global $global; $live_servers_id = intval($live_servers_id); if (!empty($live_servers_id)) { global $global; $sql = "SELECT id FROM " . static::getTableName() . " WHERE live_servers_id = ? "; $sql .= self::getSqlFromPost(); $res = sqlDAL::readSql($sql, "i", array($live_servers_id)); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $rows = array(); if ($res != false) { foreach ($fullData as $row) { $lt = new LiveTransmitionHistory($row['id']); $lt->delete(); } } } } public function delete() { if (!empty($this->id)) { LiveTransmitionHistoryLog::deleteAllFromHistory($this->id); } return parent::delete(); } } \ No newline at end of file diff --git a/plugin/Live/view/liveVideo.php b/plugin/Live/view/liveVideo.php index 6ee90803b..3b1f0eca8 100644 --- a/plugin/Live/view/liveVideo.php +++ b/plugin/Live/view/liveVideo.php @@ -1,27 +1,27 @@ - + '; $htmlMediaTag .= getLiveUsersLabelHTML(); echo PlayerSkins::getMediaTag(false, $htmlMediaTag); ?> diff --git a/plugin/Live/webRTC.js b/plugin/Live/webRTC.js index c474c3b2f..64d25a067 100644 --- a/plugin/Live/webRTC.js +++ b/plugin/Live/webRTC.js @@ -1,85 +1,86 @@ window.addEventListener('message', event => { if (event.data.startLiveRestream) { startLiveRestream(event.data.m3u8, forceIndex); }else if (event.data.showPleaseWait) { modal.showPleaseWait(); }else if (event.data.hidePleaseWait) { modal.hidePleaseWait(); }else if (event.data.webRTCModalConfig) { console.log('event.data.webRTCModalConfig', event.data.webRTCModalConfig, typeof webRTCModalConfigShow); if(event.data.webRTCModalConfig==1){ if(typeof webRTCModalConfigShow =='function'){ webRTCModalConfigShow(); } }else{ if(typeof webRTCModalConfigHide =='function'){ webRTCModalConfigHide(); } } } }); function startLiveRestream(m3u8, forceIndex) { console.log('WebRTCLiveCam: startLiveRestream', m3u8, forceIndex); modal.showPleaseWait(); $.ajax({ url: webSiteRootURL + '/plugin/Live/webRTCToLive.json.php', method: 'POST', data: { 'm3u8': m3u8, 'live_servers_id': live_servers_id, 'forceIndex': forceIndex }, success: function (response) { if (response.error) { webRTCDisconnect(); avideoAlertError(response.msg); } else { avideoToastSuccess(response.msg); //document.querySelector("iframe").contentWindow.postMessage({setLiveStart: 1}, "*"); } modal.hidePleaseWait(); } }); } function webRTCConnect() { modal.showPleaseWait(); document.querySelector("iframe").contentWindow.postMessage({setLiveStart: 1}, "*"); webRTCPleaseWaitShow(); } function webRTCDisconnect() { document.querySelector("iframe").contentWindow.postMessage({setLiveStop: 1}, "*"); webRTCPleaseWaitHide(); } function webRTCConfiguration() { document.querySelector("iframe").contentWindow.postMessage({setConfiguration: 1}, "*"); } var _webRTCPleaseWaitShowTimeout; function webRTCPleaseWaitShow(){ $('body').addClass('webRTCPleaseWait'); clearTimeout(_webRTCPleaseWaitShowTimeout); _webRTCPleaseWaitShowTimeout = setTimeout(function(){ + avideoToastError('Live error') webRTCPleaseWaitHide(); },60000); } function webRTCPleaseWaitHide(){ clearTimeout(_webRTCPleaseWaitShowTimeout); $('body').removeClass('webRTCPleaseWait'); } function webRTCisLive(){ $('body').addClass('webRTCisLive'); webRTCPleaseWaitHide(); } function webRTCisOffline(){ $('body').removeClass('webRTCisLive'); webRTCPleaseWaitHide(); } \ No newline at end of file