-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Neto
committed
Jul 3, 2024
1 parent
ab4d4eb
commit c44d69d
Showing
4 changed files
with
69 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
PlayerSkins::createMarker($rows); | ||
?> | ||
PlayerSkins::getStartPlayerJS('setTimeout(function(){adjustMarkerWidths();},1000);'); | ||
?> | ||
<script src="<?php echo getURL('plugin/Bookmark/script.js'); ?>" type="text/javascript"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function adjustMarkerWidths() { | ||
const markers = document.querySelectorAll('.vjs-marker'); | ||
const totalWidth = 100; // Representing 100% | ||
|
||
markers.forEach((marker, index) => { | ||
const currentLeft = parseFloat(marker.style.left); | ||
let nextLeft = totalWidth; | ||
|
||
if (index < markers.length - 1) { | ||
nextLeft = parseFloat(markers[index + 1].style.left); | ||
} | ||
|
||
const width = nextLeft - currentLeft; | ||
marker.style.width = `calc(${width}% - 2px)`; | ||
marker.classList.add('marker-width-changed'); | ||
}); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", adjustMarkerWidths); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.vjs-marker { | ||
position: absolute; | ||
height: 20px; | ||
top: 0; | ||
background-color: #FFFF0099; | ||
border-radius: 0; | ||
} | ||
|
||
.marker-width-changed { | ||
border: 2px solid red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,181 +1,48 @@ | ||
<?php | ||
|
||
$global['debugMemmory'] = 1; | ||
|
||
use Swoole\WebSocket\Server; | ||
|
||
ini_set('display_errors', 1); | ||
ini_set('display_startup_errors', 1); | ||
error_reporting(E_ALL & ~E_DEPRECATED); | ||
|
||
if (empty($_SERVER['HTTP_HOST'])) { | ||
$_SERVER['HTTP_HOST'] = 'localhost'; | ||
} | ||
|
||
require_once dirname(__FILE__) . '/../../videos/configuration.php'; | ||
_ob_end_clean(); | ||
ini_set('display_errors', 1); | ||
ini_set('display_startup_errors', 1); | ||
error_reporting(E_ALL & ~E_DEPRECATED); | ||
$server = new Server("0.0.0.0", 9502); | ||
|
||
function riseSQLiteError() | ||
{ | ||
_error_log("Socket server For better performance install PDO SQLite in your PHP", AVideoLog::$ERROR); | ||
echo ("sudo apt-get install php-sqlite3") . PHP_EOL; | ||
echo ("after that in your php.ini (" . php_ini_loaded_file() . ") file to uncomment this line:") . PHP_EOL; | ||
echo (";extension=pdo_sqlite.so") . PHP_EOL; | ||
} | ||
|
||
if (function_exists('pdo_drivers') && in_array("sqlite", pdo_drivers())) { | ||
_error_log("Socket server SQLite loading"); | ||
require_once $global['systemRootPath'] . 'plugin/YPTSocket/db.php'; | ||
require_once $global['systemRootPath'] . 'plugin/YPTSocket/MessageSQLite.php'; | ||
} else { | ||
riseSQLiteError(); | ||
require_once $global['systemRootPath'] . 'plugin/YPTSocket/Message.php'; | ||
} | ||
$clients = []; | ||
$messageQueue = []; | ||
|
||
require_once $global['systemRootPath'] . 'objects/autoload.php'; | ||
|
||
if (!isCommandLineInterface()) { | ||
die("Command line only"); | ||
} | ||
|
||
function findValidCertificate($url) | ||
{ | ||
$letsencryptDir = '/etc/letsencrypt/live/'; | ||
$domain = parse_url($url, PHP_URL_HOST); | ||
$certPath = ''; | ||
$keyPath = ''; | ||
|
||
if (is_dir($letsencryptDir . $domain)) { | ||
$certPath = $letsencryptDir . $domain . '/fullchain.pem'; | ||
$keyPath = $letsencryptDir . $domain . '/privkey.pem'; | ||
if (isCertificateValid($certPath)) { | ||
return ['crt' => $certPath, 'key' => $keyPath]; | ||
// Function to broadcast messages to all connected clients | ||
function broadcastMessages($server, $clients, $messages) { | ||
$data = json_encode($messages); | ||
foreach ($clients as $fd) { | ||
if ($server->isEstablished($fd)) { | ||
$server->push($fd, $data); | ||
} | ||
} | ||
|
||
$directories = glob($letsencryptDir . $domain . '-*'); | ||
foreach ($directories as $dir) { | ||
if (is_dir($dir)) { | ||
$certPath = $dir . '/fullchain.pem'; | ||
$keyPath = $dir . '/privkey.pem'; | ||
if (isCertificateValid($certPath)) { | ||
return ['crt' => $certPath, 'key' => $keyPath]; | ||
} | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
|
||
function isCertificateValid($certPath) | ||
{ | ||
if (!file_exists($certPath)) { | ||
return false; | ||
} | ||
|
||
$currentTimestamp = time(); | ||
$opensslCommand = 'openssl'; | ||
$output = []; | ||
exec($opensslCommand . ' x509 -noout -dates -in ' . escapeshellarg($certPath), $output, $returnValue); | ||
|
||
if ($returnValue === 0 && preg_match('/notBefore=(.*?)\nnotAfter=(.*)/i', implode("\n", $output), $matches)) { | ||
$validFrom = strtotime($matches[1]); | ||
$validTo = strtotime($matches[2]); | ||
|
||
if ($validFrom <= $currentTimestamp && $currentTimestamp <= $validTo) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
$SocketDataObj = AVideoPlugin::getDataObject("YPTSocket"); | ||
$SocketDataObj->serverVersion = YPTSocket::getServerVersion(); | ||
|
||
@ob_end_flush(); | ||
_mysql_close(); | ||
_session_write_close(); | ||
exec('ulimit -n 20480'); | ||
$SocketDataObj->port = intval($SocketDataObj->port); | ||
_error_log("Starting Socket server at port {$SocketDataObj->port}"); | ||
|
||
$scheme = parse_url($global['webSiteRootURL'], PHP_URL_SCHEME); | ||
echo "Starting AVideo Socket server version {$SocketDataObj->serverVersion} on port {$SocketDataObj->port}" . PHP_EOL; | ||
|
||
if (!isCertificateValid($SocketDataObj->server_crt_file)) { | ||
echo "Certificate is invalid {$SocketDataObj->server_crt_file}" . PHP_EOL; | ||
$validCertPath = findValidCertificate($global['webSiteRootURL']); | ||
if (!empty($validCertPath['crt'])) { | ||
$SocketDataObj->server_crt_file = $validCertPath['crt']; | ||
$SocketDataObj->server_key_file = $validCertPath['key']; | ||
echo "Certificate found {$SocketDataObj->server_crt_file}" . PHP_EOL; | ||
} | ||
} | ||
|
||
$sslFound = file_exists($SocketDataObj->server_crt_file) && is_readable($SocketDataObj->server_crt_file) && file_exists($SocketDataObj->server_key_file) && is_readable($SocketDataObj->server_key_file); | ||
|
||
if ((strtolower($scheme) !== 'https' || !empty($SocketDataObj->forceNonSecure)) && !$sslFound) { | ||
echo "Your socket server does NOT use a secure connection" . PHP_EOL; | ||
$server = new Server("0.0.0.0", $SocketDataObj->port); | ||
|
||
$server->on('open', function ($server, $request) { | ||
echo "Connection open: {$request->fd}\n"; | ||
}); | ||
|
||
$server->on('message', function ($server, $frame) { | ||
foreach ($server->connections as $fd) { | ||
if ($fd !== $frame->fd) { | ||
$server->push($fd, $frame->data); | ||
} | ||
} | ||
}); | ||
|
||
$server->on('close', function ($server, $fd) { | ||
echo "Connection close: {$fd}\n"; | ||
}); | ||
|
||
$server->start(); | ||
} else { | ||
if (!file_exists($SocketDataObj->server_crt_file) || !is_readable($SocketDataObj->server_crt_file)) { | ||
echo "SSL ERROR, we could not access the CRT file {$SocketDataObj->server_crt_file}, try to run this command as root or use sudo " . PHP_EOL; | ||
} | ||
if (!file_exists($SocketDataObj->server_key_file) || !is_readable($SocketDataObj->server_key_file)) { | ||
echo "SSL ERROR, we could not access the KEY file {$SocketDataObj->server_key_file}, try to run this command as root or use sudo " . PHP_EOL; | ||
// Set a timer to broadcast messages every 10 seconds | ||
$server->tick(10000, function() use ($server, &$clients, &$messageQueue) { | ||
if (!empty($messageQueue)) { | ||
broadcastMessages($server, $clients, $messageQueue); | ||
$messageQueue = []; | ||
} | ||
|
||
echo "Your socket server uses a secure connection" . PHP_EOL; | ||
|
||
$server = new Server("0.0.0.0", $SocketDataObj->port, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL); | ||
|
||
$server->set([ | ||
'ssl_cert_file' => $SocketDataObj->server_crt_file, | ||
'ssl_key_file' => $SocketDataObj->server_key_file, | ||
'ssl_allow_self_signed' => $SocketDataObj->allow_self_signed, | ||
'ssl_verify_peer' => false, | ||
'ssl_verify_peer_name' => false, | ||
'ssl_security_level' => 0, | ||
]); | ||
|
||
$server->on('open', function ($server, $request) { | ||
echo "Connection open: {$request->fd}\n"; | ||
}); | ||
|
||
// Handle new WebSocket connections | ||
$server->on('open', function ($server, $request) use (&$clients) { | ||
echo "Connection open: {$request->fd}\n"; | ||
$clients[] = $request->fd; | ||
}); | ||
|
||
// Handle incoming messages | ||
$server->on('message', function ($server, $frame) use (&$messageQueue) { | ||
echo "Received message: {$frame->data}\n"; | ||
$messageQueue[] = $frame->data; | ||
}); | ||
|
||
// Handle closed connections | ||
$server->on('close', function ($server, $fd) use (&$clients) { | ||
echo "Connection close: {$fd}\n"; | ||
$clients = array_filter($clients, function($clientFd) use ($fd) { | ||
return $clientFd !== $fd; | ||
}); | ||
}); | ||
|
||
$server->on('message', function ($server, $frame) { | ||
foreach ($server->connections as $fd) { | ||
if ($fd !== $frame->fd) { | ||
$server->push($fd, $frame->data); | ||
} | ||
} | ||
}); | ||
|
||
$server->on('close', function ($server, $fd) { | ||
echo "Connection close: {$fd}\n"; | ||
}); | ||
|
||
$server->start(); | ||
} | ||
?> | ||
$server->start(); |