소스 검색

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

徐志豪 5 년 전
부모
커밋
718eeea260
1개의 변경된 파일3개의 추가작업 그리고 1개의 파일을 삭제
  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;
 
-    });
+    })
 
   }