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

@ -243,7 +243,7 @@ class Live extends PluginAbstract {
continue;
}
//$link = addQueryStringParameter($link, 'live_schedule', intval($value['id']));
$link = $link.'/ls/'.intval($value['id']).'/';
$link = $link . '/ls/' . intval($value['id']) . '/';
$LiveUsersLabelLive = ($liveUsersEnabled ? getLiveUsersLabelLive($value['key'], $value['live_servers_id']) : '');
$title = self::getTitleFromKey($value['key'], $value['title']);
@ -365,17 +365,17 @@ class Live extends PluginAbstract {
preg_match('/([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})(.*)/', $startsOnDate, $matches);
if(empty($matches) || empty($matches[2])){
if (empty($matches) || empty($matches[2])) {
$datetime = "'$startsOnDate'";
}else{
} else {
$datetime = "convertDateFromTimezoneToLocal('{$matches[1]}', '{$matches[2]}')";
}
$startsOnDateTime = strtotime($startsOnDate);
if ($startsOnDateTime > time()) {
$callback .= ';' . '$(\'.' . $uid . ' .liveNow\').attr(\'class\', \'liveNow label label-primary\');'
. '$(\'.' . $uid . ' .liveNow\').text('.$datetime.');'
. 'startTimerToDate('.$datetime.', \'.' . $uid . ' .liveNow\', false);';
. '$(\'.' . $uid . ' .liveNow\').text(' . $datetime . ');'
. 'startTimerToDate(' . $datetime . ', \'.' . $uid . ' .liveNow\', false);';
$comingsoon = $startsOnDateTime;
}
}
@ -1240,7 +1240,7 @@ Click <a href=\"{link}\">here</a> to join our live.";
_error_log("Live::getStatsObject: You need to install the simplexml_load_file function to be able to see the Live stats", AVideoLog::$ERROR);
return false;
}
if(!isset($global['isStatsAccessible'])){
if (!isset($global['isStatsAccessible'])) {
$global['isStatsAccessible'] = array();
}
$name = "getStats" . DIRECTORY_SEPARATOR . "live_servers_id_{$live_servers_id}" . DIRECTORY_SEPARATOR . "getStatsObject";
@ -1332,7 +1332,7 @@ Click <a href=\"{link}\">here</a> to join our live.";
return $xml;
}
static function isStatsAccessible($live_servers_id){
static function isStatsAccessible($live_servers_id) {
global $global;
return !empty($global['isStatsAccessible']) && !empty($global['isStatsAccessible'][$live_servers_id]);
}
@ -1549,20 +1549,21 @@ Click <a href=\"{link}\">here</a> to join our live.";
return $btn;
}
public static function unfinishAllFromStats($force_recreate = false){
public static function unfinishAllFromStats($force_recreate = false) {
$stats = self::getStats($force_recreate);
foreach ($stats as $server) {
if (is_array($server) || is_object($server)) {
foreach ($server as $live) {
if(!empty($live->key)){
if (!empty($live->key)) {
$row = LiveTransmitionHistory::getLatest($live->key, @$live->live_servers_id);
if(!empty($row['finished'])){
if (!empty($row['finished'])) {
LiveTransmitionHistory::unfinishFromTransmitionHistoryId($row['id']);
}
}
}
}
}
}
public static function getStats($force_recreate = false) {
@ -3306,12 +3307,12 @@ Click <a href=\"{link}\">here</a> to join our live.";
return false;
}
public static function getInfo($key, $live_servers_id = null, $live_index = '', $playlists_id_live='') {
public static function getInfo($key, $live_servers_id = null, $live_index = '', $playlists_id_live = '') {
$lso = new LiveStreamObject($key, $live_servers_id, $live_index, $playlists_id_live);
$keyWithIndex=$lso->getKeyWithIndex();
$key=$lso->getKey();
$keyWithIndex = $lso->getKeyWithIndex();
$key = $lso->getKey();
$array = array(
'key' => $key,
'keyWithIndex' => $keyWithIndex,
@ -3345,7 +3346,7 @@ Click <a href=\"{link}\">here</a> to join our live.";
$array['otherLivesSameUser'] = array();
foreach ($otherLivesSameUser as $value) {
if($value['key']!==$keyWithIndex){
if ($value['key'] !== $keyWithIndex) {
$array['otherLivesSameUser'][] = $value;
}
}
@ -3363,13 +3364,13 @@ Click <a href=\"{link}\">here</a> to join our live.";
if (!empty($lth['finished'])) {
$isKeyLiveInStats = self::isKeyLiveInStats($key, $live_servers_id, $live_index);
if(empty($isKeyLiveInStats)){
if (empty($isKeyLiveInStats)) {
$array['isLive'] = false;
$array['isFinished'] = true;
$array['finishedDateTime'] = $lth['finished'];
$array['finishedSecondsAgo'] = secondsIntervalFromNow($lth['finished'], true);
$array['finishedHumanAgo'] = __('Finished') . ' ' . humanTimingAgo($lth['finished']);
}else{
} else {
LiveTransmitionHistory::unfinishFromTransmitionHistoryId($lth['id']);
}
}
@ -3377,13 +3378,13 @@ Click <a href=\"{link}\">here</a> to join our live.";
$array['displayTime'] = '';
if ($array['isFinished']) {
$array['displayTime'] = $array['finishedHumanAgo'];
if(!empty($lt['scheduled_time'])){
if (!empty($lt['scheduled_time'])) {
$time = getTimeInTimezone($lt['scheduled_time'], $lt['timezone']);
$displayTime = strtotime($array['finishedDateTime']);
//var_dump($time, $displayTime, $lt['scheduled_time'], $lt['timezone'], $array['finishedDateTime']);exit;
if($time > $displayTime){
$array['displayTime'] = __('Will start in') . ' ' . humanTiming($time). ", {$lt['scheduled_time']}, {$lt['timezone']}";
if ($time > $displayTime) {
$array['displayTime'] = __('Will start in') . ' ' . humanTiming($time) . ", {$lt['scheduled_time']}, {$lt['timezone']}";
}
}
} else if ($array['isStarded']) {
@ -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');