mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Socket update
This commit is contained in:
parent
2ac02dab17
commit
b39e5f4da6
5 changed files with 35 additions and 10 deletions
|
@ -59,7 +59,7 @@ class Message implements MessageComponentInterface {
|
||||||
$live_key['liveLink'] = '';
|
$live_key['liveLink'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//_error_log(json_encode(array($json, $wsocketGetVars)));
|
||||||
//var_dump($live_key);
|
//var_dump($live_key);
|
||||||
$client = array();
|
$client = array();
|
||||||
$client['resourceId'] = intval($conn->resourceId);
|
$client['resourceId'] = intval($conn->resourceId);
|
||||||
|
@ -141,6 +141,10 @@ class Message implements MessageComponentInterface {
|
||||||
}
|
}
|
||||||
$end = number_format(microtime(true) - $start, 4);
|
$end = number_format(microtime(true) - $start, 4);
|
||||||
_log_message("Connection opened in {$end} seconds");
|
_log_message("Connection opened in {$end} seconds");
|
||||||
|
if(!empty($client['isCommandLine'])){
|
||||||
|
_error_log('isCommandLine close it');
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onClose(ConnectionInterface $conn) {
|
public function onClose(ConnectionInterface $conn) {
|
||||||
|
@ -403,8 +407,8 @@ class Message implements MessageComponentInterface {
|
||||||
$this->msgToResourceId($msg, $row['resourceId'], $type);
|
$this->msgToResourceId($msg, $row['resourceId'], $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $exc) {
|
} catch (\Throwable $th) {
|
||||||
echo $exc->getTraceAsString();
|
echo $th->getTraceAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
_log_message("msgToUsers_id: sent to ($count) clients users_id=" . json_encode($users_id));
|
_log_message("msgToUsers_id: sent to ($count) clients users_id=" . json_encode($users_id));
|
||||||
|
@ -457,6 +461,9 @@ class Message implements MessageComponentInterface {
|
||||||
$totals = $this->getTotals();
|
$totals = $this->getTotals();
|
||||||
|
|
||||||
foreach ($rows as $key => $client) {
|
foreach ($rows as $key => $client) {
|
||||||
|
if($client['isCommandLine']){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$this->msgToResourceId($msg, $client['resourceId'], $type, $totals);
|
$this->msgToResourceId($msg, $client['resourceId'], $type, $totals);
|
||||||
}
|
}
|
||||||
$end = number_format(microtime(true) - $start, 4);
|
$end = number_format(microtime(true) - $start, 4);
|
||||||
|
@ -473,6 +480,9 @@ class Message implements MessageComponentInterface {
|
||||||
_log_message("msgToAllSameVideo: {$videos_id}");
|
_log_message("msgToAllSameVideo: {$videos_id}");
|
||||||
$totals = $this->getTotals();
|
$totals = $this->getTotals();
|
||||||
foreach (dbGetAllResourcesIdFromVideosId($videos_id) as $client) {
|
foreach (dbGetAllResourcesIdFromVideosId($videos_id) as $client) {
|
||||||
|
if($client['isCommandLine']){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$this->msgToResourceId($msg, $client['resourceId'], \SocketMessageType::ON_VIDEO_MSG, $totals);
|
$this->msgToResourceId($msg, $client['resourceId'], \SocketMessageType::ON_VIDEO_MSG, $totals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -490,6 +500,9 @@ class Message implements MessageComponentInterface {
|
||||||
$totals = $this->getTotals();
|
$totals = $this->getTotals();
|
||||||
|
|
||||||
foreach ($rows as $value) {
|
foreach ($rows as $value) {
|
||||||
|
if($value['isCommandLine']){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$this->msgToResourceId($msg, $value['resourceId'], \SocketMessageType::ON_LIVE_MSG, $totals);
|
$this->msgToResourceId($msg, $value['resourceId'], \SocketMessageType::ON_LIVE_MSG, $totals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class YPTSocket extends PluginAbstract {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getServerVersion() {
|
public static function getServerVersion() {
|
||||||
return "4.3";
|
return "4.4";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateScript() {
|
public function updateScript() {
|
||||||
|
@ -151,6 +151,7 @@ class YPTSocket extends PluginAbstract {
|
||||||
|
|
||||||
$SocketSendObj = new stdClass();
|
$SocketSendObj = new stdClass();
|
||||||
$SocketSendObj->msg = $msg;
|
$SocketSendObj->msg = $msg;
|
||||||
|
$SocketSendObj->isCommandLine = isCommandLineInterface();
|
||||||
$SocketSendObj->json = _json_decode($msg);
|
$SocketSendObj->json = _json_decode($msg);
|
||||||
|
|
||||||
$SocketSendObj->webSocketToken = getEncryptedInfo(0, $send_to_uri_pattern);
|
$SocketSendObj->webSocketToken = getEncryptedInfo(0, $send_to_uri_pattern);
|
||||||
|
@ -169,18 +170,20 @@ class YPTSocket extends PluginAbstract {
|
||||||
\Ratchet\Client\connect($SocketURL)->then(function ($conn) {
|
\Ratchet\Client\connect($SocketURL)->then(function ($conn) {
|
||||||
global $SocketSendObj, $SocketSendUsers_id, $SocketSendResponseObj;
|
global $SocketSendObj, $SocketSendUsers_id, $SocketSendResponseObj;
|
||||||
$conn->on('message', function ($msg) use ($conn, $SocketSendResponseObj) {
|
$conn->on('message', function ($msg) use ($conn, $SocketSendResponseObj) {
|
||||||
//echo "Received: {$msg}\n";
|
echo "Received: {$msg}".PHP_EOL;
|
||||||
//$conn->close();
|
|
||||||
$SocketSendResponseObj->error = false;
|
$SocketSendResponseObj->error = false;
|
||||||
$SocketSendResponseObj->msg = $msg;
|
$SocketSendResponseObj->msg = $msg;
|
||||||
|
//$conn->close();
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach ($SocketSendUsers_id as $users_id) {
|
foreach ($SocketSendUsers_id as $users_id) {
|
||||||
$SocketSendObj->to_users_id = $users_id;
|
$SocketSendObj->to_users_id = $users_id;
|
||||||
$conn->send(json_encode($SocketSendObj));
|
$conn->send(json_encode($SocketSendObj));
|
||||||
|
echo "send: {$users_id}".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn->close();
|
$conn->close();
|
||||||
|
echo "close".PHP_EOL;
|
||||||
|
|
||||||
//$SocketSendResponseObj->error = false;
|
//$SocketSendResponseObj->error = false;
|
||||||
}, function ($e) {
|
}, function ($e) {
|
||||||
|
|
|
@ -260,7 +260,7 @@ function dbGetTotalUniqueDevices() {
|
||||||
function dbGetTotalConnections() {
|
function dbGetTotalConnections() {
|
||||||
global $db;
|
global $db;
|
||||||
$sql = "SELECT count(resourceId) as total "
|
$sql = "SELECT count(resourceId) as total "
|
||||||
. "FROM `connections` ";
|
. "FROM `connections` WHERE (isCommandLine = 0 OR isCommandLine IS NULL)";
|
||||||
$sth = $db->prepare($sql);
|
$sth = $db->prepare($sql);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
$result = $sth->fetch();
|
$result = $sth->fetch();
|
||||||
|
|
|
@ -246,6 +246,7 @@ if (!empty($obj->debugAllUsersSocket) || (User::isAdmin() && !empty($obj->debugS
|
||||||
var webSocketVideos_id = '<?php echo getVideos_id(); ?>';
|
var webSocketVideos_id = '<?php echo getVideos_id(); ?>';
|
||||||
var webSocketLiveKey = '<?php echo json_encode(isLive()); ?>';
|
var webSocketLiveKey = '<?php echo json_encode(isLive()); ?>';
|
||||||
var webSocketServerVersion = '<?php echo YPTSocket::getServerVersion(); ?>';
|
var webSocketServerVersion = '<?php echo YPTSocket::getServerVersion(); ?>';
|
||||||
|
var schedulerIsActive = <?php echo class_exists('Scheduler') && Scheduler::isActive()?1:0; ?>;
|
||||||
var webSocketToken = '';
|
var webSocketToken = '';
|
||||||
var webSocketURL = '';
|
var webSocketURL = '';
|
||||||
var webSocketTypes = <?php echo json_encode($refl->getConstants()); ?>;
|
var webSocketTypes = <?php echo json_encode($refl->getConstants()); ?>;
|
||||||
|
@ -253,7 +254,7 @@ if (!empty($obj->debugAllUsersSocket) || (User::isAdmin() && !empty($obj->debugS
|
||||||
|
|
||||||
function onUserSocketConnect(response) {
|
function onUserSocketConnect(response) {
|
||||||
try {
|
try {
|
||||||
<?php echo AVideoPlugin::onUserSocketConnect(); ?>
|
<?php echo AVideoPlugin::onUserSocketConnect(); ?>
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('onUserSocketConnect:error', e.message);
|
console.log('onUserSocketConnect:error', e.message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,7 @@ async function AutoUpdateOnHTMLTimer() {
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var canShowSocketToast = true;
|
||||||
function parseSocketResponse() {
|
function parseSocketResponse() {
|
||||||
json = yptSocketResponse;
|
json = yptSocketResponse;
|
||||||
yptSocketResponse = false;
|
yptSocketResponse = false;
|
||||||
|
@ -244,8 +244,16 @@ function parseSocketResponse() {
|
||||||
console.log("parseSocketResponse", json);
|
console.log("parseSocketResponse", json);
|
||||||
//console.trace();
|
//console.trace();
|
||||||
if (json.isAdmin && webSocketServerVersion > json.webSocketServerVersion) {
|
if (json.isAdmin && webSocketServerVersion > json.webSocketServerVersion) {
|
||||||
if (typeof avideoToastWarning == 'function') {
|
if (canShowSocketToast && typeof avideoToastWarning == 'function') {
|
||||||
avideoToastWarning("Please restart your socket server. You are running (v" + json.webSocketServerVersion + ") and your client is expecting (v" + webSocketServerVersion + ")");
|
avideoToastWarning("Please restart your socket server. You are running (v" + json.webSocketServerVersion + ") and your client is expecting (v" + webSocketServerVersion + ")");
|
||||||
|
|
||||||
|
// Set the flag to false
|
||||||
|
canShowSocketToast = false;
|
||||||
|
|
||||||
|
// Reset the flag after 5 minutes
|
||||||
|
setTimeout(function() {
|
||||||
|
canShowSocketToast = true;
|
||||||
|
}, 300000); // 300,000 milliseconds = 5 minutes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (json && typeof json.users_id_online !== 'undefined') {
|
if (json && typeof json.users_id_online !== 'undefined') {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue