Ejemplo n.º 1
0
 public function broadcast()
 {
     // // Schedule another broadcast period
     // $this->scheduleBroadcast();
     // If there are clients connected ...
     if (count($this->getClients()) > 0) {
         $burstint = $this->welcome->getOption("burstint");
         // and there is ample data to broadcast ...
         if (strlen($this->pool) >= $burstint) {
             // fetch the data associated with this broadcast ...
             $buf = $this->getPool($burstint);
             // and process the data for each client
             foreach ($this->getClients() as $client) {
                 // If the client specified that it wants metadata, append the
                 // associated metadata to the data
                 $data = $buf . ($client->getOption("metadata") ? $this->meta : null);
                 // If the client is still waiting for preload data ...
                 if ($client->getOption("preload") >= 0) {
                     // and the client still has insufficient data for the configured
                     // preload amount ...
                     if ($client->getOption("preload") > 0) {
                         // append this broadcast to the preload buffer for this client
                         $client->setOption("preloadbuf", $client->getOption("preloadbuf") . $data);
                     } else {
                         // If the client's preload is fully prepared, send it and clear
                         // the preload buffer
                         $client->send($client->getOption("preloadbuf"), false);
                         $client->setOption("preloadbuf", false);
                     }
                     // Decrement the preload quantity
                     $client->setOption("preload", $client->getOption("preload") - 1);
                 }
                 // If the client is not waiting for preload data, send the data in a
                 // regular fashion
                 if ($client->getOption("preload") < 0) {
                     $client->send($data, false);
                 }
             }
         }
     } else {
         if (count(ConnectionManagement::getConnections()) < 1) {
             // Clear the pool if no clients are connected
             $this->getPool();
         }
     }
 }