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

Socket updates

This commit is contained in:
Daniel 2022-01-20 13:45:57 -03:00
parent c4f7d93846
commit f9526fa6b5
3 changed files with 29 additions and 13 deletions

View file

@ -11,10 +11,12 @@ require_once $global['systemRootPath'] . 'plugin/YPTSocket/functions.php';
class Message implements MessageComponentInterface {
protected $clients;
protected $clientsWatchinLive;
public function __construct() {
//$this->clients = new \SplObjectStorage;
$this->clients = [];
$this->clientsWatchinLive = [];
_log_message("Construct");
}
@ -59,6 +61,16 @@ class Message implements MessageComponentInterface {
$client['ip'] = $json->ip;
$client['location'] = $json->location;
if(!empty($client['live_key']['key'])){
$this->clientsWatchinLive[$client['live_key']['key']][$client['resourceId']] = $client['users_id'];
}else
if(!empty($client['live_key']['liveLink'])){
$this->clientsWatchinLive[$client['live_key']['liveLink']][$client['resourceId']] = $client['users_id'];
}else
if(!empty($client['videos_id'])){
$this->clientsWatchinLive[$client['videos_id']][$client['resourceId']] = $client['users_id'];
}
_log_message("New connection ($conn->resourceId) {$json->yptDeviceId} {$client['selfURI']} {$client['browser']}");
$this->clients[$conn->resourceId] = $client;
@ -104,16 +116,10 @@ class Message implements MessageComponentInterface {
$l = new \LiveTransmitionHistory($lt['id']);
$total_viewers = \LiveUsers::getTotalUsers($lt['key'], $lt['live_servers_id']);
$max_viewers_sametime = $l->getMax_viewers_sametime();
$viewers_now = 0;
foreach ($this->clients as $key => $client) {
if (empty($client['live_key']) || (empty($client['live_key']['key']) && empty($client['live_key']['liveLink']))) {
continue;
}
if ($client['live_key']['key'] == $live_key['key'] && $client['live_key']['live_servers_id'] == $live_key['live_servers_id']) {
$viewers_now++;
} else if ($client['live_key']['liveLink'] == $live_key['liveLink']) {
$viewers_now++;
}
if(!empty($live_key['key'])){
$viewers_now = count($this->clientsWatchinLive[$live_key['key']]);
}else if(!empty($live_key['liveLink'])){
$viewers_now = count($this->clientsWatchinLive[$live_key['liveLink']]);
}
if ($viewers_now > $max_viewers_sametime) {
$l->setMax_viewers_sametime($viewers_now);
@ -145,6 +151,16 @@ class Message implements MessageComponentInterface {
return false;
}
$client = $this->clients[$conn->resourceId];
if(!empty($client['live_key'])){
if(!empty($client['live_key']['key'])){
unset($this->clientsWatchinLive[$client['live_key']['key']][$conn->resourceId]);
}
if(!empty($client['live_key']['liveLink'])){
unset($this->clientsWatchinLive[$client['live_key']['liveLink']][$conn->resourceId]);
}
}
unset($this->clients[$conn->resourceId]);
$users_id = $client['users_id'];
$videos_id = $client['videos_id'];

View file

@ -40,7 +40,7 @@ class YPTSocket extends PluginAbstract {
}
public static function getServerVersion() {
return "2.7";
return "2.8";
}
public function updateScript() {

View file

@ -155,7 +155,7 @@ function parseSocketResponse() {
}
//console.log("parseSocketResponse", json);
if (json.isAdmin && webSocketServerVersion > json.webSocketServerVersion) {
if (typeof avideoToastWarning == 'funciton') {
if (typeof avideoToastWarning == 'function') {
avideoToastWarning("Please restart your socket server. You are running (v" + json.webSocketServerVersion + ") and your client is expecting (v" + webSocketServerVersion + ")");
}
}