From b12e3315febe3834d0dd98d8480ce34d2f9310f0 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 12 Jul 2025 01:54:00 +0800 Subject: [PATCH] :bug: Fixes of bugs --- .../Chat/Realtime/CloudflareService.cs | 9 +++-- .../Chat/RealtimeCallController.cs | 36 +++++++++---------- DysonNetwork.Sphere/appsettings.json | 2 +- DysonNetwork.sln.DotSettings.user | 1 + 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/DysonNetwork.Sphere/Chat/Realtime/CloudflareService.cs b/DysonNetwork.Sphere/Chat/Realtime/CloudflareService.cs index 188b9de..edd9fda 100644 --- a/DysonNetwork.Sphere/Chat/Realtime/CloudflareService.cs +++ b/DysonNetwork.Sphere/Chat/Realtime/CloudflareService.cs @@ -40,8 +40,7 @@ public class CloudflareRealtimeService : IRealtimeService var requestBody = new { title = roomName, - preferred_region = _configuration["Realtime:Cloudflare:PreferredRegion"], - data = metadata + preferred_region = _configuration["Realtime:Cloudflare:PreferredRegion"] }; var content = new StringContent(JsonSerializer.Serialize(requestBody), Encoding.UTF8, "application/json"); @@ -106,11 +105,15 @@ public class CloudflareRealtimeService : IRealtimeService } // Participant doesn't exist, create a new one + var baseUrl = _configuration["BaseUrl"]; var requestBody = new { name = "@" + account.Name, + picture = account.Profile.Picture is not null + ? $"{baseUrl}/api/files/{account.Profile.Picture.Id}" + : null, preset_name = isAdmin ? "group_call_host" : "group_call_participant", - custom_user_id = account.Id.ToString() + custom_participant_id = account.Id.ToString() }; var content = new StringContent( diff --git a/DysonNetwork.Sphere/Chat/RealtimeCallController.cs b/DysonNetwork.Sphere/Chat/RealtimeCallController.cs index 53e702c..426b856 100644 --- a/DysonNetwork.Sphere/Chat/RealtimeCallController.cs +++ b/DysonNetwork.Sphere/Chat/RealtimeCallController.cs @@ -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()!; - /// /// 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!; /// - /// The LiveKit server endpoint + /// The provider server endpoint /// public string Endpoint { get; set; } = null!; @@ -196,24 +194,24 @@ public class CallParticipant /// The participant's identity (username) /// public string Identity { get; set; } = null!; - + /// /// The participant's display name /// public string Name { get; set; } = null!; - + /// /// The participant's account ID if available /// public Guid? AccountId { get; set; } - + /// /// The participant's profile in the chat /// public ChatMember? Profile { get; set; } - + /// /// When the participant joined the call /// public DateTime JoinedAt { get; set; } -} +} \ No newline at end of file diff --git a/DysonNetwork.Sphere/appsettings.json b/DysonNetwork.Sphere/appsettings.json index 0f21995..7d464e0 100644 --- a/DysonNetwork.Sphere/appsettings.json +++ b/DysonNetwork.Sphere/appsettings.json @@ -86,7 +86,7 @@ "SubjectPrefix": "Solar Network" }, "Realtime": { - "Provider": "LiveKit", + "Provider": "Cloudflare", "LiveKit": { "Endpoint": "https://solar-network-im44o8gq.livekit.cloud", "ApiKey": "APIs6TiL8wj3A4j", diff --git a/DysonNetwork.sln.DotSettings.user b/DysonNetwork.sln.DotSettings.user index c088690..2d8eb61 100644 --- a/DysonNetwork.sln.DotSettings.user +++ b/DysonNetwork.sln.DotSettings.user @@ -85,6 +85,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded