mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 17:59:55 +02:00
Socket updates
This commit is contained in:
parent
c4f7d93846
commit
f9526fa6b5
3 changed files with 29 additions and 13 deletions
|
@ -11,10 +11,12 @@ require_once $global['systemRootPath'] . 'plugin/YPTSocket/functions.php';
|
||||||
class Message implements MessageComponentInterface {
|
class Message implements MessageComponentInterface {
|
||||||
|
|
||||||
protected $clients;
|
protected $clients;
|
||||||
|
protected $clientsWatchinLive;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
//$this->clients = new \SplObjectStorage;
|
//$this->clients = new \SplObjectStorage;
|
||||||
$this->clients = [];
|
$this->clients = [];
|
||||||
|
$this->clientsWatchinLive = [];
|
||||||
_log_message("Construct");
|
_log_message("Construct");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +60,17 @@ class Message implements MessageComponentInterface {
|
||||||
$client['live_key'] = object_to_array(@$json->live_key);
|
$client['live_key'] = object_to_array(@$json->live_key);
|
||||||
$client['ip'] = $json->ip;
|
$client['ip'] = $json->ip;
|
||||||
$client['location'] = $json->location;
|
$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']}");
|
_log_message("New connection ($conn->resourceId) {$json->yptDeviceId} {$client['selfURI']} {$client['browser']}");
|
||||||
|
|
||||||
$this->clients[$conn->resourceId] = $client;
|
$this->clients[$conn->resourceId] = $client;
|
||||||
|
@ -104,16 +116,10 @@ class Message implements MessageComponentInterface {
|
||||||
$l = new \LiveTransmitionHistory($lt['id']);
|
$l = new \LiveTransmitionHistory($lt['id']);
|
||||||
$total_viewers = \LiveUsers::getTotalUsers($lt['key'], $lt['live_servers_id']);
|
$total_viewers = \LiveUsers::getTotalUsers($lt['key'], $lt['live_servers_id']);
|
||||||
$max_viewers_sametime = $l->getMax_viewers_sametime();
|
$max_viewers_sametime = $l->getMax_viewers_sametime();
|
||||||
$viewers_now = 0;
|
if(!empty($live_key['key'])){
|
||||||
foreach ($this->clients as $key => $client) {
|
$viewers_now = count($this->clientsWatchinLive[$live_key['key']]);
|
||||||
if (empty($client['live_key']) || (empty($client['live_key']['key']) && empty($client['live_key']['liveLink']))) {
|
}else if(!empty($live_key['liveLink'])){
|
||||||
continue;
|
$viewers_now = count($this->clientsWatchinLive[$live_key['liveLink']]);
|
||||||
}
|
|
||||||
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 ($viewers_now > $max_viewers_sametime) {
|
if ($viewers_now > $max_viewers_sametime) {
|
||||||
$l->setMax_viewers_sametime($viewers_now);
|
$l->setMax_viewers_sametime($viewers_now);
|
||||||
|
@ -145,6 +151,16 @@ class Message implements MessageComponentInterface {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$client = $this->clients[$conn->resourceId];
|
$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]);
|
unset($this->clients[$conn->resourceId]);
|
||||||
$users_id = $client['users_id'];
|
$users_id = $client['users_id'];
|
||||||
$videos_id = $client['videos_id'];
|
$videos_id = $client['videos_id'];
|
||||||
|
|
|
@ -40,7 +40,7 @@ class YPTSocket extends PluginAbstract {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getServerVersion() {
|
public static function getServerVersion() {
|
||||||
return "2.7";
|
return "2.8";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateScript() {
|
public function updateScript() {
|
||||||
|
|
|
@ -155,7 +155,7 @@ function parseSocketResponse() {
|
||||||
}
|
}
|
||||||
//console.log("parseSocketResponse", json);
|
//console.log("parseSocketResponse", json);
|
||||||
if (json.isAdmin && webSocketServerVersion > json.webSocketServerVersion) {
|
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 + ")");
|
avideoToastWarning("Please restart your socket server. You are running (v" + json.webSocketServerVersion + ") and your client is expecting (v" + webSocketServerVersion + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue