Updatedededed...? Still needs testing.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using RelayServer.Models;
|
||||
using RelayServer.Services.Crypto;
|
||||
using RelayServer.Services.Data;
|
||||
using RelayServer.Services.Rtc;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
@@ -53,9 +54,31 @@ public class ChatSocketBehavior : WebSocketBehavior
|
||||
HandleGetHistory(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.StartsWith("RTC_JOIN_CHANNEL|"))
|
||||
{
|
||||
HandleRtcJoinChannel(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.StartsWith("RTC_LEAVE_CHANNEL|"))
|
||||
{
|
||||
HandleRtcLeaveChannel(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
HandleEncryptedChatMessage(msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnClose(CloseEventArgs e)
|
||||
{
|
||||
RtcChannelPresenceService.RemoveSession(ID);
|
||||
base.OnClose(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts a display username from a stored user record id value.
|
||||
@@ -419,6 +442,10 @@ public class ChatSocketBehavior : WebSocketBehavior
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool EnsureCoreReady()
|
||||
{
|
||||
if (ClientKeyService is null || Db is null)
|
||||
@@ -430,6 +457,10 @@ public class ChatSocketBehavior : WebSocketBehavior
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool EnsureCryptoReady()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ServerPrivateKey) || string.IsNullOrWhiteSpace(ChannelDbKey))
|
||||
@@ -446,4 +477,50 @@ public class ChatSocketBehavior : WebSocketBehavior
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
private void HandleRtcJoinChannel(string msg)
|
||||
{
|
||||
var parts = msg.Split('|', 3);
|
||||
if (parts.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Invalid RTC_JOIN_CHANNEL payload.");
|
||||
return;
|
||||
}
|
||||
|
||||
var username = parts[1];
|
||||
var channelId = parts[2];
|
||||
|
||||
RtcChannelPresenceService.SetUser(ID, username);
|
||||
RtcChannelPresenceService.JoinChannel(ID, channelId);
|
||||
|
||||
Console.WriteLine($"RTC presence joined: session={ID}, user={username}, channel={channelId}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
private void HandleRtcLeaveChannel(string msg)
|
||||
{
|
||||
var parts = msg.Split('|', 3);
|
||||
if (parts.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Invalid RTC_LEAVE_CHANNEL payload.");
|
||||
return;
|
||||
}
|
||||
|
||||
var username = parts[1];
|
||||
var channelId = parts[2];
|
||||
|
||||
if (RtcChannelPresenceService.IsInChannel(ID, channelId))
|
||||
{
|
||||
RtcChannelPresenceService.LeaveChannel(ID);
|
||||
}
|
||||
|
||||
Console.WriteLine($"RTC presence left: session={ID}, user={username}, channel={channelId}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user