Comus Party 1.0.0
Application web de mini-jeux en ligne
Chargement...
Recherche...
Aucune correspondance
Dashboard.php
Aller à la documentation de ce fichier.
1<?php
9
10namespace ComusParty\App\Sockets;
11
12use Exception;
13use Ratchet\ConnectionInterface;
14use Ratchet\MessageComponentInterface;
15use SplObjectStorage;
16
17
22class Dashboard implements MessageComponentInterface
23{
28 protected SplObjectStorage $clients;
29
33 public function __construct()
34 {
35 $this->clients = new SplObjectStorage;
36 }
37
43 function onOpen(ConnectionInterface $conn): void
44 {
45 $conn->send(json_encode(['message' => 'Connection established']));
46 $this->clients->attach($conn);
47 }
48
54 function onClose(ConnectionInterface $conn): void
55 {
56 $this->clients->detach($conn);
57 }
58
59 function onError(ConnectionInterface $conn, Exception $e): void
60 {
61 echo "An error has occurred: {$e->getMessage()}\n";
62 $conn->close();
63 }
64
71 function onMessage(ConnectionInterface $from, $msg): void
72 {
73 $command = json_decode($msg, true)['command'];
74 foreach ($this->clients as $client) {
75 $client->send(json_encode(['message' => $command]));
76 }
77 }
78}
Classe Dashboard (Sockets)
Definition Dashboard.php:23
__construct()
Constructeur de la classe Dashboard.
Definition Dashboard.php:33
onClose(ConnectionInterface $conn)
Fonction appelée lors de la déconnexion d'un modérateur.
Definition Dashboard.php:54
onMessage(ConnectionInterface $from, $msg)
Fonction appelée lors de la réception d'un message.
Definition Dashboard.php:71
onError(ConnectionInterface $conn, Exception $e)
Definition Dashboard.php:59
onOpen(ConnectionInterface $conn)
Fonction appelée lors de la connexion d'un modérateur.
Definition Dashboard.php:43