watchRoomService.js 977 B

1234567891011121314151617181920212223242526
  1. import { pubClient } from "../connection/redis.js";
  2. import { logger } from "../core/logger.js";
  3. import { io } from "../core/io.js";
  4. import { FROMTYPE } from "../enum/index.js";
  5. const passiveLeave = async (roomId, userId, socket) => {
  6. setTimeout(async () => {
  7. const isExistUser = await pubClient.exists(userId);
  8. if (isExistUser === 1) {
  9. const baseUser = await pubClient.hGetAll(userId);
  10. const user = baseUser[FROMTYPE.MiniAPP];
  11. if (user && user.isConnected) {
  12. const isConnected = typeof user.isConnected === "string" ? JSON.parse(String(user.isConnected.toLowerCase())) : user.isConnected;
  13. const from = user.from;
  14. logger.info("passiveLeave", { userId, isConnected, from });
  15. if (!isConnected && Number(from) === FROMTYPE.MiniAPP) {
  16. console.log("10秒离开");
  17. }
  18. }
  19. }
  20. }, 10000);
  21. };
  22. export async function watchRoomService(roomId, userId, socket) {
  23. passiveLeave(roomId, userId, socket);
  24. }