mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 19:42:38 +02:00
Getting ready for the socket
This commit is contained in:
parent
bb45ecff72
commit
d1db39b4d1
27 changed files with 1046 additions and 306 deletions
|
@ -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]);
|
||||
|
@ -4647,8 +4672,9 @@ function forbiddenPage($message, $logMessage = false) {
|
|||
|
||||
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();
|
||||
|
@ -5386,12 +5412,13 @@ 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"){
|
||||
|
||||
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);
|
||||
$obj = Socket::send($msg, $callbackJSFunction, $users_id, $send_to_uri_pattern);
|
||||
if ($obj->error) {
|
||||
_error_log("sendSocketMessage " . $obj->msg, AVideoLog::$ERROR);
|
||||
}
|
||||
|
@ -5413,9 +5440,10 @@ function sendSocketMessageToUsers_id($msg, $users_id, $callbackJSFunction=""){
|
|||
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 = "") {
|
||||
return sendSocketMessage($msg, $callbackJSFunction, -1);
|
||||
}
|
||||
|
@ -5446,3 +5474,18 @@ function killProcess($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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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];
|
||||
|
@ -1168,6 +1168,34 @@ class AVideoPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
$r = "";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -121,7 +202,6 @@ 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";
|
||||
|
|
|
@ -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/");
|
||||
|
|
|
@ -69,7 +69,6 @@ if (!empty($_GET['p'])) {
|
|||
$obj->liveTransmitionHistory_id = $lth->save();
|
||||
_error_log("NGINX ON Publish saved LiveTransmitionHistory");
|
||||
$obj->error = false;
|
||||
|
||||
} else if (empty($_GET['p'])) {
|
||||
_error_log("NGINX ON Publish error, Password is empty");
|
||||
} else {
|
||||
|
@ -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);
|
||||
|
|
54
plugin/Live/on_publish_done.php
Normal file
54
plugin/Live/on_publish_done.php
Normal 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");
|
|
@ -137,6 +137,7 @@ function clearCommandURL($url) {
|
|||
return preg_replace('/[^0-9a-z:.\/_&?=-]/i', "", $url);
|
||||
}
|
||||
|
||||
if(!function_exists('isURL200')){
|
||||
function isURL200($url) {
|
||||
error_log("Restreamer.json.php checking URL {$url}");
|
||||
//open connection
|
||||
|
@ -154,6 +155,7 @@ function isURL200($url) {
|
|||
error_log("Restreamer.json.php URL {$url} return code {$httpcode}");
|
||||
return $httpcode == 200;
|
||||
}
|
||||
}
|
||||
|
||||
function startRestream($m3u8, $restreamsDestinations, $logFile, $tries = 1) {
|
||||
global $ffmpegBinary;
|
||||
|
|
32
plugin/Live/view/footer.php
Normal file
32
plugin/Live/view/footer.php
Normal 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>
|
|
@ -120,12 +120,16 @@ if (empty($obj->doNotShowGoLiveButton) && User::canStream()) {
|
|||
if (href != "#") {
|
||||
$liveLi.find('.liveNow').removeClass("hidden");
|
||||
}
|
||||
|
||||
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");
|
||||
|
@ -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);
|
||||
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,11 +174,8 @@ 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) {
|
||||
function processLiveStats(response) {
|
||||
//console.log('processLiveStats', response);
|
||||
limitLiveOnVideosListCount = 0;
|
||||
if (typeof response !== 'undefined') {
|
||||
$('#availableLiveStream').empty();
|
||||
|
@ -184,12 +189,12 @@ if (empty($obj->doNotShowGoLiveButton) && User::canStream()) {
|
|||
} else {
|
||||
processApplicationLive(response);
|
||||
}
|
||||
if (!response.total) {
|
||||
if (!response.countLiveStream) {
|
||||
availableLiveStreamNotFound();
|
||||
} else {
|
||||
$('#availableLiveStream').removeClass('notfound');
|
||||
}
|
||||
$('.onlineApplications').text(response.total);
|
||||
$('.onlineApplications').text(response.countLiveStream);
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
|
@ -201,10 +206,25 @@ if (!empty($obj->playLiveInFullScreenOnIframe)) {
|
|||
}
|
||||
?>
|
||||
}, 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 () {
|
||||
if (!avideoSocketIsActive()) {
|
||||
availableLiveStreamIsLoading();
|
||||
getStatsMenu(true);
|
||||
}
|
||||
<?php
|
||||
if (AVideoPlugin::isEnabledByName('Socket')) {
|
||||
echo 'processLiveStats(' . json_encode(Live::getStats()) . ');';
|
||||
}
|
||||
?>
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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>
|
|
@ -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
|
||||
}
|
||||
?>
|
|
@ -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');
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -505,6 +505,14 @@ abstract class PluginAbstract {
|
|||
function getDataObjectHelper(){
|
||||
return $this->dataObjectHelper;
|
||||
}
|
||||
|
||||
function onUserSocketConnect($users_id, $data){
|
||||
|
||||
}
|
||||
|
||||
function onUserSocketDisconnect($users_id, $data){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
public function msgToUsers_id($msg, $users_id) {
|
||||
if(empty($users_id)){
|
||||
return false;
|
||||
}
|
||||
$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,27 +116,284 @@ 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 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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
$msg = $this->makeSureIsArray(@$json['msg']);
|
||||
$msg['callback'] = @$json['callback'];
|
||||
$msg['uniqid'] = uniqid();
|
||||
$json['msg'] = $msg;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -128,13 +414,6 @@ class Message implements MessageComponentInterface {
|
|||
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();
|
||||
|
|
|
@ -63,53 +63,65 @@ class Socket extends PluginAbstract {
|
|||
|
||||
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;
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
7
plugin/Socket/crontab.php
Normal file
7
plugin/Socket/crontab.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
require_once dirname(__FILE__) . '/../../videos/configuration.php';
|
||||
|
||||
if(!isCommandLineInterface()){
|
||||
//die("Command line only");
|
||||
}
|
||||
|
|
@ -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>
|
||||
|
|
|
@ -1,10 +1,32 @@
|
|||
<?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;
|
||||
}
|
||||
|
|
|
@ -1,40 +1,49 @@
|
|||
var socketMyResourceId = 0;
|
||||
var socketConnectRequested = 0;
|
||||
var totalDevicesOnline = 0;
|
||||
function socketConnect() {
|
||||
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,24 +68,13 @@ 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);
|
||||
}, 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);
|
||||
sendSocketMessageToUser(msg, to_users_id, callback);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
|
@ -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 = "";
|
||||
|
|
|
@ -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(
|
||||
|
|
30
plugin/Socket/start.json.php
Normal file
30
plugin/Socket/start.json.php
Normal 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));
|
|
@ -988,7 +988,9 @@ $(document).ready(function () {
|
|||
|
||||
}
|
||||
|
||||
setInterval(function(){setToolTips();},1000);
|
||||
setInterval(function () {
|
||||
setToolTips();
|
||||
}, 1000);
|
||||
|
||||
$(".thumbsImage").on("mouseenter", function () {
|
||||
gifId = $(this).find(".thumbsGIF").attr('id');
|
||||
|
@ -1171,3 +1173,11 @@ function setToolTips() {
|
|||
});
|
||||
$('[data-toggle="tooltip"]').addClass('alreadyTooltip');
|
||||
}
|
||||
|
||||
function avideoSocketIsActive() {
|
||||
if (typeof isSocketActive == 'function') {
|
||||
return isSocketActive();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -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">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue