1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-06 03:50:04 +02:00

Getting ready for the socket

This commit is contained in:
DanielnetoDotCom 2021-01-20 15:43:16 -03:00
parent bb45ecff72
commit d1db39b4d1
27 changed files with 1046 additions and 306 deletions

View file

@ -869,7 +869,7 @@ function maxLifetime() {
$maxLifetime = $aws_s3->presignedRequestSecondsTimeout;
_error_log("maxLifetime: AWS_S3 = {$maxLifetime}");
}
if (!empty($bb_b2) && empty($bb_b2->usePublicBucket) && !empty($bb_b2->presignedRequestSecondsTimeout) && (empty($maxLifetime) || $bb_b2->presignedRequestSecondsTimeout < $maxLifetime)) {
if (!empty($bb_b2) && empty($bb_b2->usePublicBucket) && !empty($bb_b2->presignedRequestSecondsTimeout) && (empty($maxLifetime) || $bb_b2->presignedRequestSecondsTimeout < $maxLifetime)) {
$maxLifetime = $bb_b2->presignedRequestSecondsTimeout;
_error_log("maxLifetime: B2 = {$maxLifetime}");
}
@ -1139,7 +1139,7 @@ function getVideosURLOnly($fileName) {
return $allFiles;
}
function getVideosDir(){
function getVideosDir() {
return Video::getStoragePath();
}
@ -1218,7 +1218,7 @@ function getVideosURL_V2($fileName, $recreateCache = false) {
TimeLogStart($timeName);
$filesInDir = globVideosDir($cleanfilename, true);
TimeLogEnd($timeName, __LINE__);
$timeName = "getVideosURL_V2::foreach";
TimeLogStart($timeName);
foreach ($filesInDir as $file) {
@ -1260,45 +1260,45 @@ function getVideosURL_V2($fileName, $recreateCache = false) {
TimeLogEnd($timeName, __LINE__);
ObjectYPT::setCache($cacheName, $files);
}
// sort by resolution
uasort($files, "sortVideosURL");
$getVideosURL_V2Array[$cleanfilename] = $files;
return $getVideosURL_V2Array[$cleanfilename];
}
//Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
function sortVideosURL($a, $b) {
if($a['type'] == 'video'){
if ($a['type'] == 'video') {
$aRes = getResolutionFromFilename($a['filename']);
$bRes = getResolutionFromFilename($b['filename']);
return $aRes - $bRes;
}
return 0;
}
function getResolutionFromFilename($filename){
function getResolutionFromFilename($filename) {
global $getResolutionFromFilenameArray;
if(!isset($getResolutionFromFilenameArray)){
if (!isset($getResolutionFromFilenameArray)) {
$getResolutionFromFilenameArray = array();
}
if(!empty($getResolutionFromFilenameArray[$filename])){
if (!empty($getResolutionFromFilenameArray[$filename])) {
return $getResolutionFromFilenameArray[$filename];
}
$res = Video::getResolutionFromFilename($filename);
if(empty($res)){
if(preg_match('/[_\/]hd[.\/]/i', $filename)){
if (empty($res)) {
if (preg_match('/[_\/]hd[.\/]/i', $filename)) {
$res = 720;
}else if(preg_match('/[_\/]sd[.\/]/i', $filename)){
} else if (preg_match('/[_\/]sd[.\/]/i', $filename)) {
$res = 480;
}else if(preg_match('/[_\/]low[.\/]/i', $filename)){
} else if (preg_match('/[_\/]low[.\/]/i', $filename)) {
$res = 240;
}else{
} else {
$res = 0;
}
}
@ -3319,7 +3319,7 @@ function _error_log($message, $type = 0, $doNotRepeat = false) {
if (!empty($global['noDebug']) && $type == 0) {
return false;
}
if(!is_string($message)){
if (!is_string($message)) {
$message = json_encode($message);
}
$prefix = "AVideoLog::";
@ -3741,7 +3741,7 @@ function getToken($timeout = 0, $salt = "") {
return encryptString($strObj);
}
function isTokenValid($token, $salt = ""){
function isTokenValid($token, $salt = "") {
return verifyToken($token, $salt);
}
@ -3856,7 +3856,25 @@ function isEmbed() {
function isLive() {
global $isLive;
return !empty($isLive);
if(!empty($isLive)){
return getLiveKey();
}else{
return false;
}
}
function getLiveKey() {
global $getLiveKey;
if(empty($getLiveKey)){
return false;
}
return $getLiveKey;
}
function setLiveKey($key, $live_servers_id){
global $getLiveKey;
$getLiveKey = array('key'=>$key,'live_servers_id'=>$live_servers_id);
return $getLiveKey;
}
function isVideoPlayerHasProgressBar() {
@ -3899,11 +3917,11 @@ function getRequestURI() {
}
function getSelfURI() {
if (empty($_SERVER['PHP_SELF'])) {
if (empty($_SERVER['PHP_SELF']) || empty($_SERVER['HTTP_HOST'])) {
return "";
}
$queryStringWithoutError = preg_replace("/error=[^&]*/", "", $_SERVER['QUERY_STRING']);
$phpselfWithoutIndex = preg_replace("/index.php/", "", $_SERVER['PHP_SELF']);
$queryStringWithoutError = preg_replace("/error=[^&]*/", "", @$_SERVER['QUERY_STRING']);
$phpselfWithoutIndex = preg_replace("/index.php/", "", @$_SERVER['PHP_SELF']);
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$phpselfWithoutIndex?$queryStringWithoutError";
$url = rtrim($url, '?');
return $url;
@ -3922,6 +3940,13 @@ function URLsAreSameVideo($url1, $url2) {
return $videos_id1 === $videos_id2;
}
function getVideos_id(){
if(isVideo()){
return getVideoIDFromURL(getSelfURI());
}
return false;
}
function getVideoIDFromURL($url) {
if (preg_match("/v=([0-9]+)/", $url, $matches)) {
return intval($matches[1]);
@ -4645,14 +4670,15 @@ function forbiddenPage($message, $logMessage = false) {
exit;
}
define('E_FATAL', E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR |
E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
register_shutdown_function('avidoeShutdown');
define('E_FATAL', E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR |
E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
if(!isCommandLineInterface()){
register_shutdown_function('avidoeShutdown');
}
function avidoeShutdown() {
global $global;
$error = error_get_last();
if($error && ($error['type'] & E_FATAL)){
if ($error && ($error['type'] & E_FATAL)) {
_error_log($error, AVideoLog::$ERROR);
include $global['systemRootPath'] . 'view/maintanance.html';
exit;
@ -5292,7 +5318,7 @@ function pathToRemoteURL($filename) {
if (!isset($pathToRemoteURL)) {
$pathToRemoteURL = array();
}
if (isset($pathToRemoteURL[$filename])) {
return $pathToRemoteURL[$filename];
}
@ -5319,9 +5345,9 @@ function pathToRemoteURL($filename) {
if (empty($url)) {
$url = $filename;
}
//$url = str_replace(array($global['systemRootPath'], '/videos/videos/'), array("", '/videos/'), $url);
$pathToRemoteURL[$filename] = $url;
return $url;
}
@ -5363,7 +5389,7 @@ function showCloseButton() {
function getThemes() {
global $_getThemes, $global;
if(isset($_getThemes)){
if (isset($_getThemes)) {
return $_getThemes;
}
$_getThemes = array();
@ -5376,7 +5402,7 @@ function getThemes() {
function getCurrentTheme() {
global $config;
if(!empty($_COOKIE['customCSS'])){
if (!empty($_COOKIE['customCSS'])) {
return $_COOKIE['customCSS'];
}
return $config->getTheme();
@ -5386,37 +5412,39 @@ function getCurrentTheme() {
* $users_id="" or 0 means send messages to all users
* $users_id="-1" means send to no one
*/
function sendSocketMessage($msg, $callbackJSFunction="", $users_id="-1"){
if(AVideoPlugin::isEnabledByName('Socket')){
if(!is_string($msg)){
function sendSocketMessage($msg, $callbackJSFunction = "", $users_id = "-1", $send_to_uri_pattern="") {
if (AVideoPlugin::isEnabledByName('Socket')) {
if (!is_string($msg)) {
$msg = json_encode($msg);
}
$obj = Socket::send($msg, $callbackJSFunction, $users_id);
if($obj->error){
_error_log("sendSocketMessage ".$obj->msg, AVideoLog::$ERROR);
$obj = Socket::send($msg, $callbackJSFunction, $users_id, $send_to_uri_pattern);
if ($obj->error) {
_error_log("sendSocketMessage " . $obj->msg, AVideoLog::$ERROR);
}
return $obj;
}
return false;
}
function sendSocketMessageToUsers_id($msg, $users_id, $callbackJSFunction=""){
if(!is_array($users_id)){
function sendSocketMessageToUsers_id($msg, $users_id, $callbackJSFunction = "") {
if (!is_array($users_id)) {
$users_id = array($users_id);
}
$resp = array();
foreach ($users_id as $value) {
$resp[] = sendSocketMessage($msg, $callbackJSFunction, $value);
}
return $resp;
}
function sendSocketMessageToAll($msg, $callbackJSFunction=""){
return sendSocketMessage($msg, $callbackJSFunction, "");
function sendSocketMessageToAll($msg, $callbackJSFunction = "", $send_to_uri_pattern="") {
return sendSocketMessage($msg, $callbackJSFunction, "", $send_to_uri_pattern);
}
function sendSocketMessageToNone($msg, $callbackJSFunction=""){
function sendSocketMessageToNone($msg, $callbackJSFunction = "") {
return sendSocketMessage($msg, $callbackJSFunction, -1);
}
@ -5426,17 +5454,17 @@ function execAsync($command) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
//echo $command;
//$pid = system("start /min ".$command. " > NUL");
$commandString = "start /B cmd /S /C ". $command." > NUL";
pclose($pid = popen($commandString, "r"));
$commandString = "start /B cmd /S /C " . $command . " > NUL";
pclose($pid = popen($commandString, "r"));
} else {
$pid = exec($command . " > /dev/null 2>&1 & echo $!; ");
}
return $pid;
}
function killProcess($pid){
function killProcess($pid) {
$pid = intval($pid);
if(empty($pid)){
if (empty($pid)) {
return false;
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
@ -5445,4 +5473,19 @@ function killProcess($pid){
exec("kill -9 $pid");
}
return true;
}
}
function isURL200($url) {
error_log("isURL200 checking URL {$url}");
$headers = @get_headers($url);
foreach ($headers as $value) {
if(
strpos($headers[0],'200') ||
strpos($headers[0],'302') ||
strpos($headers[0],'304')
){
return true;
}
}
return false;
}

View file

@ -67,6 +67,7 @@ foreach ($scanVars as $value) {
}
}
// all variables with _id at the end will be forced to be interger
foreach ($scanThis as $key => $value) {
if(preg_match('/_id$/i', $key)){
$scanThis[$key] = intval($value);

View file

@ -307,7 +307,7 @@ class AVideoPlugin {
if (isset($isPluginTablesInstalled[$installSQLFile])) {
return $isPluginTablesInstalled[$installSQLFile];
}
_error_log("isPluginTablesInstalled: Check for {$installSQLFile}");
//_error_log("isPluginTablesInstalled: Check for {$installSQLFile}");
if (!file_exists($installSQLFile)) {
$isPluginTablesInstalled[$installSQLFile] = true;
return $isPluginTablesInstalled[$installSQLFile];
@ -1167,6 +1167,34 @@ class AVideoPlugin {
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function onUserSocketConnect($users_id, $data) {
_mysql_connect();
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onUserSocketConnect($users_id, $data);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
_mysql_close();
}
public static function onUserSocketDisconnect($users_id, $data) {
_mysql_connect();
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onUserSocketConnect($users_id, $data);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
_mysql_close();
}
public static function thumbsOverlay($videos_id) {
$plugins = Plugin::getAllEnabled();

View file

@ -80,6 +80,87 @@ class LiveTransmitionHistory extends ObjectYPT {
return intval($this->live_servers_id);
}
static function getApplicationObject($liveTransmitionHistory_id) {
global $global;
$lth = new LiveTransmitionHistory($liveTransmitionHistory_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();
$key = $lth->getKey();
$title = $lth->getTitle();
$photo = $u->getPhotoDB();
$m3u8 = Live::getM3U8File($key);
$poster = $global['webSiteRootURL'] . $p->getPosterImage($users_id, $live_servers_id);
$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->photo = $photo;
$obj->channelName = $u->getChannelName();
$obj->href = Live::getLinkToLiveFromUsers_idAndLiveServer($users_id, $live_servers_id);
$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 = Live::isAPrivateLiveFromLiveKey($obj->key);
$obj->title = $title;
$obj->user = $u->getUser();
$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);
return $obj;
}
static function getStatsAndAddApplication($liveTransmitionHistory_id) {
$stats = Live::getStats();
$lth = new LiveTransmitionHistory($liveTransmitionHistory_id);
$key = $lth->getKey();
foreach ($stats->applications as $value) {
$value = object_to_array($value);
if($value['key']==$key){ // application is already in the list
return $stats;
}
}
foreach ($stats->hidden_applications as $value) {
$value = object_to_array($value);
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++;
return $stats;
}
function setLive_servers_id($live_servers_id) {
$this->live_servers_id = intval($live_servers_id);
}
@ -120,8 +201,7 @@ class LiveTransmitionHistory extends ObjectYPT {
}
return $row;
}
static function getLatestFromUser($users_id) {
global $global;
$sql = "SELECT * FROM " . static::getTableName() . " WHERE `users_id` = ? ORDER BY created DESC LIMIT 1";

View file

@ -45,6 +45,7 @@ if (!empty($_GET['users_id']) && User::isAdmin()) {
// if user already have a key
$trasnmition = LiveTransmition::createTransmitionIfNeed($users_id);
$getLiveKey = array('key'=>$trasnmition['key'], 'live_servers_id'=> Live::getLiveServersIdRequest());
if (!empty($_GET['resetKey'])) {
LiveTransmition::resetTransmitionKey($users_id);
header("Location: {$global['webSiteRootURL']}plugin/Live/");

View file

@ -7,9 +7,9 @@ $obj = new stdClass();
$obj->error = true;
$obj->liveTransmitionHistory_id = 0;
_error_log("NGINX ON Publish POST: ".json_encode($_POST));
_error_log("NGINX ON Publish GET: ".json_encode($_GET));
_error_log("NGINX ON Publish php://input" .file_get_contents("php://input"));
_error_log("NGINX ON Publish POST: " . json_encode($_POST));
_error_log("NGINX ON Publish GET: " . json_encode($_GET));
_error_log("NGINX ON Publish php://input" . file_get_contents("php://input"));
// get GET parameters
$url = $_POST['tcurl'];
@ -18,30 +18,30 @@ if (empty($url)) {
}
$parts = parse_url($url);
parse_str($parts["query"], $_GET);
_error_log("NGINX ON Publish parse_url: ".json_encode($parts));
_error_log("NGINX ON Publish parse_str: ".json_encode($_GET));
_error_log("NGINX ON Publish parse_url: " . json_encode($parts));
_error_log("NGINX ON Publish parse_str: " . json_encode($_GET));
$_GET = object_to_array($_GET);
if($_POST['name']=='live'){
if ($_POST['name'] == 'live') {
_error_log("NGINX ON Publish wrong name {$_POST['p']}");
// fix name for streamlab
$pParts = explode("/", $_POST['p']);
if(!empty($pParts[1])){
if (!empty($pParts[1])) {
_error_log("NGINX ON Publish like key fixed");
$_POST['name']=$pParts[1];
$_POST['name'] = $pParts[1];
}
}
if(empty($_POST['name']) && !empty($_GET['name'])){
if (empty($_POST['name']) && !empty($_GET['name'])) {
$_POST['name'] = $_GET['name'];
}
if(empty($_POST['name']) && !empty($_GET['key'])){
if (empty($_POST['name']) && !empty($_GET['key'])) {
$_POST['name'] = $_GET['key'];
}
if(strpos($_GET['p'], '/') !== false){
$parts = explode("/",$_GET['p']);
if(!empty($parts[1])){
if (strpos($_GET['p'], '/') !== false) {
$parts = explode("/", $_GET['p']);
if (!empty($parts[1])) {
$_GET['p'] = $parts[0];
$_POST['name'] = $parts[1];
}
@ -51,13 +51,13 @@ if (!empty($_GET['p'])) {
$_GET['p'] = str_replace("/", "", $_GET['p']);
_error_log("NGINX ON Publish check if key exists ({$_POST['name']})");
$obj->row = LiveTransmition::keyExists($_POST['name']);
_error_log("NGINX ON Publish key exists return ". json_encode($obj->row));
_error_log("NGINX ON Publish key exists return " . json_encode($obj->row));
if (!empty($obj->row)) {
_error_log("NGINX ON Publish new User({$obj->row['users_id']})");
$user = new User($obj->row['users_id']);
if(!$user->thisUserCanStream()){
if (!$user->thisUserCanStream()) {
_error_log("NGINX ON Publish User [{$obj->row['users_id']}] can not stream");
}else if (!empty($_GET['p']) && $_GET['p'] === $user->getPassword()) {
} else if (!empty($_GET['p']) && $_GET['p'] === $user->getPassword()) {
_error_log("NGINX ON Publish get LiveTransmitionHistory");
$lth = new LiveTransmitionHistory();
$lth->setTitle($obj->row['title']);
@ -69,11 +69,10 @@ if (!empty($_GET['p'])) {
$obj->liveTransmitionHistory_id = $lth->save();
_error_log("NGINX ON Publish saved LiveTransmitionHistory");
$obj->error = false;
} else if(empty ($_GET['p'])) {
} else if (empty($_GET['p'])) {
_error_log("NGINX ON Publish error, Password is empty");
} else {
_error_log("NGINX ON Publish error, Password does not match ({$_GET['p']}) expect (".$user->getPassword().")");
_error_log("NGINX ON Publish error, Password does not match ({$_GET['p']}) expect (" . $user->getPassword() . ")");
}
} else {
_error_log("NGINX ON Publish error, Transmition name not found ({$_POST['name']}) ", AVideoLog::$SECURITY);
@ -88,6 +87,23 @@ if (!empty($obj) && empty($obj->error)) {
header("HTTP/1.1 200 OK");
echo "success";
Live::on_publish($obj->liveTransmitionHistory_id);
ob_end_flush();
if (!$socketObj->msgObj->msg->isURL200) {
$m3u8 = Live::getM3U8File($key);
for ($i = 5; $i > 0; $i--) {
if (!isURL200($m3u8)) {
//live is not ready request again
sleep($i);
} else {
break;
}
}
$lth = new LiveTransmitionHistory($obj->liveTransmitionHistory_id);
$array = setLiveKey($lth->getKey(), $lth->getLive_servers_id());
$array['stats'] = LiveTransmitionHistory::getStatsAndAddApplication($obj->liveTransmitionHistory_id);
$socketObj = sendSocketMessageToAll($array, "socketLiveONCallback");
}
exit;
} else {
_error_log("NGINX ON Publish denied ", AVideoLog::$SECURITY);

View file

@ -0,0 +1,54 @@
<?php
require_once '../../videos/configuration.php';
require_once './Objects/LiveTransmition.php';
require_once './Objects/LiveTransmitionHistory.php';
$obj = new stdClass();
$obj->error = true;
$obj->liveTransmitionHistory_id = 0;
_error_log("NGINX ON Publish Done POST: " . json_encode($_POST));
_error_log("NGINX ON Publish Done GET: " . json_encode($_GET));
_error_log("NGINX ON Publish Done php://input" . file_get_contents("php://input"));
// get GET parameters
$url = $_POST['tcurl'];
if (empty($url)) {
$url = $_POST['swfurl'];
}
$parts = parse_url($url);
parse_str($parts["query"], $_GET);
_error_log("NGINX ON Publish Done parse_url: " . json_encode($parts));
_error_log("NGINX ON Publish Done parse_str: " . json_encode($_GET));
$_GET = object_to_array($_GET);
if ($_POST['name'] == 'live') {
_error_log("NGINX ON Publish Done wrong name {$_POST['p']}");
// fix name for streamlab
$pParts = explode("/", $_POST['p']);
if (!empty($pParts[1])) {
_error_log("NGINX ON Publish Done like key fixed");
$_POST['name'] = $pParts[1];
}
}
if (empty($_POST['name']) && !empty($_GET['name'])) {
$_POST['name'] = $_GET['name'];
}
if (empty($_POST['name']) && !empty($_GET['key'])) {
$_POST['name'] = $_GET['key'];
}
if (strpos($_GET['p'], '/') !== false) {
$parts = explode("/", $_GET['p']);
if (!empty($parts[1])) {
$_GET['p'] = $parts[0];
$_POST['name'] = $parts[1];
}
}
$row = LiveTransmitionHistory::getLatest($_POST['name']);
$array = setLiveKey($row['key'], $row['live_servers_id']);
$array['stats'] = LiveTransmitionHistory::getStatsAndAddApplication($obj->liveTransmitionHistory_id);
$socketObj = sendSocketMessageToAll($array, "socketLiveOFFCallback");

View file

@ -137,22 +137,24 @@ function clearCommandURL($url) {
return preg_replace('/[^0-9a-z:.\/_&?=-]/i', "", $url);
}
function isURL200($url) {
error_log("Restreamer.json.php checking URL {$url}");
//open connection
$ch = curl_init();
if(!function_exists('isURL200')){
function isURL200($url) {
error_log("Restreamer.json.php checking URL {$url}");
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
error_log("Restreamer.json.php URL {$url} return code {$httpcode}");
return $httpcode == 200;
error_log("Restreamer.json.php URL {$url} return code {$httpcode}");
return $httpcode == 200;
}
}
function startRestream($m3u8, $restreamsDestinations, $logFile, $tries = 1) {

View file

@ -0,0 +1,32 @@
<script>
function onlineLabelOnline(selector) {
console.log("Change video to Online");
$(selector).removeClass('label-warning');
$(selector).removeClass('label-danger');
$(selector).addClass('label-success');
$(selector).text("<?php echo __("ONLINE"); ?>");
}
function onlineLabelPleaseWait(selector) {
console.log("Change video to please wait");
$(selector).removeClass('label-success');
$(selector).removeClass('label-danger');
$(selector).addClass('label-warning');
$(selector).text("<?php echo __("Please Wait ..."); ?>");
}
function onlineLabelOffline(selector) {
console.log("Change video to offline");
$(selector).removeClass('label-warning');
$(selector).removeClass('label-success');
$(selector).addClass('label-danger');
$(selector).text("<?php echo __("OFFLINE"); ?>");
}
function onlineLabelFinishing(selector) {
console.log("Change video to finishing");
$(selector).removeClass('label-warning');
$(selector).removeClass('label-success');
$(selector).addClass('label-danger');
$(selector).text("<?php echo __("Finishing Live..."); ?>");
}
</script>

View file

@ -120,18 +120,22 @@ if (empty($obj->doNotShowGoLiveButton) && User::canStream()) {
if (href != "#") {
$liveLi.find('.liveNow').removeClass("hidden");
}
$('.liveUsersOnline_' + key).text(online);
$('.liveUsersViews_' + key).text(views);
if(!avideoSocketIsActive()){
$('.liveUsersOnline_' + key).text(online);
$('.liveUsersViews_' + key).text(views);
}
}
var limitLiveOnVideosListCount = 0;
function createExtraVideos(href, title, name, photo, user, online, views, key, disableGif, live_servers_id) {
if(typeof key !== 'string'){
return false;
}
limitLiveOnVideosListCount++;
if (limitLiveOnVideosListCount ><?php echo intval($obj->limitLiveOnVideosList); ?>) {
console.log("Max live videos on first page reached");
return false;
}
var matches = key.match(/.*_([0-9]+)/);
var playlists_id_live = "";
if (matches && matches[1]) {
@ -139,6 +143,7 @@ if (empty($obj->doNotShowGoLiveButton) && User::canStream()) {
}
var id = 'extraVideo' + user + "_" + live_servers_id + "_" + key;
var _class = 'live' + "_" + live_servers_id + "_" + key;
id = id.replace(/\W/g, '');
if ($(".extraVideos").length && $("#" + id).length == 0) {
var $liveLi = $('.extraVideosModel').clone();
@ -146,14 +151,17 @@ if (empty($obj->doNotShowGoLiveButton) && User::canStream()) {
$liveLi.removeClass("hidden").removeClass("extraVideosModel");
$liveLi.css({'display': 'none'})
$liveLi.attr('id', id);
$liveLi.addClass(_class);
$liveLi.find('.videoLink').attr("href", href);
$liveLi.find('.liveTitle').text(title);
$liveLi.find('.liveUser').text(name);
$liveLi.find('.photoImg').attr("src", photo);
$liveLi.find('.liveUsersOnline').text(online);
$liveLi.find('.liveUsersViews').text(views);
$liveLi.find('.liveUsersOnline').addClass("liveUsersOnline_" + key);
$liveLi.find('.liveUsersViews').addClass("liveUsersViews_" + key);
if(!avideoSocketIsActive()){
$liveLi.find('.liveUsersOnline').text(online);
$liveLi.find('.liveUsersViews').text(views);
$liveLi.find('.liveUsersOnline').addClass("liveUsersOnline_" + key);
$liveLi.find('.liveUsersViews').addClass("liveUsersViews_" + key);
}
$liveLi.find('.thumbsJPG').attr("src", "<?php echo $global['webSiteRootURL']; ?>plugin/Live/getImage.php?live_servers_id=" + live_servers_id + "&u=" + user + "&format=jpg" + playlists_id_live + '&' + Math.random());
if (!disableGif) {
$liveLi.find('.thumbsGIF').attr("src", "<?php echo $global['webSiteRootURL']; ?>plugin/Live/getImage.php?live_servers_id=" + live_servers_id + "&u=" + user + "&format=gif" + playlists_id_live + '&' + Math.random());
@ -166,33 +174,30 @@ if (empty($obj->doNotShowGoLiveButton) && User::canStream()) {
}
}
function getStatsMenu(recurrentCall) {
availableLiveStreamIsLoading();
$.ajax({
url: webSiteRootURL + 'plugin/Live/stats.json.php?Menu<?php echo (!empty($_GET['videoName']) ? "&requestComesFromVideoPage=1" : "") ?>',
success: function (response) {
limitLiveOnVideosListCount = 0;
if (typeof response !== 'undefined') {
$('#availableLiveStream').empty();
if (isArray(response)) {
for (var i in response) {
if (typeof response[i] !== 'object') {
continue;
}
processApplicationLive(response[i]);
}
} else {
processApplicationLive(response);
function processLiveStats(response) {
//console.log('processLiveStats', response);
limitLiveOnVideosListCount = 0;
if (typeof response !== 'undefined') {
$('#availableLiveStream').empty();
if (isArray(response)) {
for (var i in response) {
if (typeof response[i] !== 'object') {
continue;
}
if (!response.total) {
availableLiveStreamNotFound();
} else {
$('#availableLiveStream').removeClass('notfound');
}
$('.onlineApplications').text(response.total);
processApplicationLive(response[i]);
}
} else {
processApplicationLive(response);
}
if (!response.countLiveStream) {
availableLiveStreamNotFound();
} else {
$('#availableLiveStream').removeClass('notfound');
}
$('.onlineApplications').text(response.countLiveStream);
}
setTimeout(function () {
setTimeout(function () {
<?php
if (!empty($obj->playLiveInFullScreenOnIframe)) {
echo 'if (typeof linksToFullscreen === \'function\') {linksToFullscreen(\'.liveVideo a, #availableLiveStream a\');}';
@ -200,11 +205,26 @@ if (!empty($obj->playLiveInFullScreenOnIframe)) {
echo 'if (typeof linksToEmbed === \'function\') {linksToEmbed(\'.liveVideo a, #availableLiveStream a\');}';
}
?>
}, 200);
}, 200);
}
function getStatsMenu(recurrentCall) {
if (avideoSocketIsActive()) {
return false;
}
availableLiveStreamIsLoading();
$.ajax({
url: webSiteRootURL + 'plugin/Live/stats.json.php?Menu<?php echo (!empty($_GET['videoName']) ? "&requestComesFromVideoPage=1" : "") ?>',
success: function (response) {
if (avideoSocketIsActive()) {
return false;
}
processLiveStats(response);
if (recurrentCall) {
var timeOut = <?php echo $obj->requestStatsInterval * 1000; ?>;
setTimeout(function () {
getStatsMenu(true);
}, <?php echo $obj->requestStatsInterval * 1000; ?>);
}, timeOut);
}
}
});
@ -303,8 +323,30 @@ if (!empty($obj->playLiveInFullScreenOnIframe)) {
}
}
function socketLiveONCallback(json) {
console.log('socketLiveONCallback', json);
processLiveStats(json.stats);
$('.live_' + json.live_servers_id + "_" + json.key).slideDown();
var selector = '#liveViewStatusID_' + json.key + '_' + json.live_servers_id;
onlineLabelOnline(selector);
}
function socketLiveOFFCallback(json) {
console.log('socketLiveOFFCallback', json);
processLiveStats(json.stats);
$('.live_' + json.live_servers_id + "_" + json.key).slideUp();
var selector = '#liveViewStatusID_' + json.key + '_' + json.live_servers_id;
onlineLabelOffline(selector);
}
$(document).ready(function () {
availableLiveStreamIsLoading();
getStatsMenu(true);
if (!avideoSocketIsActive()) {
availableLiveStreamIsLoading();
getStatsMenu(true);
}
<?php
if (AVideoPlugin::isEnabledByName('Socket')) {
echo 'processLiveStats(' . json_encode(Live::getStats()) . ');';
}
?>
});
</script>

View file

@ -21,6 +21,7 @@ if (!empty($_GET['c'])) {
}
$livet = LiveTransmition::getFromDbByUserName($_GET['u']);
$getLiveKey = array('key'=>$livet['key'], 'live_servers_id'=> Live::getLiveServersIdRequest());
$lt = new LiveTransmition($livet['id']);
if (!$lt->userCanSeeTransmition()) {
forbiddenPage("You are not allowed see this streaming");

View file

@ -1,14 +1,16 @@
<?php
$live_servers_id = Live::getCurrentLiveServersId();
$liveViewStatusID = "liveViewStatusID_{$streamName}_{$live_servers_id}";
$liveViewStatusClass = "liveViewStatusClass liveViewStatusClass_{$streamName} liveViewStatusClass_{$streamName}_{$live_servers_id}";
?>
<span class="label label-danger" id="liveViewStatus<?php echo $live_servers_id; ?>">OFFLINE</span>
<span class="label label-danger liveOnlineLabel <?php $liveViewStatusClass ?>" id="<?php echo $liveViewStatusID; ?>">OFFLINE</span>
<script>
function isOfflineVideo() {
<?php
if(isMobile()){
?>
return !$('#liveViewStatus<?php echo $live_servers_id; ?>').hasClass('isOnline');
return !$('#<?php echo $liveViewStatusID; ?>').hasClass('isOnline');
<?php
}else{
?>
@ -34,40 +36,32 @@ $live_servers_id = Live::getCurrentLiveServersId();
return true;
}
var isOnlineLabel = false;
var playCorrectSource<?php echo $live_servers_id; ?>Timout;
function playCorrectSource<?php echo $live_servers_id; ?>() {
var playCorrectSource<?php echo $liveViewStatusID; ?>Timout;
function playCorrectSource<?php echo $liveViewStatusID; ?>() {
if(typeof player === 'undefined'){
clearTimeout(playCorrectSource<?php echo $live_servers_id; ?>Timout);
playCorrectSource<?php echo $live_servers_id; ?>Timout = setTimeout(function () {
playCorrectSource<?php echo $live_servers_id; ?>();
clearTimeout(playCorrectSource<?php echo $liveViewStatusID; ?>Timout);
playCorrectSource<?php echo $liveViewStatusID; ?>Timout = setTimeout(function () {
playCorrectSource<?php echo $liveViewStatusID; ?>();
}, 1000);
return false;
}
var bigPlayButtonModified = false;
if($('#liveViewStatus<?php echo $live_servers_id; ?>').hasClass('isOnline') && !isOfflineVideo()){
if($('#<?php echo $liveViewStatusID; ?>').hasClass('isOnline') && !isOfflineVideo()){
isOnlineLabel=true;
player.bigPlayButton.show();
bigPlayButtonModified = true;
console.log("Change video to Online");
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-warning');
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-danger');
$('#liveViewStatus<?php echo $live_servers_id; ?>').addClass('label-success');
$('#liveViewStatus<?php echo $live_servers_id; ?>').text("<?php echo __("ONLINE"); ?>");
onlineLabelOnline('#<?php echo $liveViewStatusID; ?>');
//playerPlayIfAutoPlay(0);
clearTimeout(_reloadVideoJSTimeout<?php echo $live_servers_id; ?>);
clearTimeout(_reloadVideoJSTimeout<?php echo $liveViewStatusID; ?>);
if (isAutoplayEnabled() && !player.paused()) {
player.play();
}
}else if ($('#liveViewStatus<?php echo $live_servers_id; ?>').hasClass('isOnline') && isOfflineVideo()) {
}else if ($('#<?php echo $liveViewStatusID; ?>').hasClass('isOnline') && isOfflineVideo()) {
isOnlineLabel=true;
player.bigPlayButton.show();
bigPlayButtonModified = true;
console.log("Change video to please wait");
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-success');
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-danger');
$('#liveViewStatus<?php echo $live_servers_id; ?>').addClass('label-warning');
$('#liveViewStatus<?php echo $live_servers_id; ?>').text("<?php echo __("Please Wait ..."); ?>");
reloadVideoJSTimeout<?php echo $live_servers_id; ?>(10000);
onlineLabelPleaseWait('#<?php echo $liveViewStatusID; ?>');
reloadVideoJSTimeout<?php echo $liveViewStatusID; ?>(10000);
//reloadVideoJS();
//playerPlayIfAutoPlay(0);
if (isAutoplayEnabled() && !player.paused()) {
@ -80,18 +74,15 @@ $live_servers_id = Live::getCurrentLiveServersId();
console.log("PError 2 "+player.error());
console.log("PError 2.1 "+this.error());
});
clearTimeout(playCorrectSource<?php echo $live_servers_id; ?>Timout);
playCorrectSource<?php echo $live_servers_id; ?>Timout = setTimeout(function () {
playCorrectSource<?php echo $live_servers_id; ?>();
clearTimeout(playCorrectSource<?php echo $liveViewStatusID; ?>Timout);
playCorrectSource<?php echo $liveViewStatusID; ?>Timout = setTimeout(function () {
playCorrectSource<?php echo $liveViewStatusID; ?>();
getStats<?php echo $liveViewStatusID; ?>();
}, 5000);
} else if (!$('#liveViewStatus<?php echo $live_servers_id; ?>').hasClass('isOnline') && !isOfflineVideo()) {
} else if (!$('#<?php echo $liveViewStatusID; ?>').hasClass('isOnline') && !isOfflineVideo()) {
if (player.readyState() <= 2) {
isOnlineLabel=false;
console.log("Change video to offline");
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-warning');
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-success');
$('#liveViewStatus<?php echo $live_servers_id; ?>').addClass('label-danger');
$('#liveViewStatus<?php echo $live_servers_id; ?>').text("<?php echo __("OFFLINE"); ?>");
onlineLabelOffline('#<?php echo $liveViewStatusID; ?>');
player.pause();
//player.reset();
$('#mainVideo.liveVideo').find('.vjs-poster').css({'background-image': 'url(<?php echo $global['webSiteRootURL']; ?>plugin/Live/view/Offline.jpg)'});
@ -103,18 +94,15 @@ $live_servers_id = Live::getCurrentLiveServersId();
player.on('play', function(){
$('#mainVideo.liveVideo').find('.vjs-poster').fadeOut();
});
//reloadVideoJSTimeout<?php echo $live_servers_id; ?>(10000);
//reloadVideoJSTimeout<?php echo $liveViewStatusID; ?>(10000);
//reloadVideoJS();
//playerPlay(0);
} else {
console.log("Change video to finishing");
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-warning');
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('label-success');
$('#liveViewStatus<?php echo $live_servers_id; ?>').addClass('label-danger');
$('#liveViewStatus<?php echo $live_servers_id; ?>').text("<?php echo __("Finishing Live..."); ?>");
clearTimeout(playCorrectSource<?php echo $live_servers_id; ?>Timout);
playCorrectSource<?php echo $live_servers_id; ?>Timout = setTimeout(function () {
playCorrectSource<?php echo $live_servers_id; ?>();
onlineLabelFinishing('#<?php echo $liveViewStatusID; ?>');
clearTimeout(playCorrectSource<?php echo $liveViewStatusID; ?>Timout);
playCorrectSource<?php echo $liveViewStatusID; ?>Timout = setTimeout(function () {
playCorrectSource<?php echo $liveViewStatusID; ?>();
getStats<?php echo $liveViewStatusID; ?>();
}, 15000);
}
}
@ -123,44 +111,52 @@ $live_servers_id = Live::getCurrentLiveServersId();
}
}
var _reloadVideoJSTimeout<?php echo $live_servers_id; ?>;
function reloadVideoJSTimeout<?php echo $live_servers_id; ?>(timeout){
if(_reloadVideoJSTimeout<?php echo $live_servers_id; ?>){
var _reloadVideoJSTimeout<?php echo $liveViewStatusID; ?>;
function reloadVideoJSTimeout<?php echo $liveViewStatusID; ?>(timeout){
if(_reloadVideoJSTimeout<?php echo $liveViewStatusID; ?>){
return false;
}
_reloadVideoJSTimeout<?php echo $live_servers_id; ?> = setTimeout(function(){reloadVideoJS();},timeout);
_reloadVideoJSTimeout<?php echo $liveViewStatusID; ?> = setTimeout(function(){reloadVideoJS();},timeout);
}
function getStats<?php echo $live_servers_id; ?>() {
function getStats<?php echo $liveViewStatusID; ?>() {
if(avideoSocketIsActive()){
return false;
}
var timeout = 10000;
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>plugin/Live/stats.json.php?live_servers_id=<?php echo $live_servers_id; ?>&Label',
url: webSiteRootURL+'plugin/Live/stats.json.php?live_servers_id=<?php echo $live_servers_id; ?>&Label',
data: {"name": "<?php echo $streamName; ?>"},
type: 'post',
success: function (response) {
if(avideoSocketIsActive()){
return false;
}
if(response.name == "<?php echo $streamName; ?>"){
if (response.msg === "ONLINE") {
isOnlineLabel=true;
$('#liveViewStatus<?php echo $live_servers_id; ?>').addClass('isOnline');
$('#<?php echo $liveViewStatusID; ?>').addClass('isOnline');
} else {
isOnlineLabel=false;
$('#liveViewStatus<?php echo $live_servers_id; ?>').removeClass('isOnline');
$('#<?php echo $liveViewStatusID; ?>').removeClass('isOnline');
}
playCorrectSource<?php echo $live_servers_id; ?>();
playCorrectSource<?php echo $liveViewStatusID; ?>();
$('.liveViewCount').text(" " + response.nclients);
$('#liveViewStatus<?php echo $live_servers_id; ?>').text(response.msg);
$('#<?php echo $liveViewStatusID; ?>').text(response.msg);
$('#onlineApplications').text(response.applications.lenght);
timeout = 15000;
}
setTimeout(function () {
getStats<?php echo $live_servers_id; ?>();
getStats<?php echo $liveViewStatusID; ?>();
}, timeout);
}
});
}
$(document).ready(function () {
getStats<?php echo $live_servers_id; ?>();
if(!avideoSocketIsActive()){
getStats<?php echo $liveViewStatusID; ?>();
}
});
</script>

View file

@ -8,13 +8,15 @@ if (empty($lu) || $lu->doNotDisplayCounter) {
}
if (empty($lu->doNotDisplayLiveCounter)) {
$liveUsersOnlineClass = "liveUsersOnline_{$streamName} liveUsersOnline_{$streamName}_".Live::getAvailableLiveServer();
?>
<span class="label label-primary" data-toggle="tooltip" title="<?php echo __("Watching Now"); ?>" data-placement="bottom" ><i class="fa fa-eye"></i> <b class="liveUsersOnline_<?php echo $streamName; ?>">0</b></span>
<span class="label label-primary" data-toggle="tooltip" title="<?php echo __("Watching Now"); ?>" data-placement="bottom" ><i class="fa fa-eye"></i> <b class="total_on_same_live liveUsersOnline <?php echo $liveUsersOnlineClass; ?>">0</b></span>
<?php
}
if (empty($lu->doNotDisplayTotal)) {
$liveUsersViewsClass = "liveUsersViews_{$streamName} liveUsersViews_{$streamName}_".Live::getAvailableLiveServer();
?>
<span class="label label-default" data-toggle="tooltip" title="<?php echo __("Total Views"); ?>" data-placement="bottom" ><i class="fa fa-user"></i> <b class="liveUsersViews_<?php echo $streamName; ?>">0</b></span>
<span class="label label-default" data-toggle="tooltip" title="<?php echo __("Total Views"); ?>" data-placement="bottom" ><i class="fa fa-user"></i> <b class="liveUsersViews <?php echo $liveUsersViewsClass; ?>">0</b></span>
<?php
}
?>

View file

@ -14,6 +14,7 @@ if (!empty($_GET['c'])) {
$customizedAdvanced = AVideoPlugin::getObjectDataIfEnabled('CustomizeAdvanced');
$livet = LiveTransmition::getFromDbByUserName($_GET['u']);
$getLiveKey = array('key'=>$livet['key'], 'live_servers_id'=> Live::getLiveServersIdRequest());
$uuid = LiveTransmition::keyNameFix($livet['key']);
$p = AVideoPlugin::loadPlugin("Live");
$objSecure = AVideoPlugin::loadPluginIfEnabled('SecureVideosDirectory');

View file

@ -20,6 +20,7 @@ if (!empty($_GET['c'])) {
$customizedAdvanced = AVideoPlugin::getObjectDataIfEnabled('CustomizeAdvanced');
$livet = LiveTransmition::getFromDbByUserName($_GET['u']);
$getLiveKey = array('key'=>$livet['key'], 'live_servers_id'=> Live::getLiveServersIdRequest());
$uuid = LiveTransmition::keyNameFix($livet['key']);
$p = AVideoPlugin::loadPlugin("Live");

View file

@ -505,6 +505,14 @@ abstract class PluginAbstract {
function getDataObjectHelper(){
return $this->dataObjectHelper;
}
function onUserSocketConnect($users_id, $data){
}
function onUserSocketDisconnect($users_id, $data){
}
}

View file

@ -10,7 +10,7 @@ require_once $global['systemRootPath'] . 'plugin/Socket/functions.php';
class Message implements MessageComponentInterface {
protected $clients, $clients_users_id;
protected $clients;
public function __construct() {
//$this->clients = new \SplObjectStorage;
@ -19,57 +19,85 @@ class Message implements MessageComponentInterface {
}
public function onOpen(ConnectionInterface $conn) {
_log_message("New connection! ({$conn->resourceId})");
global $onMessageSentTo;
$onMessageSentTo = array();
$query = $conn->httpRequest->getUri()->getQuery();
parse_str($query, $wsocketToken);
if (empty($wsocketToken['webSocketToken'])) {
_log_message("Empty websocket token ");
return false;
}
$json = getDecryptedInfo($wsocketToken['webSocketToken']);
if (empty($json)) {
_log_message("Invalid websocket token ");
return false;
}
// Store the new connection to send messages to later
//$this->clients->attach($conn);
if (!isset($this->clients[$conn->resourceId])) {
$this->clients[$conn->resourceId] = array();
}
$this->clients[$conn->resourceId]['conn'] = $conn;
$this->clients[$conn->resourceId]['users_id'] = $json->from_users_id;
$this->clients[$conn->resourceId]['yptDeviceId'] = $json->yptDeviceId;
$this->clients[$conn->resourceId]['selfURI'] = $json->selfURI;
$this->clients[$conn->resourceId]['isCommandLine'] = $wsocketToken['isCommandLine'];
$this->clients[$conn->resourceId]['videos_id'] = $json->videos_id;
$this->clients[$conn->resourceId]['live_key'] = object_to_array(@$json->live_key);
$this->clients[$conn->resourceId]['autoEvalCodeOnHTML'] = $json->autoEvalCodeOnHTML;
self::msgToResourceId("Connection opened", $conn->resourceId);
_log_message("New connection ");
if ($this->shouldPropagateInfo($this->clients[$conn->resourceId])) {
_log_message("shouldPropagateInfo ");
$this->msgToAll($conn, array(), \SocketMessageType::NEW_CONNECTION, true);
\AVideoPlugin::onUserSocketConnect($json->from_users_id, $this->clients[$conn->resourceId]);
} else {
_log_message("NOT shouldPropagateInfo ");
}
if (!empty($json->videos_id)) {
_log_message("msgToAllSameVideo ");
$this->msgToAllSameVideo($json->videos_id, "");
} else {
_log_message("NOT msgToAllSameVideo ");
}
if (!empty($json->live_key)) {
_log_message("msgToAllSameLive ");
$this->msgToAllSameLive($json->live_key, "");
} else {
_log_message("NOT msgToAllSameLive ");
}
}
public function msgToResourceId($msg, $resourceId) {
if(!is_array($msg)){
$this->msgToArray($msg);
}
$msg['ResourceId'] = $resourceId;
$msg = json_encode($msg);
_log_message("msgToUser: resourceId=({$resourceId}) {$msg}");
$this->clients[$resourceId]['conn']->send($msg);
}
public function onClose(ConnectionInterface $conn) {
global $getStatsLive, $_getStats, $onMessageSentTo;
$onMessageSentTo = array();
public function msgToUsers_id($msg, $users_id) {
if(empty($users_id)){
return false;
unset($getStatsLive);
unset($_getStats);
_log_message("Connection {$conn->resourceId} has disconnected");
// The connection is closed, remove it, as we can no longer send it messages
//$this->clients->detach($conn);
$users_id = $this->clients[$conn->resourceId]['users_id'];
$videos_id = $this->clients[$conn->resourceId]['videos_id'];
$live_key = $this->clients[$conn->resourceId]['live_key'];
if ($this->shouldPropagateInfo($this->clients[$conn->resourceId])) {
$this->msgToAll($conn, array(), \SocketMessageType::NEW_DISCONNECTION, true);
\AVideoPlugin::onUserSocketDisconnect($users_id, $this->clients[$conn->resourceId]);
}
$this->clients[$from->resourceId]['users_id'];
$count = 0;
foreach ($this->clients as $resourceId => $value) {
if($value['users_id'] == $users_id){
$count++;
$this->msgToResourceId($msg, $resourceId);
}
}
_log_message("msgToUsers_id: sent to ($count) clients users_id={$users_id}");
}
public function msgToAll(ConnectionInterface $from, $msg) {
_log_message("msgToAll");
$numRecv = count($this->clients) - 1;
//_log_message(sprintf('Connection %d sending message "%s" to %d other connection%s' . PHP_EOL , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's'));
foreach ($this->clients as $key => $client) {
if ($from !== $client['conn']) {
$this->msgToResourceId($msg, $key);
}
unset($this->clients[$conn->resourceId]);
if (!empty($videos_id)) {
$this->msgToAllSameVideo($videos_id, "");
}
if (!empty($live_key)) {
$this->msgToAllSameLive($live_key, "");
}
}
public function onMessage(ConnectionInterface $from, $msg) {
_log_message("onMessage: {$msg}");
global $onMessageSentTo;
$onMessageSentTo = array();
//_log_message("onMessage: {$msg}");
$json = json_decode($msg);
if (empty($json)) {
_log_message("onMessage ERROR: JSON is empty ");
@ -79,6 +107,7 @@ class Message implements MessageComponentInterface {
_log_message("onMessage ERROR: webSocketToken is empty ");
return false;
}
if (!$msgObj = getDecryptedInfo($json->webSocketToken)) {
_log_message("onMessage ERROR: could not decrypt webSocketToken");
return false;
@ -87,54 +116,304 @@ class Message implements MessageComponentInterface {
switch ($json->msg) {
case "webSocketToken":
if (empty($this->clients[$from->resourceId]['users_id'])) {
_log_message("onMessage: set users_id {$msgObj->users_id}");
$this->clients[$from->resourceId]['users_id'] = $msgObj->users_id;
_log_message("onMessage:webSocketToken");
$this->clients[$from->resourceId]['users_id'] = $msgObj->from_users_id;
$this->clients[$from->resourceId]['yptDeviceId'] = $msgObj->yptDeviceId;
}
break;
default:
$this->msgToArray($json);
if (!empty($json['to_users_id'])) {
$this->msgToUsers_id($json['msg'], $json['to_users_id']);
_log_message("onMessage:msgObj: " . json_encode($json));
if (!empty($msgObj->send_to_uri_pattern)) {
$this->msgToSelfURI($json, $msgObj->send_to_uri_pattern);
} else if (!empty($json['to_users_id'])) {
$this->msgToUsers_id($json, $json['to_users_id']);
} else {
$this->msgToAll($from, $json['msg']);
$this->msgToAll($from, $json);
}
break;
}
}
private function msgToArray(&$json){
$json = $this->makeSureIsArray($json);
$msg = $this->makeSureIsArray(@$json['msg']);
$msg['callback'] = @$json['callback'];
$msg['uniqid'] = uniqid();
$json['msg'] = $msg;
private function shouldPropagateInfo($connection) {
if ($connection['yptDeviceId'] == 'unknowDevice') {
return false;
}
if (!empty($connection['isCommandLine'])) {
return false;
}
return true;
}
public function msgToResourceId($msg, $resourceId, $type = "") {
global $onMessageSentTo;
if (in_array($resourceId, $onMessageSentTo)) {
return false;
}
// do not sent duplicated messages
$onMessageSentTo[] = $resourceId;
if (!is_array($msg)) {
$this->msgToArray($msg);
}
if(!empty($msg['webSocketToken'])){
unset($msg['webSocketToken']);
}
if (empty($type)) {
$type = \SocketMessageType::DEFAULT_MESSAGE;
}
$videos_id = $this->clients[$resourceId]['videos_id'];
$users_id = $this->clients[$resourceId]['users_id'];
$live_key = $this->clients[$resourceId]['live_key'];
$obj = array();
$obj['ResourceId'] = $resourceId;
$obj['type'] = $type;
if(isset($msg['callback'])){
$obj['callback'] = $msg['callback'];
unset($msg['callback']);
}else{
$obj['callback'] = "";
}
if(!empty($msg['json'])){
$obj['msg'] = $msg['json'];
}else if(!empty($msg['msg'])){
$obj['msg'] = $msg['msg'];
}else{
$obj['msg'] = $msg;
}
$obj['uniqid'] = uniqid();
$obj['users_id'] = $users_id;
$obj['videos_id'] = $videos_id;
$obj['live_key'] = $live_key;
$obj['autoUpdateOnHTML'] = array(
'socket_users_id' => $users_id,
'socket_resourceId' => $resourceId,
'total_devices_online' => count($this->getUsersIdFromDevicesOnline()),
'totalConnections' => count($this->clients),
'usersonline_per_video' => $this->getTotalPerVideo(),
'total_on_same_video' => $this->getTotalOnVideos_id($videos_id),
'total_on_same_live' => $this->getTotalOnlineOnLive_key($live_key)
);
$obj['autoEvalCodeOnHTML'] = $this->clients[$resourceId]['autoEvalCodeOnHTML'];
$msgToSend = json_encode($obj);
_log_message("msgToResourceId: resourceId=({$resourceId})");
$this->clients[$resourceId]['conn']->send($msgToSend);
}
public function msgToUsers_id($msg, $users_id, $type = "") {
if (empty($users_id)) {
return false;
}
$count = 0;
foreach ($this->clients as $resourceId => $value) {
if ($value['users_id'] == $users_id) {
$count++;
$this->msgToResourceId($msg, $resourceId, $type);
}
}
_log_message("msgToUsers_id: sent to ($count) clients users_id={$users_id}");
}
public function msgToSelfURI($msg, $pattern, $type = "") {
if (empty($pattern)) {
return false;
}
$count = 0;
foreach ($this->clients as $resourceId => $value) {
if (empty($value['selfURI'])) {
continue;
}
if (preg_match($pattern, $value['selfURI'])) {
$count++;
$this->msgToResourceId($msg, $resourceId, $type);
}
}
_log_message("msgToSelfURI: sent to ($count) clients pattern={$pattern} ");
}
public function getTotalSelfURI($pattern) {
if (empty($videos_id)) {
return false;
}
$count = 0;
foreach ($this->clients as $key => $client) {
if (empty($client['selfURI'])) {
continue;
}
if (preg_match($pattern, $client['selfURI'])) {
$count++;
}
}
_log_message("getTotalSelfURI: total ($count) clients pattern={$pattern} ");
return $count;
}
public function getTotalPerVideo() {
$videos = array();
foreach ($this->clients as $key => $client) {
if (empty($client['videos_id'])) {
continue;
}
if (!isset($videos[$client['videos_id']])) {
$videos[$client['videos_id']] = array('videos_id' => $client['videos_id'], 'total' => 1);
} else {
$videos[$client['videos_id']]['total']++;
}
}
return $videos;
}
public function msgToDevice_id($msg, $yptDeviceId) {
if (empty($yptDeviceId)) {
return false;
}
$count = 0;
foreach ($this->clients as $resourceId => $value) {
if ($value['yptDeviceId'] == $yptDeviceId) {
$count++;
$this->msgToResourceId($msg, $resourceId);
}
}
_log_message("msgToDevice_id: sent to ($count) clients yptDeviceId={$yptDeviceId}");
}
public function getUsersIdFromDevicesOnline() {
$devices = array();
foreach ($this->clients as $value) {
if (empty($value['yptDeviceId'])) {
continue;
}
if (!in_array($value['yptDeviceId'], $devices) && $this->shouldPropagateInfo($value)) {
$array = array(
'users_id' => $value['users_id'],
'yptDeviceId' => $value['yptDeviceId'],
'selfURI'=>$value['selfURI'] //removed for security reasons
);
$devices[] = $array;
}
}
$total = count($devices);
//_log_message("getUsersIdFromDevicesOnline: {$total}/" . count($this->clients));
return $devices;
}
public function msgToAll(ConnectionInterface $from, $msg, $type = "", $includeMe = false) {
_log_message("msgToAll {$type}");
foreach ($this->clients as $key => $client) {
if (!empty($includeMe) || $from !== $client['conn']) {
$this->msgToResourceId($msg, $key, $type);
}
}
}
public function getTotalOnVideos_id($videos_id) {
if (empty($videos_id)) {
return false;
}
//_log_message("getTotalOnVideos_id: {$videos_id}");
$count = 0;
foreach ($this->clients as $key => $client) {
if (empty($client['videos_id'])) {
continue;
}
if ($client['videos_id'] == $videos_id) {
$count++;
}
}
return $count;
}
private function makeSureIsArray($msg){
if(empty($msg)){
public function getTotalOnlineOnLive_key($live_key) {
if (empty($live_key)) {
return false;
}
$live_key = object_to_array($live_key);
//_log_message("getTotalOnlineOnLive_key: key={$live_key['key']} live_servers_id={$live_key['live_servers_id']}");
$count = 0;
foreach ($this->clients as $key => $client) {
if (empty($client['live_key'])) {
continue;
}
if ($client['live_key']['key'] == $live_key['key'] && $client['live_key']['live_servers_id'] == $live_key['live_servers_id']) {
$count++;
}
}
return $count;
}
public function msgToAllSameVideo($videos_id, $msg) {
if (empty($videos_id)) {
return false;
}
if (!is_array($msg)) {
$this->msgToArray($msg);
}
$msg['total'] = $this->getTotalOnVideos_id($videos_id);
$msg['videos_id'] = $videos_id;
_log_message("msgToAllSameVideo: {$videos_id}");
foreach ($this->clients as $key => $client) {
if (empty($client['videos_id'])) {
continue;
}
if ($client['videos_id'] == $videos_id) {
$this->msgToResourceId($msg, $key, \SocketMessageType::ON_VIDEO_MSG);
}
}
}
public function msgToAllSameLive($live_key, $msg) {
if (empty($live_key)) {
return false;
}
$live_key = object_to_array($live_key);
if (!is_array($msg)) {
$this->msgToArray($msg);
}
_mysql_connect();
$msg['is_live'] = \Live::isLiveAndIsReadyFromKey($live_key['key'], $live_key['live_servers_id'], true);
_mysql_close();
_log_message("msgToAllSameLive: key={$live_key['key']} live_servers_id={$live_key['live_servers_id']}");
foreach ($this->clients as $key => $client) {
if (empty($client['live_key'])) {
continue;
}
if ($client['live_key']['key'] == $live_key['key'] && $client['live_key']['live_servers_id'] == $live_key['live_servers_id']) {
$this->msgToResourceId($msg, $key, \SocketMessageType::ON_LIVE_MSG);
}
}
}
private function msgToArray(&$json) {
$json = $this->makeSureIsArray($json);
return true;
}
private function makeSureIsArray($msg) {
if (empty($msg)) {
return array();
}
if(is_string($msg)){
if (is_string($msg)) {
$decoded = json_decode($msg);
}else{
} else {
$decoded = object_to_array($msg);
}
if(is_string($msg) && !$decoded){
if (is_string($msg) && !$decoded) {
return array($msg);
}else if(is_string($msg)){
} else if (is_string($msg)) {
return object_to_array($decoded);
}
return object_to_array($msg);
}
public function onClose(ConnectionInterface $conn) {
_log_message("Connection {$conn->resourceId} has disconnected");
// The connection is closed, remove it, as we can no longer send it messages
//$this->clients->detach($conn);
unset($this->clients[$conn->resourceId]);
}
public function onError(ConnectionInterface $conn, \Exception $e) {
_log_message("An error has occurred: {$e->getMessage()}");
$conn->close();

View file

@ -60,56 +60,68 @@ class Socket extends PluginAbstract {
public function getFooterCode() {
self::getSocketJS();
}
public static function getSocketJS() {
global $global;
$socketobj = AVideoPlugin::getDataObject("Socket");
$address = parse_url($global['webSiteRootURL'], PHP_URL_HOST);
$port = $socketobj->port;
include $global['systemRootPath'] . 'plugin/Socket/footer.php';
}
public static function send($msg, $callbackJSFunction="", $users_id="") {
global $global, $SocketSendObj;
$socketobj = AVideoPlugin::getDataObject("Socket");
$address = "localhost";
$port = $socketobj->port;
public static function send($msg, $callbackJSFunction = "", $users_id = "", $send_to_uri_pattern = "") {
global $global, $SocketSendObj, $SocketSendUsers_id, $SocketSendResponseObj;
if(!is_string($msg)){
$msg = json_encode($msg);
}
$SocketSendUsers_id = $users_id;
if(!is_array($SocketSendUsers_id)){
$SocketSendUsers_id = array($SocketSendUsers_id);
}
$SocketSendObj = new stdClass();
$SocketSendObj->webSocketToken = getEncryptedInfo();
$SocketSendObj->webSocketToken = getEncryptedInfo(0,$send_to_uri_pattern);
$SocketSendObj->msg = $msg;
$SocketSendObj->json = json_decode($msg);
$SocketSendObj->to_users_id = $users_id;
$SocketSendObj->callback = $callbackJSFunction;
$obj = new stdClass();
$obj->error = true;
$obj->msg = "";
$obj->msgObj = $SocketSendObj;
$obj->callbackJSFunction = $callbackJSFunction;
$SocketSendResponseObj = new stdClass();
$SocketSendResponseObj->error = true;
$SocketSendResponseObj->msg = "";
$SocketSendResponseObj->msgObj = $SocketSendObj;
$SocketSendResponseObj->callbackJSFunction = $callbackJSFunction;
require_once $global['systemRootPath'] . 'objects/autoload.php';
\Ratchet\Client\connect("ws://{$address}:{$port}")->then(function($conn) {
global $SocketSendObj;
\Ratchet\Client\connect(self::getWebSocketURL(true, true))->then(function($conn) {
global $SocketSendObj, $SocketSendUsers_id, $SocketSendResponseObj;
$conn->on('message', function($msg) use ($conn) {
//echo "Received: {$msg}\n";
$conn->close();
//$conn->close();
$SocketSendResponseObj->error = false;
});
$conn->send(json_encode($SocketSendObj));
foreach ($SocketSendUsers_id as $users_id) {
$SocketSendObj->to_users_id = $users_id;
$conn->send(json_encode($SocketSendObj));
}
$conn->close();
//$SocketSendResponseObj->error = false;
}, function ($e) {
echo "Could not connect: {$e->getMessage()}\n";
});
return $obj;
return $SocketSendResponseObj;
}
public static function getWebSocketURL($useLocalHost = true, $isCommandLine=false) {
global $global;
$socketobj = AVideoPlugin::getDataObject("Socket");
$address = "localhost";
if (empty($useLocalHost)) {
$address = parse_url($global['webSiteRootURL'], PHP_URL_HOST);
}
$port = $socketobj->port;
return "ws://{$address}:{$port}?webSocketToken=".getEncryptedInfo(0)."&isCommandLine=".intval($isCommandLine);
}
}

View file

@ -0,0 +1,7 @@
<?php
require_once dirname(__FILE__) . '/../../videos/configuration.php';
if(!isCommandLineInterface()){
//die("Command line only");
}

View file

@ -1,4 +1,16 @@
<?php
$refl = new ReflectionClass('SocketMessageType');
?>
<div style="position: fixed; top: 60px; left: 20px; background: #CCC; border: solid 2px black; padding: 5px;">
<div><b>users_id</b> <span class="socket_users_id">0</span></div>
<div><b>ResourceId</b> <span class="socket_resourceId">0</span></div>
<div><b>totalDevicesOnline</b> <span class="total_devices_online">0</span></div>
<div><b>onlineOnThisVideo</b> <span class="total_on_same_video">0</span></div>
<div><b>onlineOnThisLive</b> <span class="total_on_same_live">0</span></div>
</div>
<script>
var webSocketURL = '<?php echo "ws:{$address}:{$port}"?>';
var webSocketToken = '<?php echo getEncryptedInfo(0); ?>';
var webSocketURL = '<?php echo Socket::getWebSocketURL(true); ?>';
var webSocketTypes = <?php echo json_encode($refl->getConstants()); ?>;
</script>
<script src="<?php echo $global['webSiteRootURL']; ?>plugin/Socket/script.js" type="text/javascript"></script>

View file

@ -1,11 +1,33 @@
<?php
function getEncryptedInfo() {
function getEncryptedInfo($timeOut = 0, $send_to_uri_pattern = "") {
if (empty($timeOut)) {
$timeOut = 43200; // valid for 12 hours
}
$msgObj = new stdClass();
$msgObj->users_id = User::getId();
$msgObj->token = getToken(43200); // valid for 12 hours
$msgObj->from_users_id = User::getId();
$msgObj->yptDeviceId = getDeviceID();
$msgObj->token = getToken($timeOut);
$msgObj->time = time();
$msgObj->selfURI = getSelfURI();
$msgObj->send_to_uri_pattern = $send_to_uri_pattern;
$msgObj->autoEvalCodeOnHTML = array();
if (empty($msgObj->videos_id)) {
$msgObj->videos_id = getVideos_id();
}
if (empty($msgObj->live_key)) {
$msgObj->live_key = isLive();
}
if (!empty($msgObj->live_key)) {
$msgObj->is_live = Live::isLiveAndIsReadyFromKey($msgObj->live_key['key'], $msgObj->live_key['live_servers_id'], true);
if($msgObj->is_live){
$code = "onlineLabelOnline('.liveOnlineLabel');";
}else{
$code = "onlineLabelOffline('.liveOnlineLabel');";
}
$msgObj->autoEvalCodeOnHTML[] = $code;
}
return encryptString(json_encode($msgObj));
}
@ -23,3 +45,32 @@ function getDecryptedInfo($string) {
}
return false;
}
class SocketMessageType {
const NEW_CONNECTION = "NEW_CONNECTION";
const NEW_DISCONNECTION = "NEW_DISCONNECTION";
const DEFAULT_MESSAGE = "DEFAULT_MESSAGE";
const ON_VIDEO_MSG = "ON_VIDEO_MSG";
const ON_LIVE_MSG = "ON_LIVE_MSG";
}
function getTotalViewsLive_key($live_key) {
if (empty($live_key)) {
return false;
}
$live_key = object_to_array($live_key);
_mysql_connect();
$liveUsersEnabled = \AVideoPlugin::isEnabledByName("LiveUsers");
if ($liveUsersEnabled) {
$liveUsers = new \LiveOnlineUsers(0);
$total = $liveUsers->getTotalUsersFromTransmitionKey($live_key['key'], $live_key['live_servers_id']);
} else {
$total = null;
}
_mysql_close();
return $total;
}

View file

@ -1,40 +1,49 @@
var socketMyResourceId = 0;
var socketConnectRequested = 0;
var totalDevicesOnline = 0;
function socketConnect() {
if(socketConnectRequested){
if (socketConnectRequested) {
return false;
}
socketConnectRequested = 1;
console.log('Trying to reconnect on ' + webSocketURL);
console.log('Trying to reconnect on socket...');
conn = new WebSocket(webSocketURL);
conn.onopen = function (e) {
console.log("Socket onopen", e);
socketMyResourceId = 0;
sendSocketMessageToNone("webSocketToken", "");
console.log("Socket onopen");
return false;
};
conn.onmessage = function (e) {
//console.log("Socket onmessage", e);
var json = JSON.parse(e.data);
console.log("Socket onmessage", json);
if (!socketMyResourceId) {
socketMyResourceId = parseInt(json.ResourceId);
var msg = "Socket socketMyResourceId " + socketMyResourceId;
//sendSocketMessage(msg, "", "");
console.log(msg);
parseSocketResponse(json);
if (json.type == webSocketTypes.ON_VIDEO_MSG) {
console.log("Socket onmessage ON_VIDEO_MSG", json);
$('.videoUsersOnline, .videoUsersOnline_' + json.videos_id).text(json.total);
}
if (json.type == webSocketTypes.ON_LIVE_MSG) {
console.log("Socket onmessage ON_LIVE_MSG", json);
var selector = '#liveViewStatusID_' + json.live_key.key + '_' + json.live_key.live_servers_id;
if (json.is_live) {
onlineLabelOnline(selector);
} else {
onlineLabelOffline(selector);
}
}
if (json.type == webSocketTypes.NEW_CONNECTION) {
//console.log("Socket onmessage NEW_CONNECTION", json);
} else if (json.type == webSocketTypes.NEW_DISCONNECTION) {
//console.log("Socket onmessage NEW_DISCONNECTION", json);
} else {
var myfunc;
if (json.callback) {
console.log("Socket onmessage json.callback", json.callback);
var code = "if(typeof " + json.callback + " == 'function'){myfunc = " + json.callback + ";}else{myfunc = defaultCallback;}";
//console.log(code);
eval(code);
} else {
console.log("onmessage: callback not found");
console.log("onmessage: callback not found", json);
myfunc = defaultCallback;
}
myfunc(json);
myfunc(json.msg);
}
};
conn.onclose = function (e) {
socketConnectRequested = 0;
@ -59,29 +68,18 @@ function sendSocketMessageToNone(msg, callback) {
sendSocketMessageToUser(msg, callback, -1);
}
function sendSocketMessageToUser(msg, callback, users_id) {
function sendSocketMessageToUser(msg, callback, to_users_id) {
if (conn.readyState === 1) {
conn.send(JSON.stringify({msg: msg, webSocketToken: webSocketToken, callback: callback, users_id, users_id}));
conn.send(JSON.stringify({msg: msg, webSocketToken: webSocketToken, callback: callback, to_users_id: to_users_id}));
} else {
console.log('Socket not ready send message in 1 second');
setTimeout(function () {
sendSocketMessageToUser(msg, callback, to_users_id);
sendSocketMessageToUser(msg, to_users_id, callback);
}, 1000);
}
}
function sendSocketMessageToUser(msg, users_id, callback) {
if (conn.readyState === 1) {
conn.send(JSON.stringify({msg: msg, webSocketToken: webSocketToken, users_id: users_id, callback: callback}));
} else {
console.log('Socket not ready send message in 1 second');
setTimeout(function () {
sendSocketMessageToUser(msg, users_id, callback);
}, 1000);
}
}
function isSocketActive(){
function isSocketActive() {
return typeof conn != 'undefined' && conn.readyState === 1;
}
@ -89,6 +87,30 @@ function defaultCallback(json) {
//console.log('defaultCallback', json);
}
function parseSocketResponse(json) {
console.log("parseSocketResponse", json);
if (json && typeof json.autoUpdateOnHTML !== 'undefined') {
//console.log("parseSocketResponse", json.autoUpdateOnHTML);
for (var prop in json.autoUpdateOnHTML) {
if(json.autoUpdateOnHTML[prop]===false){
continue;
}
$('.'+prop).text(json.autoUpdateOnHTML[prop]);
}
}
if (json && typeof json.autoEvalCode !== 'undefined') {
//console.log("parseSocketResponse", json.autoUpdateOnHTML);
for (var prop in json.autoUpdateOnHTML) {
if(json.autoEvalCode[prop]===false){
continue;
}
console.log("autoEvalCode", json.autoEvalCode[prop]);
eval(json.autoEvalCode[prop]);
}
}
}
$(function () {
socketConnect();
});

View file

@ -3,6 +3,10 @@ require_once dirname(__FILE__) . '/../../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/autoload.php';
header('Content-Type: application/json');
ob_end_flush();
_mysql_close();
session_write_close();
$obj = new stdClass();
$obj->error = true;
$obj->msg = "";

View file

@ -8,13 +8,15 @@ require_once dirname(__FILE__) . '/../../videos/configuration.php';
require_once $global['systemRootPath'] . 'plugin/Socket/Message.php';
require_once $global['systemRootPath'] . 'objects/autoload.php';
if(!isCommandLineInterface()){
die("Command line only");
}
$obj = AVideoPlugin::getDataObject("Socket");
ob_end_flush();
_mysql_close();
session_write_close();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
_error_log("Starting Socket server at port {$obj->port}");
$server = IoServer::factory(
new HttpServer(

View file

@ -0,0 +1,30 @@
<?php
require_once dirname(__FILE__) . '/../../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/autoload.php';
header('Content-Type: application/json');
_mysql_close();
session_write_close();
$obj = new stdClass();
$obj->error = true;
$obj->msg = "";
$obj->pid = "none";
$obj->time = time();
$videosDir = getVideosDir();
$pidFile = "{$videosDir}socketPID.log";
if(file_exists($pidFile)){
$oldObj = json_decode(file_get_contents($pidFile));
if(!empty($oldObj)){
killProcess($oldObj->pid);
}
}
$obj->pid = execAsync("php '{$global['systemRootPath']}plugin/Socket/server.php'");
file_put_contents($pidFile, json_encode($obj));
die(json_encode($obj));

View file

@ -987,8 +987,10 @@ $(document).ready(function () {
} catch (e) {
}
setInterval(function(){setToolTips();},1000);
setInterval(function () {
setToolTips();
}, 1000);
$(".thumbsImage").on("mouseenter", function () {
gifId = $(this).find(".thumbsGIF").attr('id');
@ -1087,7 +1089,7 @@ function validURL(str) {
return !!pattern.test(str);
}
function isURL(url){
function isURL(url) {
return validURL(url);
}
@ -1159,7 +1161,7 @@ function getCroppie(uploadCropObject, callback, width, height) {
}
function setToolTips() {
if(!$('[data-toggle="tooltip"]').not('.alreadyTooltip').length){
if (!$('[data-toggle="tooltip"]').not('.alreadyTooltip').length) {
return false;
}
$('[data-toggle="tooltip"]').not('.alreadyTooltip').tooltip({container: 'body'});
@ -1170,4 +1172,12 @@ function setToolTips() {
}, 2000);
});
$('[data-toggle="tooltip"]').addClass('alreadyTooltip');
}
function avideoSocketIsActive() {
if (typeof isSocketActive == 'function') {
return isSocketActive();
} else {
return false;
}
}

View file

@ -13,6 +13,9 @@
<a href="<?php echo $global['webSiteRootURL']; ?>objects/getAllEmails.csv.php" class="btn btn-primary">
<i class="fas fa-file-csv"></i> <?php echo __("CSV File"); ?>
</a>
<a href="#" class="btn btn-primary">
<i class="fas fa-users"></i> <span class="totalDevicesOnline">0</span>
</a>
</div>
<ul class="nav nav-tabs">