ShawnZhang2015 / grace

探索CocosCreator的正确的编程姿势
MIT License
44 stars 19 forks source link

bugfix #3

Open ghost opened 5 years ago

ghost commented 5 years ago
git diff  > patch
  1. fixed #2
  2. decode msg error
diff --git a/assets/Script/common/socket.js b/assets/Script/common/socket.js
index 0c85401..2e911dd 100644
--- a/assets/Script/common/socket.js
+++ b/assets/Script/common/socket.js
@@ -37,7 +37,7 @@ Socket.prototype = {
     on(actionCode, cb) {
         this.notification.on(actionCode.toString(), (event) => {
             if (cb) {
-                cb(event.detail);
+                cb(event);
             }
         })    
     },
diff --git a/server/index.js b/server/index.js
index 228a56e..e69faa9 100644
--- a/server/index.js
+++ b/server/index.js
@@ -33,4 +33,12 @@ ws.on('connection', function(client){
             console.log('clinet closed');
         }
     });
+
+    client.on('error', () => {
+        let index = clients.indexOf(client);
+        if (index !== -1) {
+            clients.splice(index, 1);
+            console.log('clinet error closed');
+        }
+    });
 });
\ No newline at end of file