This commit is contained in:
parent
a9e3cf2ea5
commit
48f62c8c02
6 changed files with 107 additions and 5 deletions
|
|
@ -221,15 +221,21 @@ void WatchSyncController::broadcastRoomSync(const std::string& realmId) {
|
|||
}
|
||||
|
||||
// Add 1 second buffer to account for timing variations
|
||||
if (it->second.durationSeconds > 0 &&
|
||||
expectedTime >= static_cast<double>(it->second.durationSeconds) + 1.0) {
|
||||
// Also check client-reported video end as fallback when duration is unknown
|
||||
bool durationBasedEnd = it->second.durationSeconds > 0 &&
|
||||
expectedTime >= static_cast<double>(it->second.durationSeconds) + 1.0;
|
||||
bool clientReportedEnd = it->second.videoEndedReported;
|
||||
|
||||
if (durationBasedEnd || clientReportedEnd) {
|
||||
shouldAutoAdvance = true;
|
||||
// Mark as ended to prevent multiple auto-advance calls
|
||||
it->second.playbackState = "ended";
|
||||
it->second.videoEndedReported = false; // Reset the flag
|
||||
it->second.stateVersion++;
|
||||
LOG_INFO << "Video ended in room " << realmId << ", auto-advancing"
|
||||
<< " (expectedTime=" << expectedTime
|
||||
<< ", duration=" << it->second.durationSeconds << ")";
|
||||
<< ", duration=" << it->second.durationSeconds
|
||||
<< ", clientReported=" << clientReportedEnd << ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -799,6 +805,8 @@ void WatchSyncController::handleNewMessage(const WebSocketConnectionPtr& wsConnP
|
|||
handleUpdateDuration(wsConnPtr, info, json);
|
||||
} else if (msgType == "lock_update") {
|
||||
handleLockUpdate(wsConnPtr, info, json);
|
||||
} else if (msgType == "video_ended") {
|
||||
handleVideoEnded(wsConnPtr, info);
|
||||
} else {
|
||||
sendError(wsConnPtr, "Unknown message type: " + msgType);
|
||||
}
|
||||
|
|
@ -1609,3 +1617,30 @@ void WatchSyncController::handleLockUpdate(const WebSocketConnectionPtr& wsConnP
|
|||
|
||||
broadcastToRoom(info.realmId, broadcast);
|
||||
}
|
||||
|
||||
void WatchSyncController::handleVideoEnded(const WebSocketConnectionPtr& wsConnPtr,
|
||||
const ViewerInfo& info) {
|
||||
if (info.realmId.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO << "Video ended reported by client in room " << info.realmId;
|
||||
|
||||
// Set the videoEndedReported flag in room state
|
||||
// This is a fallback for when duration-based detection fails
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(roomStatesMutex_);
|
||||
auto it = roomStates_.find(info.realmId);
|
||||
if (it != roomStates_.end()) {
|
||||
// Only set if we haven't already processed an end event recently
|
||||
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
if (now - it->second.lastSkipMs >= SKIP_DEBOUNCE_MS) {
|
||||
it->second.videoEndedReported = true;
|
||||
LOG_INFO << "Set videoEndedReported=true for room " << info.realmId;
|
||||
} else {
|
||||
LOG_DEBUG << "Ignoring video_ended - skip was recent for room " << info.realmId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ private:
|
|||
|
||||
// State freshness tracking
|
||||
int64_t lastDbSyncMs = 0; // Last time state was synced from database
|
||||
|
||||
// Client-reported video end (fallback when duration is unknown)
|
||||
bool videoEndedReported = false; // True when client reports video ended
|
||||
};
|
||||
|
||||
static std::unordered_map<WebSocketConnectionPtr, ViewerInfo> viewers_;
|
||||
|
|
@ -128,6 +131,9 @@ private:
|
|||
const ViewerInfo& info,
|
||||
const Json::Value& data);
|
||||
|
||||
void handleVideoEnded(const WebSocketConnectionPtr& wsConnPtr,
|
||||
const ViewerInfo& info);
|
||||
|
||||
void sendError(const WebSocketConnectionPtr& wsConnPtr, const std::string& error);
|
||||
void sendSuccess(const WebSocketConnectionPtr& wsConnPtr, const Json::Value& data);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue