From 12f1c92f333b5c602f5f4d3188262ebfdd219716 Mon Sep 17 00:00:00 2001
From: vilson <545522390@qq.com>
Date: Fri, 25 Jan 2019 11:25:48 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E6=8E=A8?=
 =?UTF-8?q?=E9=80=81=E4=BA=8B=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: vilson <545522390@qq.com>
---
 .../common/Plugins/GateWayWorker/Events.php   | 28 ++++++++++---------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/application/common/Plugins/GateWayWorker/Events.php b/application/common/Plugins/GateWayWorker/Events.php
index 98f528c..4d5d61e 100644
--- a/application/common/Plugins/GateWayWorker/Events.php
+++ b/application/common/Plugins/GateWayWorker/Events.php
@@ -17,6 +17,7 @@
  * 如果发现业务卡死,可以将下面declare打开(去掉//注释),并执行php start.php reload
  * 然后观察一段时间workerman.log看是否有process_timeout异常
  */
+
 //declare(ticks=1);
 
 use GatewayWorker\Lib\Gateway;
@@ -36,11 +37,10 @@ class Events
      */
     public static function onConnect($client_id)
     {
-        // 向当前client_id发送数据
-        $data = ['action' => 'connect', 'data' => ['client_id' => $client_id]];
-        Gateway::sendToClient($client_id, json_encode($data));
         // 向所有人发送
-//        Gateway::sendToAll("$client_id login\r\n");
+        //getAllUidCount
+        $data = ['action' => 'connect', 'data' => ['client_id' => $client_id, 'online' => Gateway::getAllClientCount()]];
+        Gateway::sendToAll(json_encode($data));
     }
 
     /**
@@ -49,20 +49,22 @@ class Events
      * @param mixed $message 具体消息
      * @throws Exception
      */
-   public static function onMessage($client_id, $message)
-   {
+    public static function onMessage($client_id, $message)
+    {
         // 向所有人发送
-        Gateway::sendToAll("$client_id said $message\r\n");
-   }
+        $data = ['action' => 'onMessage', 'data' => ['client_id' => $client_id, 'msg' => "$client_id said $message\r\n"]];
+        Gateway::sendToAll(json_encode($data));
+    }
 
     /**
      * 当用户断开连接时触发
      * @param int $client_id 连接id
      * @throws Exception
      */
-   public static function onClose($client_id)
-   {
-       // 向所有人发送
-       GateWay::sendToAll("$client_id logout\r\n");
-   }
+    public static function onClose($client_id)
+    {
+        // 向所有人发送
+        $data = ['action' => 'onClose', 'data' => ['client_id' => $client_id, 'online' => Gateway::getAllClientCountindex.html()]];
+        GateWay::sendToAll(json_encode($data));
+    }
 }