|
@@ -1,46 +1,49 @@
|
|
|
-import { BasicController } from "./basicController.js";
|
|
|
-import { RoomController } from "./room/index.js";
|
|
|
-import { SyncDeviceController } from "./syncDeviceController.js";
|
|
|
-import { FROMTYPE } from "../enum/index.js";
|
|
|
-import { updateRoomUser } from "../service/userService.js";
|
|
|
-
|
|
|
-export class ConnectController extends BasicController {
|
|
|
- constructor(...args) {
|
|
|
- super(...args);
|
|
|
- this.roomController = new RoomController(this.io, this.socket, this.redisCli);
|
|
|
- this.syncDeviceController = new SyncDeviceController(this.io, this.socket, this.redisCli, this.roomController);
|
|
|
- }
|
|
|
- async run() {
|
|
|
- await this.roomController.run();
|
|
|
- await this.syncDeviceController.run();
|
|
|
-
|
|
|
- this.socket.on("disconnect", async (reason) => {
|
|
|
- const res = String(reason).split(" ");
|
|
|
- console.log("disconnect-reason", res);
|
|
|
-
|
|
|
- // if (res.includes("close") || res.includes("disconnect")) {
|
|
|
- if ([FROMTYPE.MiniAPP].includes(Number(this.roomController.user.from))) {
|
|
|
- const userId = this.roomController.userId;
|
|
|
- const from = this.roomController.user.from;
|
|
|
- const roomId = this.roomController.roomId;
|
|
|
- const role = this.roomController.user.role;
|
|
|
- const user = this.roomController.user;
|
|
|
- this.roomController.logger.info("断开连接", {
|
|
|
- userId,
|
|
|
- from,
|
|
|
- roomId,
|
|
|
- });
|
|
|
- // if (this.roomController.isHoster(role)) {
|
|
|
- user.onlineStatus = 0;
|
|
|
- await updateRoomUser(roomId, userId, user);
|
|
|
- this.roomController.roomAssistant.notifyUsersChange(roomId, user, false);
|
|
|
- // await updateRoomUser(this.roomController.user);
|
|
|
- // }
|
|
|
- // this.roomController.roomAssistant.setRoomAvailableBySeconds(this.roomController.sessionId, 3 * 60);
|
|
|
- // this.roomController.roomAssistant.disconnect();
|
|
|
- // this.roomController.roomAssistant.unWatchRoomExpired();
|
|
|
- // }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
+import { BasicController } from "./basicController.js";
|
|
|
+import { RoomController } from "./room/index.js";
|
|
|
+import { SyncDeviceController } from "./syncDeviceController.js";
|
|
|
+import { FROMTYPE } from "../enum/index.js";
|
|
|
+import { updateRoomUser } from "../service/userService.js";
|
|
|
+
|
|
|
+export class ConnectController extends BasicController {
|
|
|
+ constructor(...args) {
|
|
|
+ super(...args);
|
|
|
+ this.roomController = new RoomController(this.io, this.socket, this.redisCli);
|
|
|
+ this.syncDeviceController = new SyncDeviceController(this.io, this.socket, this.redisCli, this.roomController);
|
|
|
+ }
|
|
|
+ async run() {
|
|
|
+ await this.roomController.run();
|
|
|
+ await this.syncDeviceController.run();
|
|
|
+
|
|
|
+ this.socket.on("disconnect", async (reason) => {
|
|
|
+ const res = String(reason).split(" ");
|
|
|
+ console.log("disconnect-reason", res);
|
|
|
+
|
|
|
+ // if (res.includes("close") || res.includes("disconnect")) {
|
|
|
+ if ([FROMTYPE.MiniAPP].includes(Number(this.roomController.user.from))) {
|
|
|
+ const userId = this.roomController.userId;
|
|
|
+ const from = this.roomController.user.from;
|
|
|
+ const roomId = this.roomController.roomId;
|
|
|
+ const role = this.roomController.user.role;
|
|
|
+ const user = this.roomController.user;
|
|
|
+ this.roomController.logger.info("断开连接", {
|
|
|
+ userId,
|
|
|
+ from,
|
|
|
+ roomId,
|
|
|
+ });
|
|
|
+ // if (this.roomController.isHoster(role)) {
|
|
|
+ setTimeout(()=>{
|
|
|
+ user.onlineStatus = 0;
|
|
|
+ await updateRoomUser(roomId, userId, user);
|
|
|
+ this.roomController.roomAssistant.notifyUsersChange(roomId, user, false);
|
|
|
+ })
|
|
|
+
|
|
|
+ // await updateRoomUser(this.roomController.user);
|
|
|
+ // }
|
|
|
+ // this.roomController.roomAssistant.setRoomAvailableBySeconds(this.roomController.sessionId, 3 * 60);
|
|
|
+ // this.roomController.roomAssistant.disconnect();
|
|
|
+ // this.roomController.roomAssistant.unWatchRoomExpired();
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|