当前位置: 首页>>代码示例>>PHP>>正文


PHP Factory::run方法代码示例

本文整理汇总了PHP中React\EventLoop\Factory::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::run方法的具体用法?PHP Factory::run怎么用?PHP Factory::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在React\EventLoop\Factory的用法示例。


在下文中一共展示了Factory::run方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * Runs the WebSocket client.
  *
  * @return void 
  */
 public function run()
 {
     $this->wsfactory->__invoke($this->gateway)->then(function (WebSocketInstance $ws) {
         $this->ws = $ws;
         $ws->on('message', function ($data, $ws) {
             $this->emit('raw', [$data, $this->discord]);
             $data = json_decode($data);
             if (!is_null($handler = $this->handlers->getHandler($data->t))) {
                 $handler = new $handler();
                 $handlerData = $handler->getData($data->d, $this->discord);
                 $newDiscord = $handler->updateDiscordInstance($handlerData, $this->discord);
                 $this->emit($data->t, [$handlerData, $this->discord, $newDiscord]);
                 $this->discord = $newDiscord;
             }
             if ($data->t == Event::READY) {
                 $tts = $data->d->heartbeat_interval / 1000;
                 $this->loop->addPeriodicTimer($tts, function () use($ws) {
                     $this->send(['op' => 1, 'd' => microtime(true) * 1000]);
                 });
                 $content = $data->d;
                 // set user settings obtain guild data etc.
                 // user client settings
                 $this->discord->user_settings = $content->user_settings;
                 // guilds
                 $guilds = new Collection();
                 foreach ($content->guilds as $guild) {
                     $guildPart = new Guild(['id' => $guild->id, 'name' => $guild->name, 'icon' => $guild->icon, 'region' => $guild->region, 'owner_id' => $guild->owner_id, 'roles' => $guild->roles, 'joined_at' => $guild->joined_at, 'afk_channel_id' => $guild->afk_channel_id, 'afk_timeout' => $guild->afk_timeout, 'large' => $guild->large, 'features' => $guild->features, 'splash' => $guild->splash, 'emojis' => $guild->emojis], true);
                     $channels = new Collection();
                     foreach ($guild->channels as $channel) {
                         $channelPart = new Channel(['id' => $channel->id, 'name' => $channel->name, 'type' => $channel->type, 'topic' => $channel->topic, 'guild_id' => $guild->id, 'position' => $channel->position, 'last_message_id' => $channel->last_message_id, 'permission_overwrites' => $channel->permission_overwrites], true);
                         $channels->push($channelPart);
                     }
                     $guildPart->setCache('channels', $channels);
                     // preload
                     $guildPart->getBansAttribute();
                     // guild members
                     $members = new Collection();
                     foreach ($guild->members as $member) {
                         $memberPart = new Member(['user' => $member->user, 'roles' => $member->roles, 'mute' => $member->mute, 'deaf' => $member->deaf, 'joined_at' => $member->joined_at, 'guild_id' => $guild->id, 'status' => 'offline', 'game' => null], true);
                         // check for presences
                         foreach ($guild->presences as $presence) {
                             if ($presence->user->id == $member->user->id) {
                                 $memberPart->status = $presence->status;
                                 $memberPart->game = $presence->game;
                             }
                         }
                         $members->push($memberPart);
                     }
                     $guildPart->setCache('members', $members);
                     $guilds->push($guildPart);
                 }
                 $this->discord->setCache('guilds', $guilds);
                 // after we do everything, emit ready
                 $this->emit('ready', [$this->discord]);
             }
         });
         $ws->on('close', function ($ws) {
             $this->emit('close', [$ws, $this->discord]);
         });
         $ws->on('error', function ($error, $ws) {
             $this->emit('error', [$error, $ws, $this->discord]);
         });
         if (!$this->sentLoginFrame) {
             $this->sendLoginFrame();
             $this->sentLoginFrame = true;
             $this->emit('sent-login-frame', [$ws, $this->discord]);
         }
     }, function ($e) {
         $this->emit('connectfail', [$e]);
         $this->loop->stop();
     });
     $this->loop->run();
 }
开发者ID:shellbot,项目名称:DiscordPHP,代码行数:78,代码来源:WebSocket.php


注:本文中的React\EventLoop\Factory::run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。