This isn't FULLY functional, but it's what I've made thus far... I'm still working on a Ice Disconnect somewhere at least for me - welcome to test.
This commit is contained in:
@@ -71,11 +71,10 @@ public static class RtcEndpoints
|
||||
return Results.Ok(await rtcCallService.GetAnswersAsync(channelId));
|
||||
});
|
||||
|
||||
//app.MapGet("/api/rtc/participants/{channelId}", (string channelId) => // TODO: UNCOMMENT AND ADD
|
||||
//{
|
||||
// var participants = RtcChannelPresenceService.GetUsernamesInChannel(channelId);
|
||||
// return Results.Ok(participants);
|
||||
//});
|
||||
app.MapGet("/api/rtc/participants/{channelId}", (string channelId) =>
|
||||
{
|
||||
return Results.Ok(RtcChannelPresenceService.GetUsersInChannel(channelId));
|
||||
});
|
||||
|
||||
// Return the latest answer stored for the specified channel.
|
||||
app.MapGet("/api/rtc/answer/{channelId}", async (string channelId, RtcCallService rtcCallService) =>
|
||||
|
||||
@@ -69,9 +69,72 @@ public class ChatSocketBehavior : WebSocketBehavior
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsEncryptedRtcSignal(msg))
|
||||
{
|
||||
HandleEncryptedRtcSignal(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
HandleEncryptedChatMessage(msg);
|
||||
}
|
||||
|
||||
private static bool IsEncryptedRtcSignal(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(msg);
|
||||
var root = doc.RootElement;
|
||||
|
||||
if (!root.TryGetProperty("Type", out var typeProp))
|
||||
return false;
|
||||
|
||||
var type = (SignalType)typeProp.GetInt32();
|
||||
|
||||
return type == SignalType.EncryptedSignal;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEncryptedRtcSignal(string msg)
|
||||
{
|
||||
Console.WriteLine("RTC SIGNAL HIT");
|
||||
SocketRtcSignalMessage? clientPayload;
|
||||
|
||||
try
|
||||
{
|
||||
clientPayload = JsonSerializer.Deserialize<SocketRtcSignalMessage>(msg);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Failed to parse encrypted RTC signal payload.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientPayload is null || clientPayload.Type != SignalType.EncryptedSignal)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(clientPayload.ChannelId))
|
||||
{
|
||||
Console.WriteLine("Encrypted RTC signal missing channel id.");
|
||||
return;
|
||||
}
|
||||
|
||||
var sessionIds = RtcChannelPresenceService.GetSessionsInChannel(clientPayload.ChannelId);
|
||||
|
||||
foreach (var sessionId in sessionIds)
|
||||
{
|
||||
if (sessionId == ID)
|
||||
continue;
|
||||
|
||||
Sessions.SendTo(JsonSerializer.Serialize(clientPayload), sessionId);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Forwarded encrypted RTC signal from {clientPayload.SenderUsername} to channel {clientPayload.ChannelId}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
@@ -35,6 +35,11 @@ public static class RtcChannelPresenceService
|
||||
.Select(x => x.Key)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static List<string> GetUsernamesInChannel(string channelId)
|
||||
{
|
||||
return GetUsersInChannel(channelId).ToList();
|
||||
}
|
||||
|
||||
public static IReadOnlyList<string> GetUsersInChannel(string channelId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user