From f9526fa6b51fee013ef5eb2b8a6c86f4402b2efa Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 20 Jan 2022 13:45:57 -0300 Subject: [PATCH] Socket updates --- plugin/YPTSocket/Message.php | 38 ++++++++++++++++++++++++---------- plugin/YPTSocket/YPTSocket.php | 2 +- plugin/YPTSocket/script.js | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/plugin/YPTSocket/Message.php b/plugin/YPTSocket/Message.php index 99fa4b5c7c..a932a4cc9d 100644 --- a/plugin/YPTSocket/Message.php +++ b/plugin/YPTSocket/Message.php @@ -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"); } @@ -58,7 +60,17 @@ class Message implements MessageComponentInterface { $client['live_key'] = object_to_array(@$json->live_key); $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']; diff --git a/plugin/YPTSocket/YPTSocket.php b/plugin/YPTSocket/YPTSocket.php index 74f910b93c..e31b621a5e 100644 --- a/plugin/YPTSocket/YPTSocket.php +++ b/plugin/YPTSocket/YPTSocket.php @@ -40,7 +40,7 @@ class YPTSocket extends PluginAbstract { } public static function getServerVersion() { - return "2.7"; + return "2.8"; } public function updateScript() { diff --git a/plugin/YPTSocket/script.js b/plugin/YPTSocket/script.js index 5609909d59..0e85f2c66a 100644 --- a/plugin/YPTSocket/script.js +++ b/plugin/YPTSocket/script.js @@ -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 + ")"); } }