()
| 1101 | } |
| 1102 | |
| 1103 | private checkOfflineUsers(): void { |
| 1104 | try { |
| 1105 | const ownerId = this.authState.bootstrapAdminUserId || ""; |
| 1106 | const users = this.opts.store.listHubUsers("active"); |
| 1107 | const now = Date.now(); |
| 1108 | const currentlyOnline = new Set<string>(); |
| 1109 | for (const u of users) { |
| 1110 | if (u.id === ownerId) continue; |
| 1111 | if (u.lastActiveAt && now - u.lastActiveAt < HubServer.OFFLINE_THRESHOLD_MS) { |
| 1112 | currentlyOnline.add(u.id); |
| 1113 | } |
| 1114 | } |
| 1115 | for (const uid of this.knownOnlineUsers) { |
| 1116 | if (!currentlyOnline.has(uid)) { |
| 1117 | const user = users.find(u => u.id === uid); |
| 1118 | if (user) { |
| 1119 | this.notifyAdmins("user_offline", "user", user.username, uid); |
| 1120 | this.opts.log.info(`Hub: user "${user.username}" (${uid}) went offline`); |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | for (const uid of currentlyOnline) { |
| 1125 | if (!this.knownOnlineUsers.has(uid)) { |
| 1126 | const user = users.find(u => u.id === uid); |
| 1127 | if (user) { |
| 1128 | this.notifyAdmins("user_online", "user", user.username, uid); |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | this.knownOnlineUsers = currentlyOnline; |
| 1133 | } catch { /* best-effort */ } |
| 1134 | } |
| 1135 | |
| 1136 | private authenticate(req: http.IncomingMessage) { |
| 1137 | const header = req.headers.authorization; |
no test coverage detected