1 parent
756d2a98b2
commit
a00dcc4e70
4 files changed
+144
-70
No files matched your search
Regular → Executable
+14
-7
@@ -5,31 +5,38 @@ if (!isset($_GET['user'])) {
|
||||
}
|
||||
|
||||
$user = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['user']);
|
||||
|
||||
// Verifica se a live está online (arquivo .mpd existe)
|
||||
$mpdPath = "/var/www/html/stream/{$user}.mpd";
|
||||
if (!file_exists($mpdPath)) {
|
||||
http_response_code(404);
|
||||
exit("Live offline");
|
||||
}
|
||||
|
||||
header("Content-Type: text/event-stream");
|
||||
header("Cache-Control: no-cache");
|
||||
header("Connection: keep-alive");
|
||||
|
||||
$tmp_file = sys_get_temp_dir() . "/relay_chat_{$user}.txt";
|
||||
|
||||
// Cria o arquivo se ainda não existir
|
||||
if (!file_exists($tmp_file)) {
|
||||
file_put_contents($tmp_file, '');
|
||||
}
|
||||
|
||||
$last_modif = 0;
|
||||
$lastMessage = '';
|
||||
|
||||
while (true) {
|
||||
clearstatcache();
|
||||
$current_modif = filemtime($tmp_file);
|
||||
$currentMessage = trim(file_get_contents($tmp_file));
|
||||
|
||||
if ($current_modif > $last_modif) {
|
||||
$last_modif = $current_modif;
|
||||
$data = file_get_contents($tmp_file);
|
||||
echo "data: " . trim($data) . "\n\n";
|
||||
if ($currentMessage !== '' && $currentMessage !== $lastMessage) {
|
||||
echo "data: " . $currentMessage . "\n\n";
|
||||
ob_flush();
|
||||
flush();
|
||||
$lastMessage = $currentMessage;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
?>
|
||||
|
||||
Regular → Executable
+2
-2
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
if (isset($_POST['mensagem']) && isset($_GET['user'])) {
|
||||
$mensagem = trim($_POST['mensagem']);
|
||||
$user = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['user']); // sanitiza o nome do usuário
|
||||
$user = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['user']);
|
||||
|
||||
if ($mensagem !== '') {
|
||||
$tmp_file = sys_get_temp_dir() . "/relay_chat_{$user}.txt";
|
||||
file_put_contents($tmp_file, $mensagem);
|
||||
file_put_contents($tmp_file, $mensagem); // sobrescreve, não acumula
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user