Spaces:
Running
Running
Commit ·
c65f7a2
1
Parent(s): 35321eb
feat(sync): secure WebRTC endpoints with board authorization check
Browse files15 unmodified lines161718192021221 unmodified line242526262728293031323318 unmodified lines5253545355565758596061626364656621 unmodified lines8889908591929394959697989910010110221 unmodified lines12412512611712712812913013113213313413513613713817 unmodified lines15615715814515916016116216316416516616716816917015 unmodified lines public class SyncController : ControllerBase { private readonly ISyncService _syncService; private readonly IGraphService _graphService;
// In-memory store for WebRTC: ProjectId -> List of signals private static readonly ConcurrentDictionary<string, ConcurrentQueue<WebRTCSignal>> Signals = new();1 unmodified line // In-memory store for WebRTC: ProjectId -> (UserId -> Presence Info) private static readonly ConcurrentDictionary<string, ConcurrentDictionary<string, WebRTCPresence>> Presence = new();
public SyncController(ISyncService syncService) public SyncController(ISyncService syncService, IGraphService graphService) { _syncService = syncService; _graphService = graphService; }
private Guid CurrentUserId18 unmodified lines // --- WebRTC Real-time Presence --- [Authorize] [HttpPost("{projectId}/presence")] public IActionResult RegisterPresence(string projectId) public async Task<IActionResult> RegisterPresence(string projectId) { var userId = CurrentUserId; if (userId == Guid.Empty) return Unauthorized();
if (!Guid.TryParse(projectId, out var graphId)) return BadRequest("Invalid project ID"); var graph = await _graphService.GetByIdAsync(graphId, userId); if (graph is null) return Forbid();
var projectPresence = Presence.GetOrAdd(projectId, _ => new ConcurrentDictionary<string, WebRTCPresence>()); var info = new WebRTCPresence21 unmodified lines
[Authorize] [HttpGet("{projectId}/presence")] public IActionResult GetPresence(string projectId) public async Task<IActionResult> GetPresence(string projectId) { var userId = CurrentUserId; if (userId == Guid.Empty) return Unauthorized();
if (!Guid.TryParse(projectId, out var graphId)) return BadRequest("Invalid project ID"); var graph = await _graphService.GetByIdAsync(graphId, userId); if (graph is null) return Forbid();
if (!Presence.TryGetValue(projectId, out var projectPresence)) { return Ok(Array.Empty<WebRTCPresence>());21 unmodified lines // --- WebRTC Real-time Signaling --- [Authorize] [HttpPost("{projectId}/signal")] public IActionResult SendSignal(string projectId, [FromBody] WebRTCSignalDto dto) public async Task<IActionResult> SendSignal(string projectId, [FromBody] WebRTCSignalDto dto) { var userId = CurrentUserId; if (userId == Guid.Empty) return Unauthorized();
if (!Guid.TryParse(projectId, out var graphId)) return BadRequest("Invalid project ID"); var graph = await _graphService.GetByIdAsync(graphId, userId); if (graph is null) return Forbid();
var message = new WebRTCSignal { SenderId = userId.ToString(),17 unmodified lines
[Authorize] [HttpGet("{projectId}/signal")] public IActionResult GetSignals(string projectId) public async Task<IActionResult> GetSignals(string projectId) { var userId = CurrentUserId; if (userId == Guid.Empty) return Unauthorized();
if (!Guid.TryParse(projectId, out var graphId)) return BadRequest("Invalid project ID"); var graph = await _graphService.GetByIdAsync(graphId, userId); if (graph is null) return Forbid();
var queue = Signals.GetOrAdd(projectId, _ => new ConcurrentQueue<WebRTCSignal>()); var mySignals = new List<WebRTCSignal>();FlowAPI/Controllers/SyncController.cs+23-5