по адресу
https://site.net/translate/server.php
Fatal error: Uncaught Error: Class "YourNamespace\AudioStream" not found in /sites/site.net/translate/server.php:16 Stack trace: #0 {main} thrown in /sites/criptopays.net/translate/server.php on line 16
server.php
<?php
namespace YourNamespace; // Замените на ваше пространство имен
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\WebSocket\WsServerInterface;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
require __DIR__ . '/vendor/autoload.php'; // Путь к вашей установленной библиотеке Ratchet
use YourNamespace\AudioStream; // Импортируйте класс AudioStream
$server = IoServer::factory(
new HttpServer(
new WsServer(
new AudioStream() // Используйте класс без пространства имен
)
),
8080
);
$server->run();
AudioStream.php
<?php
namespace YourNamespace; // Замените на ваше пространство имен
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class AudioStream implements MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
}
public function onMessage(ConnectionInterface $from, $msg) {
foreach ($this->clients as $client) {
if ($client !== $from) {
$client->send($msg);
}
}
}
public function onClose(ConnectionInterface $conn) {
$this->clients->detach($conn);
}
public function onError(ConnectionInterface $conn, \Exception $e) {
$conn->close();
}
}