|
@@ -137,8 +137,14 @@ public class WebSocketServer {
|
|
|
room.put(userId, session);
|
|
room.put(userId, session);
|
|
|
|
|
|
|
|
// 存储用户进入直播间的时间到 Redis(用于计算在线时长)
|
|
// 存储用户进入直播间的时间到 Redis(用于计算在线时长)
|
|
|
|
|
+ // 如果已经存在进入时间,说明是重连,不应该覆盖,保持原来的进入时间
|
|
|
String entryTimeKey = String.format(USER_ENTRY_TIME_KEY, liveId, userId);
|
|
String entryTimeKey = String.format(USER_ENTRY_TIME_KEY, liveId, userId);
|
|
|
- redisCache.setCacheObject(entryTimeKey, System.currentTimeMillis(), 24, TimeUnit.HOURS);
|
|
|
|
|
|
|
+ Long existingEntryTime = redisCache.getCacheObject(entryTimeKey);
|
|
|
|
|
+ if (existingEntryTime == null) {
|
|
|
|
|
+ // 首次连接,记录进入时间
|
|
|
|
|
+ redisCache.setCacheObject(entryTimeKey, System.currentTimeMillis(), 24, TimeUnit.HOURS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果是重连,不覆盖进入时间,保持原来的进入时间以便正确计算总时长
|
|
|
|
|
|
|
|
// 直播间浏览量 +1
|
|
// 直播间浏览量 +1
|
|
|
redisCache.incr(PAGE_VIEWS_KEY + liveId, 1);
|
|
redisCache.incr(PAGE_VIEWS_KEY + liveId, 1);
|