Example #1
0
 /**
  * When a new connection is opened it will be passed to this method
  * @param  ConnectionInterface $conn The socket/connection that just connected to your application
  * @throws \Exception
  */
 function onOpen(ConnectionInterface $socket)
 {
     $user = new User();
     $user->setId($this->id++);
     $user->setSocket($socket);
     $this->users->attach($user);
     $this->emitter->emit("open", [$user]);
     $socket->send(json_encode(["user" => ["id" => $user->getId(), "name" => $user->getName()], "message" => ["type" => "user"]]));
 }
 public function fire()
 {
     // Query logları tutulmasın
     // Server uzun süre çalıştığında memory leak sorunu yaratır
     DB::connection()->enableQueryLog();
     // Tüm userları offline yap.
     User::where('status', 1)->update(['status' => 0]);
     // Websocket Serverını Çalıştır
     $server = IoServer::factory(new HttpServer(new WsServer(new ChatServer())), env("WS_PORT"));
     $server->run();
 }
 public function sendUsersList($to = null)
 {
     $users = User::orderBy('status', 'desc')->orderBy('name', 'asc')->get();
     $message['topic'] = 'users';
     $message['data']['users'] = $users;
     if ($to) {
         $to->send($message);
     } else {
         // herkese gonder
         foreach ($this->clients as $client) {
             if ($client->isLoggedIn()) {
                 $client->send($message);
             }
         }
     }
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }