This commit is contained in:
parent
9e985d05f1
commit
33c20bf59d
11 changed files with 107 additions and 45 deletions
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue