fixes lol
All checks were successful
Build and Push / build-all (push) Successful in 9m27s

This commit is contained in:
doomtube 2026-01-11 10:57:46 -05:00
parent 9e985d05f1
commit 33c20bf59d
11 changed files with 107 additions and 45 deletions

View file

@ -211,20 +211,22 @@ void StreamController::issueViewerToken(const HttpRequestPtr &,
void StreamController::heartbeat(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback,
const std::string &realmId,
const std::string &streamKey) {
auto token = req->getCookie("viewer_token");
// Use realm-specific cookie to support multi-stream viewing
auto token = req->getCookie("viewer_token_" + realmId);
if (token.empty()) {
callback(jsonResp({}, k403Forbidden));
return;
}
RedisHelper::getKeyAsync("viewer_token:" + token,
RedisHelper::getKeyAsync("viewer_token:" + token,
[callback, streamKey, token](const std::string& storedStreamKey) {
if (storedStreamKey != streamKey) {
callback(jsonResp({}, k403Forbidden));
return;
}
// Refresh token TTL to 5 minutes on heartbeat
services::RedisHelper::instance().expireAsync("viewer_token:" + token, 300,
[callback](bool success) {
@ -232,7 +234,7 @@ void StreamController::heartbeat(const HttpRequestPtr &req,
callback(jsonResp({}, k500InternalServerError));
return;
}
callback(jsonOk(json({
{"success", true},
{"renewed", true}

View file

@ -17,7 +17,7 @@ public:
ADD_METHOD_TO(StreamController::getStreamStats, "/api/stream/stats/{1}", Get);
ADD_METHOD_TO(StreamController::getActiveStreams, "/api/stream/active", Get);
ADD_METHOD_TO(StreamController::issueViewerToken, "/api/stream/token/{1}", Get);
ADD_METHOD_TO(StreamController::heartbeat, "/api/stream/heartbeat/{1}", Post);
ADD_METHOD_TO(StreamController::heartbeat, "/api/stream/heartbeat/{1}/{2}", Post);
// OvenMediaEngine webhook endpoints
ADD_METHOD_TO(StreamController::handleOmeWebhook, "/api/webhook/ome", Post);
ADD_METHOD_TO(StreamController::handleOmeAdmission, "/api/webhook/ome/admission", Post);
@ -47,6 +47,7 @@ public:
void heartbeat(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback,
const std::string &realmId,
const std::string &streamKey);
// OvenMediaEngine webhook handlers

View file

@ -188,17 +188,24 @@ void StatsService::updateStreamStats(const std::string& streamKey) {
// Only broadcast if stream has meaningful data or is live
if (updatedStats.isLive || updatedStats.totalBytesIn > 0 || updatedStats.uniqueViewers > 0) {
// Fetch live_started_at for duration display
// Fetch live_started_at and viewer_multiplier for duration display and consistent counts
auto dbClient = app().getDbClient();
*dbClient << "SELECT live_started_at FROM realms WHERE stream_key = $1"
*dbClient << "SELECT live_started_at, viewer_multiplier FROM realms WHERE stream_key = $1"
<< streamKey
>> [streamKey, updatedStats](const orm::Result& r) {
Json::Value msg;
msg["type"] = "stats_update";
msg["stream_key"] = streamKey;
// Apply viewer multiplier for consistent display across all sources
int multiplier = 1;
if (!r.empty() && !r[0]["viewer_multiplier"].isNull()) {
multiplier = r[0]["viewer_multiplier"].as<int>();
if (multiplier < 1) multiplier = 1;
}
auto& s = msg["stats"];
JSON_INT(s, "connections", updatedStats.uniqueViewers);
JSON_INT(s, "connections", updatedStats.uniqueViewers * multiplier);
JSON_INT(s, "raw_connections", updatedStats.currentConnections);
s["bitrate"] = updatedStats.bitrate;
s["resolution"] = updatedStats.resolution;
@ -213,12 +220,12 @@ void StatsService::updateStreamStats(const std::string& streamKey) {
s["live_started_at"] = r[0]["live_started_at"].as<std::string>();
}
// Protocol breakdown
// Protocol breakdown (also apply multiplier for consistency)
auto& pc = s["protocol_connections"];
JSON_INT(pc, "webrtc", updatedStats.protocolConnections.webrtc);
JSON_INT(pc, "hls", updatedStats.protocolConnections.hls);
JSON_INT(pc, "llhls", updatedStats.protocolConnections.llhls);
JSON_INT(pc, "dash", updatedStats.protocolConnections.dash);
JSON_INT(pc, "webrtc", updatedStats.protocolConnections.webrtc * multiplier);
JSON_INT(pc, "hls", updatedStats.protocolConnections.hls * multiplier);
JSON_INT(pc, "llhls", updatedStats.protocolConnections.llhls * multiplier);
JSON_INT(pc, "dash", updatedStats.protocolConnections.dash * multiplier);
StreamWebSocketController::broadcastStatsUpdate(msg);
}