Explorar el Código

feat:断开连接的时候通知web端

徐志豪 hace 5 años
padre
commit
718eeea260
Se han modificado 1 ficheros con 3 adiciones y 1 borrados
  1. 3 1
      server/index.js

+ 3 - 1
server/index.js

@@ -25,6 +25,7 @@ module.exports = class WebSocketServer {
       let user = socket.handshake.query
       this._users.push(user)
       const roomId = user['roomId']
+      console.log(user)
       socket.join(roomId, () => {
         let roomsPerson = this._roomPerson.get(roomId) || []
         roomsPerson.push(user)
@@ -57,6 +58,7 @@ module.exports = class WebSocketServer {
         // 断开连接的把roomsPerson中的user去掉
         roomsPerson = roomsPerson.filter(item => item !== user)
         this._roomPerson.set(roomId, roomsPerson)
+        this.io.to(roomId).emit('vr_request', { persons: roomsPerson.filter(item => !item.isClient) });
         console.log("关闭连接", reason);
       });
       socket.on("error", function (reason) {
@@ -64,7 +66,7 @@ module.exports = class WebSocketServer {
       });
       return this;
 
-    });
+    })
 
   }