1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Socket new version

This commit is contained in:
DanieL 2022-06-01 11:40:38 -03:00
parent 4aeb911dac
commit 9ec9f3bd5a
8 changed files with 307 additions and 337 deletions

View file

@ -243,7 +243,7 @@ class Live extends PluginAbstract {
continue;
}
//$link = addQueryStringParameter($link, 'live_schedule', intval($value['id']));
$link = $link.'/ls/'.intval($value['id']).'/';
$link = $link . '/ls/' . intval($value['id']) . '/';
$LiveUsersLabelLive = ($liveUsersEnabled ? getLiveUsersLabelLive($value['key'], $value['live_servers_id']) : '');
$title = self::getTitleFromKey($value['key'], $value['title']);
@ -258,7 +258,7 @@ class Live extends PluginAbstract {
$app['Live_schedule_timezone'] = date_default_timezone_get();
$app['scheduled_time_timezone'] = $value['timezone'];
$app['scheduled_time'] = $value['scheduled_time'];
$array[] = $app;
}
//var_dump($rows);exit;
@ -362,20 +362,20 @@ class Live extends PluginAbstract {
$name = User::getNameIdentificationById($users_id);
$comingsoon = false;
if (!empty($startsOnDate)) {
preg_match('/([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})(.*)/', $startsOnDate, $matches);
if(empty($matches) || empty($matches[2])){
if (empty($matches) || empty($matches[2])) {
$datetime = "'$startsOnDate'";
}else{
} else {
$datetime = "convertDateFromTimezoneToLocal('{$matches[1]}', '{$matches[2]}')";
}
$startsOnDateTime = strtotime($startsOnDate);
if ($startsOnDateTime > time()) {
$callback .= ';' . '$(\'.' . $uid . ' .liveNow\').attr(\'class\', \'liveNow label label-primary\');'
. '$(\'.' . $uid . ' .liveNow\').text('.$datetime.');'
. 'startTimerToDate('.$datetime.', \'.' . $uid . ' .liveNow\', false);';
. '$(\'.' . $uid . ' .liveNow\').text(' . $datetime . ');'
. 'startTimerToDate(' . $datetime . ', \'.' . $uid . ' .liveNow\', false);';
$comingsoon = $startsOnDateTime;
}
}
@ -1240,7 +1240,7 @@ Click <a href=\"{link}\">here</a> to join our live.";
_error_log("Live::getStatsObject: You need to install the simplexml_load_file function to be able to see the Live stats", AVideoLog::$ERROR);
return false;
}
if(!isset($global['isStatsAccessible'])){
if (!isset($global['isStatsAccessible'])) {
$global['isStatsAccessible'] = array();
}
$name = "getStats" . DIRECTORY_SEPARATOR . "live_servers_id_{$live_servers_id}" . DIRECTORY_SEPARATOR . "getStatsObject";
@ -1332,11 +1332,11 @@ Click <a href=\"{link}\">here</a> to join our live.";
return $xml;
}
static function isStatsAccessible($live_servers_id){
static function isStatsAccessible($live_servers_id) {
global $global;
return !empty($global['isStatsAccessible']) && !empty($global['isStatsAccessible'][$live_servers_id]);
}
public function get_data($url, $timeout) {
global $global;
if (!IsValidURL($url)) {
@ -1469,7 +1469,7 @@ Click <a href=\"{link}\">here</a> to join our live.";
if (!empty($live_schedule_id)) {
$url = "{$url}/ls/{$live_schedule_id}";
}
if (!empty($live_index)) {
$url .= '/' . urlencode($live_index);
} elseif (!isset($live_index) && !empty($_REQUEST['live_index'])) {
@ -1548,21 +1548,22 @@ Click <a href=\"{link}\">here</a> to join our live.";
}
return $btn;
}
public static function unfinishAllFromStats($force_recreate = false){
public static function unfinishAllFromStats($force_recreate = false) {
$stats = self::getStats($force_recreate);
foreach ($stats as $server) {
foreach ($server as $live) {
if(!empty($live->key)){
$row = LiveTransmitionHistory::getLatest($live->key, @$live->live_servers_id);
if(!empty($row['finished'])){
LiveTransmitionHistory::unfinishFromTransmitionHistoryId($row['id']);
if (is_array($server) || is_object($server)) {
foreach ($server as $live) {
if (!empty($live->key)) {
$row = LiveTransmitionHistory::getLatest($live->key, @$live->live_servers_id);
if (!empty($row['finished'])) {
LiveTransmitionHistory::unfinishFromTransmitionHistoryId($row['id']);
}
}
}
}
}
}
public static function getStats($force_recreate = false) {
@ -3306,12 +3307,12 @@ Click <a href=\"{link}\">here</a> to join our live.";
return false;
}
public static function getInfo($key, $live_servers_id = null, $live_index = '', $playlists_id_live='') {
public static function getInfo($key, $live_servers_id = null, $live_index = '', $playlists_id_live = '') {
$lso = new LiveStreamObject($key, $live_servers_id, $live_index, $playlists_id_live);
$keyWithIndex=$lso->getKeyWithIndex();
$key=$lso->getKey();
$keyWithIndex = $lso->getKeyWithIndex();
$key = $lso->getKey();
$array = array(
'key' => $key,
'keyWithIndex' => $keyWithIndex,
@ -3340,16 +3341,16 @@ Click <a href=\"{link}\">here</a> to join our live.";
$array['transmission'] = $lt;
$array['live_schedule_id'] = $lt['live_schedule_id'];
$array['users_id'] = $lt['users_id'];
$otherLivesSameUser = LiveTransmitionHistory::getActiveLiveFromUser($array['users_id'], '', '', 100);
$array['otherLivesSameUser'] = array();
foreach ($otherLivesSameUser as $value) {
if($value['key']!==$keyWithIndex){
if ($value['key'] !== $keyWithIndex) {
$array['otherLivesSameUser'][] = $value;
}
}
$lth = LiveTransmitionHistory::getLatest($keyWithIndex, $live_servers_id);
if (empty($lth)) {
return $array;
@ -3363,13 +3364,13 @@ Click <a href=\"{link}\">here</a> to join our live.";
if (!empty($lth['finished'])) {
$isKeyLiveInStats = self::isKeyLiveInStats($key, $live_servers_id, $live_index);
if(empty($isKeyLiveInStats)){
if (empty($isKeyLiveInStats)) {
$array['isLive'] = false;
$array['isFinished'] = true;
$array['finishedDateTime'] = $lth['finished'];
$array['finishedSecondsAgo'] = secondsIntervalFromNow($lth['finished'], true);
$array['finishedHumanAgo'] = __('Finished') . ' ' . humanTimingAgo($lth['finished']);
}else{
} else {
LiveTransmitionHistory::unfinishFromTransmitionHistoryId($lth['id']);
}
}
@ -3377,19 +3378,19 @@ Click <a href=\"{link}\">here</a> to join our live.";
$array['displayTime'] = '';
if ($array['isFinished']) {
$array['displayTime'] = $array['finishedHumanAgo'];
if(!empty($lt['scheduled_time'])){
if (!empty($lt['scheduled_time'])) {
$time = getTimeInTimezone($lt['scheduled_time'], $lt['timezone']);
$displayTime = strtotime($array['finishedDateTime']);
//var_dump($time, $displayTime, $lt['scheduled_time'], $lt['timezone'], $array['finishedDateTime']);exit;
if($time > $displayTime){
$array['displayTime'] = __('Will start in') . ' ' . humanTiming($time). ", {$lt['scheduled_time']}, {$lt['timezone']}";
if ($time > $displayTime) {
$array['displayTime'] = __('Will start in') . ' ' . humanTiming($time) . ", {$lt['scheduled_time']}, {$lt['timezone']}";
}
}
} else if ($array['isStarded']) {
$array['displayTime'] = $array['startedHumanAgo'];
}
return $array;
}
@ -3496,9 +3497,9 @@ Click <a href=\"{link}\">here</a> to join our live.";
//var_dump($parts);
$selectedEarlierOptions[] = intval($parts[3]);
}
$ls = new Live_schedule($_REQUEST['live_schedule_id']);
$ls = new Live_schedule($live_schedule_id);
$users_id = Live_schedule::getUsers_idOrCompany($live_schedule_id);
$title = $ls->getTitle();
@ -3506,11 +3507,10 @@ Click <a href=\"{link}\">here</a> to join our live.";
$date_end = '';
$joinURL = Live::getLinkToLiveFromUsers_id($users_id);
$joinURL = addQueryStringParameter($joinURL, 'live_schedule', $live_schedule_id);
// , $date_start, $selectedEarlierOptions = array(), $date_end = '', $joinURL='', $description=''
return Scheduler::getReminderOptions($destinationURL, $title, $date_start, $selectedEarlierOptions, $date_end, $joinURL);
// , $date_start, $selectedEarlierOptions = array(), $date_end = '', $joinURL='', $description=''
return Scheduler::getReminderOptions($destinationURL, $title, $date_start, $selectedEarlierOptions, $date_end, $joinURL);
}
public function getWatchActionButton($videos_id): string {

View file

@ -585,7 +585,7 @@ class LiveTransmitionHistory extends ObjectYPT {
$formats .= "i";
$values[] = $users_id;
}
if (strtolower($live_servers_id) == 'null') {
if (!isset($live_servers_id) || strtolower($live_servers_id) == 'null') {
$sql .= ' AND `live_servers_id` IS NULL ';
}else if (!empty($live_servers_id)) {
$sql .= ' AND `live_servers_id` = ? ';

View file

@ -1,52 +1,56 @@
<?php
require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
class LoginTwitter extends PluginAbstract {
public function getTags() {
return array(
PluginTags::$FREE,
PluginTags::$LOGIN,
);
}
public function getDescription() {
global $global;
$obj = $this->getLogin();
$name = $obj->type;
$str = "Login with {$name} OAuth Integration";
$str .= "<br><a href='{$obj->linkToDevelopersPage}'>Get {$name} ID and Key</a>"
. "<br>Valid OAuth redirect URIs: <strong>{$global['webSiteRootURL']}objects/login.json.php</strong>"
. "<br>For mobile a Valid OAuth redirect URIs: <strong>{$global['webSiteRootURL']}plugin/MobileManager/oauth2.php</strong>";
return $str;
}
public function getName() {
return "LoginTwitter";
}
public function getUUID() {
return "bc50f9c1-85d8-4898-8092-82ee69041b3f";
}
public function getPluginVersion() {
return "1.0";
}
public function getEmptyDataObject() {
global $global;
$obj = new stdClass();
$obj->id = "";
$obj->key = "";
return $obj;
}
public function getLogin() {
$obj = new stdClass();
$obj->class = "btn btn-info btn-block";
$obj->icon = "fab fa-twitter";
$obj->type = "Twitter";
$obj->linkToDevelopersPage = "https://apps.twitter.com/";
return $obj;
}
}
<?php
require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
class LoginTwitter extends PluginAbstract {
public function getTags() {
return array(
PluginTags::$FREE,
PluginTags::$LOGIN,
);
}
public function getDescription() {
global $global;
$obj = $this->getLogin();
$name = $obj->type;
$str = "Login with {$name} OAuth Integration";
$str .= "<br><a href='{$obj->linkToDevelopersPage}'>Get {$name} ID and Key</a>"
. "<br>Valid OAuth redirect URIs: <strong>{$global['webSiteRootURL']}objects/login.json.php</strong>"
. "<br>For mobile a Valid OAuth redirect URIs: <strong>{$global['webSiteRootURL']}plugin/MobileManager/oauth2.php</strong>";
return $str;
}
public function getName() {
return "LoginTwitter";
}
public function getUUID() {
return "bc50f9c1-85d8-4898-8092-82ee69041b3f";
}
public function getPluginVersion() {
return "1.0";
}
public function getEmptyDataObject() {
global $global;
$obj = new stdClass();
$obj->id = "";
self::addDataObjectHelper('id', 'Consumer API Key');
$obj->key = "";
self::addDataObjectHelper('key', 'Consumer API Key Secret');
return $obj;
}
public function getLogin() {
$obj = new stdClass();
$obj->class = "btn btn-info btn-block";
$obj->icon = "fab fa-twitter";
$obj->type = "Twitter";
$obj->linkToDevelopersPage = "https://apps.twitter.com/";
return $obj;
}
}

View file

@ -12,6 +12,7 @@ require_once $global['systemRootPath'] . 'plugin/YPTSocket/functions.php';
class Message implements MessageComponentInterface {
protected $clients;
protected $totalUsersOnLives;
protected $clientsWatchinLive;
protected $clientsWatchVideosId;
protected $clientsUsersId;
@ -26,7 +27,6 @@ class Message implements MessageComponentInterface {
$this->clientsChatRoom = [];
//$this->loop->ad
_log_message("Construct");
}
public function onOpen(ConnectionInterface $conn) {
@ -113,6 +113,7 @@ class Message implements MessageComponentInterface {
unset($resourceId);
}
*/
//$this->msgToResourceId('open connection', $conn->resourceId, \SocketMessageType::OPEN_CONNECTION);
if ($client['browser'] == \SocketMessageType::TESTING) {
_log_message("Test detected and received from ($conn->resourceId) " . PHP_EOL . "\e[1;32;40m*** SUCCESS TEST CONNECION {$json->test_msg} ***\e[0m");
$this->msgToResourceId($json, $conn->resourceId, \SocketMessageType::TESTING);
@ -130,7 +131,7 @@ class Message implements MessageComponentInterface {
}
if (!empty($json->live_key)) {
//_log_message("msgToAllSameLive ");
if (\AVideoPlugin::isEnabledByName('LiveUsers') && method_exists('LiveUsers', 'getTotalUsers')) {
if ($this->isLiveUsersEnabled()) {
$live_key = object_to_array($json->live_key);
if (!empty($live_key['key'])) {
\_mysql_connect(true);
@ -481,12 +482,55 @@ class Message implements MessageComponentInterface {
}
}
}
$return['LivesTotals'] = $this->getLivesTotal();
if (!$isAdmin) {
$SocketGetTotals = $return;
}
return $return;
}
function getLivesTotal() {
if (!isset($this->totalUsersOnLives) || $this->totalUsersOnLives['updated'] < strtotime('- 1 minute')) {
$stats = getStatsNotifications();
$statsList = array();
foreach ($stats as $server) {
if (is_array($server) || is_object($server)) {
foreach ($server as $lt) {
if (!empty($lt['key'])) {
if ($this->isLiveUsersEnabled()) {
$total_viewers = \LiveUsers::getTotalUsers($lt['key'], $lt['live_servers_id']);
}
$statsList[$lt['key']] = array('total_viewers' => $total_viewers);
}
}
}
}
$this->totalUsersOnLives = array('updated' => time(), 'statsList' => $statsList);
}
foreach ($this->totalUsersOnLives['statsList'] as $key => $lt) {
if(!empty($lt['key']) && $lt['key'] !== 'key' && isset($this->clientsWatchinLive[$lt['key']]) && is_array($this->clientsWatchinLive[$lt['key']])){
$this->totalUsersOnLives['statsList'][$key]['watching_now'] = count($this->clientsWatchinLive[$lt['key']]);
}else{
$this->totalUsersOnLives['statsList'][$key]['watching_now'] = 0;
}
}
//var_dump($this->totalUsersOnLives);
return $this->totalUsersOnLives;
}
private function isLiveUsersEnabled() {
global $_isLiveUsersEnabled;
if (!isset($_isLiveUsersEnabled)) {
$_isLiveUsersEnabled = \AVideoPlugin::isEnabledByName('LiveUsers') && method_exists('LiveUsers', 'getTotalUsers');
}
return $_isLiveUsersEnabled;
}
public function msgToDevice_id($msg, $yptDeviceId) {
if (empty($yptDeviceId)) {
return false;
@ -504,7 +548,10 @@ class Message implements MessageComponentInterface {
public function msgToAll(ConnectionInterface $from, $msg, $type = "", $includeMe = false) {
_log_message("msgToAll FROM ({$from->resourceId}) {$type} Total Clients: " . count($this->clients));
foreach ($this->clients as $key => $client) {
if (!empty($includeMe) || $from !== $client['conn']) {
if (
!empty($includeMe)
//|| $from !== $client['conn']
) {
//_log_message("msgToAll FROM ({$from->resourceId}) TO {$key} {$type}");
$this->msgToResourceId($msg, $key, $type);
}

View file

@ -41,7 +41,7 @@ class YPTSocket extends PluginAbstract {
}
public static function getServerVersion() {
return "3.1";
return "3.2";
}
public function updateScript() {

View file

@ -1,154 +1,155 @@
<?php
function getEncryptedInfo($timeOut = 0, $send_to_uri_pattern = "") {
if (empty($timeOut)) {
$timeOut = 43200; // valid for 12 hours
}
$msgObj = new stdClass();
$msgObj->from_users_id = User::getId();
$msgObj->isAdmin = User::isAdmin();
$msgObj->user_name = User::getNameIdentification();
$msgObj->browser = get_browser_name();
$msgObj->yptDeviceId = getDeviceID(false);
$msgObj->token = getToken($timeOut);
$msgObj->time = time();
$msgObj->ip = getRealIpAddr();
$msgObj->send_to_uri_pattern = $send_to_uri_pattern;
//var_dump($msgObj);exit;
if (!empty($_REQUEST['webSocketSelfURI'])) {
$msgObj->selfURI = $_REQUEST['webSocketSelfURI'];
} else {
$msgObj->selfURI = getSelfURI();
}
if (empty($msgObj->videos_id)) {
if (!empty($_REQUEST['webSocketVideos_id'])) {
$msgObj->videos_id = $_REQUEST['webSocketVideos_id'];
} else {
$msgObj->videos_id = getVideos_id();
}
}
if (empty($msgObj->live_key)) {
if (!empty($_REQUEST['webSocketLiveKey'])) {
$msgObj->live_key = _json_decode($_REQUEST['webSocketLiveKey']);
} else {
$msgObj->live_key = isLive();
}
}
if (AVideoPlugin::isEnabledByName('User_location')) {
$msgObj->location = User_Location::getThisUserLocation();
} else {
$msgObj->location = false;
}
return encryptString(json_encode($msgObj));
}
function getDecryptedInfo($string) {
$decriptedString = decryptString($string);
$json = _json_decode($decriptedString);
if (!empty($json) && !empty($json->token)) {
if (verifyTokenSocket($json->token)) {
return $json;
} else {
_error_log("socket:getDecryptedInfo: token is invalid ");
}
} else {
_error_log("socket:getDecryptedInfo: json->token is empty ({$decriptedString})");
}
return false;
}
function verifyTokenSocket($token) {
global $global;
$obj = _json_decode(decryptString($token));
if (empty($obj)) {
_error_log("verifyToken invalid token");
return false;
}
if ($obj->salt !== $global['salt']) {
_error_log("verifyToken salt fail");
return false;
}
$time = time();
if (!($time >= $obj->time && $time <= $obj->timeout)) {
_error_log("verifyToken token timout time = $time; obj->time = $obj->time; obj->timeout = $obj->timeout");
//return false;
}
return true;
}
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";
const TESTING = "TESTING";
}
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;
}
function killProcessOnPort() {
$obj = \AVideoPlugin::getDataObject("YPTSocket");
$port = intval($obj->port);
if (!empty($port)) {
echo 'Searching for port: ' . $port . PHP_EOL;
//$command = 'netstat -ano | findstr ' . $port;
//exec($command, $output, $retval);
$pid = getPIDUsingPort($port);
if (!empty($pid)) {
echo 'Server is already runing on port '.$port.' Killing, PID ' . $pid . PHP_EOL;
killProcess($pid);
} else {
echo 'No Need to kill, port NOT found' . PHP_EOL;
}
}
}
function restartServer($kill=true) {
global $global;
if($kill){
killProcessOnPort();
sleep(1);
}
$cmd = "php {$global['systemRootPath']}plugin/YPTSocket/server.php";
echo 'Starting server with command ' . $cmd . PHP_EOL;
exec($cmd, $output, $retval);
echo implode(PHP_EOL,$output);
echo PHP_EOL;
return $retval;
}
function restartServerIfIsDead() {
global $global;
$obj = \AVideoPlugin::getDataObject("YPTSocket");
$port = intval($obj->port);
$pid = getPIDUsingPort($port);
if (!empty($pid)) {
echo 'Server is already runing on port '.$port.' PID ' . $pid . PHP_EOL;
echo 'Run "php '.$global['systemRootPath'].'plugin/YPTSocket/serverRestart.php force" if you want to kill the current server and restart it'.PHP_EOL;
return false;
}
echo 'Server was dead, restart it'.PHP_EOL;
return restartServer(false);
}
<?php
function getEncryptedInfo($timeOut = 0, $send_to_uri_pattern = "") {
if (empty($timeOut)) {
$timeOut = 43200; // valid for 12 hours
}
$msgObj = new stdClass();
$msgObj->from_users_id = User::getId();
$msgObj->isAdmin = User::isAdmin();
$msgObj->user_name = User::getNameIdentification();
$msgObj->browser = get_browser_name();
$msgObj->yptDeviceId = getDeviceID(false);
$msgObj->token = getToken($timeOut);
$msgObj->time = time();
$msgObj->ip = getRealIpAddr();
$msgObj->send_to_uri_pattern = $send_to_uri_pattern;
//var_dump($msgObj);exit;
if (!empty($_REQUEST['webSocketSelfURI'])) {
$msgObj->selfURI = $_REQUEST['webSocketSelfURI'];
} else {
$msgObj->selfURI = getSelfURI();
}
if (empty($msgObj->videos_id)) {
if (!empty($_REQUEST['webSocketVideos_id'])) {
$msgObj->videos_id = $_REQUEST['webSocketVideos_id'];
} else {
$msgObj->videos_id = getVideos_id();
}
}
if (empty($msgObj->live_key)) {
if (!empty($_REQUEST['webSocketLiveKey'])) {
$msgObj->live_key = _json_decode($_REQUEST['webSocketLiveKey']);
} else {
$msgObj->live_key = isLive();
}
}
if (AVideoPlugin::isEnabledByName('User_location')) {
$msgObj->location = User_Location::getThisUserLocation();
} else {
$msgObj->location = false;
}
return encryptString(json_encode($msgObj));
}
function getDecryptedInfo($string) {
$decriptedString = decryptString($string);
$json = _json_decode($decriptedString);
if (!empty($json) && !empty($json->token)) {
if (verifyTokenSocket($json->token)) {
return $json;
} else {
_error_log("socket:getDecryptedInfo: token is invalid ");
}
} else {
_error_log("socket:getDecryptedInfo: json->token is empty ({$decriptedString})");
}
return false;
}
function verifyTokenSocket($token) {
global $global;
$obj = _json_decode(decryptString($token));
if (empty($obj)) {
_error_log("verifyToken invalid token");
return false;
}
if ($obj->salt !== $global['salt']) {
_error_log("verifyToken salt fail");
return false;
}
$time = time();
if (!($time >= $obj->time && $time <= $obj->timeout)) {
_error_log("verifyToken token timout time = $time; obj->time = $obj->time; obj->timeout = $obj->timeout");
//return false;
}
return true;
}
class SocketMessageType {
const OPEN_CONNECTION = "OPEN_CONNECTION";
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";
const TESTING = "TESTING";
}
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;
}
function killProcessOnPort() {
$obj = \AVideoPlugin::getDataObject("YPTSocket");
$port = intval($obj->port);
if (!empty($port)) {
echo 'Searching for port: ' . $port . PHP_EOL;
//$command = 'netstat -ano | findstr ' . $port;
//exec($command, $output, $retval);
$pid = getPIDUsingPort($port);
if (!empty($pid)) {
echo 'Server is already runing on port '.$port.' Killing, PID ' . $pid . PHP_EOL;
killProcess($pid);
} else {
echo 'No Need to kill, port NOT found' . PHP_EOL;
}
}
}
function restartServer($kill=true) {
global $global;
if($kill){
killProcessOnPort();
sleep(1);
}
$cmd = "php {$global['systemRootPath']}plugin/YPTSocket/server.php";
echo 'Starting server with command ' . $cmd . PHP_EOL;
exec($cmd, $output, $retval);
echo implode(PHP_EOL,$output);
echo PHP_EOL;
return $retval;
}
function restartServerIfIsDead() {
global $global;
$obj = \AVideoPlugin::getDataObject("YPTSocket");
$port = intval($obj->port);
$pid = getPIDUsingPort($port);
if (!empty($pid)) {
echo 'Server is already runing on port '.$port.' PID ' . $pid . PHP_EOL;
echo 'Run "php '.$global['systemRootPath'].'plugin/YPTSocket/serverRestart.php force" if you want to kill the current server and restart it'.PHP_EOL;
return false;
}
echo 'Server was dead, restart it'.PHP_EOL;
return restartServer(false);
}

View file

@ -23,6 +23,7 @@ function socketConnect() {
};
conn.onmessage = function (e) {
var json = JSON.parse(e.data);
//console.log("Socket onmessage conn.onmessage", json);
socketResourceId = json.resourceId;
yptSocketResponse = json;
parseSocketResponse();

View file

@ -1,83 +0,0 @@
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
namespace Google\Service;
use Google\Client;
/**
* Service definition for PlayIntegrity (v1).
*
* <p>
* Play Integrity</p>
*
* <p>
* For more information about this service, see the API
* <a href="https://developer.android.com/google/play/integrity" target="_blank">Documentation</a>
* </p>
*
* @author Google, Inc.
*/
class PlayIntegrity extends \Google\Service
{
/** Private Service: https://www.googleapis.com/auth/playintegrity. */
const PLAYINTEGRITY =
"https://www.googleapis.com/auth/playintegrity";
public $v1;
/**
* Constructs the internal representation of the PlayIntegrity service.
*
* @param Client|array $clientOrConfig The client used to deliver requests, or a
* config array to pass to a new Client instance.
* @param string $rootUrl The root URL used for requests to the service.
*/
public function __construct($clientOrConfig = [], $rootUrl = null)
{
parent::__construct($clientOrConfig);
$this->rootUrl = $rootUrl ?: 'https://playintegrity.googleapis.com/';
$this->servicePath = '';
$this->batchPath = 'batch';
$this->version = 'v1';
$this->serviceName = 'playintegrity';
$this->v1 = new PlayIntegrity\Resource\V1(
$this,
$this->serviceName,
'v1',
[
'methods' => [
'decodeIntegrityToken' => [
'path' => 'v1/{+packageName}:decodeIntegrityToken',
'httpMethod' => 'POST',
'parameters' => [
'packageName' => [
'location' => 'path',
'type' => 'string',
'required' => true,
],
],
],
]
]
);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(PlayIntegrity::class, 'Google_Service_PlayIntegrity');