🐛 Fixes of bugs

This commit is contained in:
2025-07-12 01:54:00 +08:00
parent da4ee81c95
commit b12e3315fe
4 changed files with 25 additions and 23 deletions

View File

@ -6,11 +6,6 @@ using Swashbuckle.AspNetCore.Annotations;
namespace DysonNetwork.Sphere.Chat;
public class RealtimeChatConfiguration
{
public string Endpoint { get; set; } = null!;
}
[ApiController]
[Route("/api/chat/realtime")]
public class RealtimeCallController(
@ -20,9 +15,6 @@ public class RealtimeCallController(
IRealtimeService realtime
) : ControllerBase
{
private readonly RealtimeChatConfiguration _config =
configuration.GetSection("RealtimeChat").Get<RealtimeChatConfiguration>()!;
/// <summary>
/// This endpoint is especially designed for livekit webhooks,
/// for update the call participates and more.
@ -35,9 +27,9 @@ public class RealtimeCallController(
using var reader = new StreamReader(Request.Body);
var postData = await reader.ReadToEndAsync();
var authHeader = Request.Headers.Authorization.ToString();
await realtime.ReceiveWebhook(postData, authHeader);
return Ok();
}
@ -90,11 +82,17 @@ public class RealtimeCallController(
return BadRequest("Call session is not properly configured.");
var isAdmin = member.Role >= ChatMemberRole.Moderator;
var userToken = realtime.GetUserToken(currentUser, ongoingCall.SessionId, isAdmin);
var userToken = await realtime.GetUserTokenAsync(currentUser, ongoingCall.SessionId, isAdmin);
// Get LiveKit endpoint from configuration
var endpoint = _config.Endpoint ??
throw new InvalidOperationException("LiveKit endpoint configuration is missing");
var endpoint = configuration[$"Realtime:{realtime.ProviderName}:Endpoint"] ?? realtime.ProviderName switch
{
// Unusable for sure, just for placeholder
"LiveKit" => "https://livekit.cloud",
"Cloudflare" => "https://rtk.realtime.cloudflare.com/v2",
// Unusable for sure, just for placeholder
_ => "https://example.com"
};
// Create the response model
var response = new JoinCallResponse
@ -162,7 +160,7 @@ public class JoinCallResponse
public string Provider { get; set; } = null!;
/// <summary>
/// The LiveKit server endpoint
/// The provider server endpoint
/// </summary>
public string Endpoint { get; set; } = null!;
@ -196,24 +194,24 @@ public class CallParticipant
/// The participant's identity (username)
/// </summary>
public string Identity { get; set; } = null!;
/// <summary>
/// The participant's display name
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// The participant's account ID if available
/// </summary>
public Guid? AccountId { get; set; }
/// <summary>
/// The participant's profile in the chat
/// </summary>
public ChatMember? Profile { get; set; }
/// <summary>
/// When the participant joined the call
/// </summary>
public DateTime JoinedAt { get; set; }
}
}