1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +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

@ -1553,6 +1553,7 @@ Click <a href=\"{link}\">here</a> to join our live.";
$stats = self::getStats($force_recreate);
foreach ($stats as $server) {
if (is_array($server) || is_object($server)) {
foreach ($server as $live) {
if (!empty($live->key)) {
$row = LiveTransmitionHistory::getLatest($live->key, @$live->live_servers_id);
@ -1562,7 +1563,7 @@ Click <a href=\"{link}\">here</a> to join our live.";
}
}
}
}
}
public static function getStats($force_recreate = false) {
@ -3510,7 +3511,6 @@ Click <a href=\"{link}\">here</a> to join our live.";
// , $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

@ -37,7 +37,11 @@ class LoginTwitter extends PluginAbstract {
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() {

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

@ -79,6 +79,7 @@ function verifyTokenSocket($token) {
class SocketMessageType {
const OPEN_CONNECTION = "OPEN_CONNECTION";
const NEW_CONNECTION = "NEW_CONNECTION";
const NEW_DISCONNECTION = "NEW_DISCONNECTION";
const DEFAULT_MESSAGE = "DEFAULT_MESSAGE";

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');