⚡ Directly message singaling
This commit is contained in:
@@ -108,10 +108,10 @@ The signaling server broadcasts messages using the WebSocketPacket format. All m
|
||||
|
||||
**WebSocketPacket Format:**
|
||||
|
||||
For signaling messages:
|
||||
For signaling messages (see SignalingMessage model):
|
||||
```json
|
||||
{
|
||||
"type": "signaling",
|
||||
"type": "webrtc.signal",
|
||||
"data": {
|
||||
"type": "signaling-message-type",
|
||||
"data": {
|
||||
@@ -119,14 +119,14 @@ For signaling messages:
|
||||
"answer": "...SDP string here...",
|
||||
"candidate": {...ICE candidate data...}
|
||||
},
|
||||
"to": "optional-target-user-id-for-directed-messaging",
|
||||
"senderAccountId": "server-validated-user-guid",
|
||||
"senderInfo": {
|
||||
// Full SnAccount model with user details
|
||||
"id": "user-guid",
|
||||
"name": "username",
|
||||
"nick": "display nickname",
|
||||
"profile": { ... },
|
||||
// ... complete account information
|
||||
"profile": {},
|
||||
"updatedAt": "2022-01-01T00:00:00Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,11 @@ For connection established:
|
||||
{
|
||||
"type": "webrtc",
|
||||
"data": {
|
||||
// welcome data
|
||||
"userId": "user-guid",
|
||||
"roomId": "room-guid",
|
||||
"message": "Connected to call...",
|
||||
"timestamp": "2022-01-01T00:00:00Z",
|
||||
"participants": [...]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@@ -19,6 +19,7 @@ public class SignalingMessage
|
||||
{
|
||||
public string Type { get; set; } = null!;
|
||||
public object? Data { get; set; }
|
||||
public string? To { get; set; }
|
||||
public string? AccountId { get; set; }
|
||||
public SnAccount? Account { get; set; }
|
||||
}
|
||||
@@ -377,9 +378,16 @@ public class RealtimeCallController(
|
||||
var messageBytes = packet.ToBytes();
|
||||
var segment = new ArraySegment<byte>(messageBytes);
|
||||
|
||||
var signalingMessage = packet.GetData<SignalingMessage>();
|
||||
var targetAccountId = signalingMessage?.To;
|
||||
|
||||
foreach (var pair in roomDict)
|
||||
{
|
||||
if (pair.Key == senderId) continue;
|
||||
// Skip sender unless it's broadcast message
|
||||
if (!string.IsNullOrEmpty(targetAccountId) && pair.Key == senderId) continue;
|
||||
|
||||
// If directed message, only send to target
|
||||
if (!string.IsNullOrEmpty(targetAccountId) && pair.Value.AccountId != targetAccountId) continue;
|
||||
|
||||
if (pair.Value.Socket.State != WebSocketState.Open) continue;
|
||||
await pair.Value.Socket.SendAsync(segment, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
|
Reference in New Issue
Block a user