Update: Combined Endpoints to do correct jobs.
This commit is contained in:
@@ -25,62 +25,10 @@ public sealed class RtcCallService
|
||||
return activeCalls.Any(x => x.ChannelId == channelId && x.IsActive);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Joins a user to a channel call and determines whether they should become the offerer
|
||||
/// or join an already active call.
|
||||
/// </summary>
|
||||
/// <param name="channelId">The channel being joined.</param>
|
||||
/// <param name="username">The user joining the call.</param>
|
||||
/// <returns>
|
||||
/// A join response describing whether a call already exists, who the offer user is,
|
||||
/// and whether the caller should act as the offerer.
|
||||
/// </returns>
|
||||
public async Task<RtcJoinResponse> JoinCallAsync(string channelId, string username)
|
||||
{
|
||||
//TODO: move active call creation logic to WriteOfferAsync Function
|
||||
var activeCalls = await _db.Select<RtcActiveCall>("rtc_active_calls");
|
||||
var activeCall = activeCalls.FirstOrDefault(x => x.ChannelId == channelId && x.IsActive);
|
||||
|
||||
if (activeCall is null)
|
||||
{
|
||||
await _db.Create("rtc_active_calls", new RtcActiveCall
|
||||
{
|
||||
ChannelId = channelId,
|
||||
OfferUser = username,
|
||||
IsActive = true,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = DateTime.UtcNow
|
||||
});
|
||||
|
||||
return new RtcJoinResponse
|
||||
{
|
||||
ChannelId = channelId,
|
||||
HasActiveCall = false,
|
||||
IsOfferer = true,
|
||||
OfferUser = username,
|
||||
OfferSdp = null
|
||||
};
|
||||
}
|
||||
|
||||
var offers = await _db.Select<RtcOffer>("rtc_offers");
|
||||
var offer = offers //TODO: Remove offer creation in C#
|
||||
.Where(x => x.ChannelId == channelId)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.FirstOrDefault();
|
||||
|
||||
return new RtcJoinResponse
|
||||
{
|
||||
ChannelId = channelId,
|
||||
HasActiveCall = true,
|
||||
IsOfferer = false,
|
||||
OfferUser = activeCall.OfferUser,
|
||||
OfferSdp = offer?.Sdp
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates or updates the current SDP offer for a user in the specified channel.
|
||||
/// Also refreshes the active call timestamp when a matching active call exists.
|
||||
/// If no active call exists for the channel, a new active call is created.
|
||||
/// Otherwise, the existing active call timestamp is refreshed.
|
||||
/// </summary>
|
||||
/// <param name="channelId">The channel the offer belongs to.</param>
|
||||
/// <param name="username">The user creating the offer.</param>
|
||||
@@ -110,7 +58,19 @@ public sealed class RtcCallService
|
||||
|
||||
var activeCalls = await _db.Select<RtcActiveCall>("rtc_active_calls");
|
||||
var activeCall = activeCalls.FirstOrDefault(x => x.ChannelId == channelId && x.IsActive);
|
||||
if (activeCall is not null)
|
||||
|
||||
if (activeCall is null)
|
||||
{
|
||||
await _db.Create("rtc_active_calls", new RtcActiveCall
|
||||
{
|
||||
ChannelId = channelId,
|
||||
OfferUser = username,
|
||||
IsActive = true,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
activeCall.UpdatedAt = DateTime.UtcNow;
|
||||
await _db.Merge<RtcActiveCall, RtcActiveCall>(activeCall);
|
||||
@@ -281,9 +241,11 @@ public sealed class RtcCallService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<object?> GetOffersAsync()
|
||||
public async Task<List<RtcOffer>> GetOffersAsync()
|
||||
{
|
||||
var offers = await _db.Select<RtcOffer>("rtc_offers");
|
||||
return offers;
|
||||
return offers
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user