Files
forkmessager/apps/server-net/src/Host/Controllers/WebRtcController.cs
Халимов Рустам 893c9f2316 Очистка мусора
2026-03-15 21:36:49 +03:00

44 lines
1.3 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
namespace Host.Controllers;
[Authorize]
[ApiController]
[Route("api/webrtc")]
public sealed class WebRtcController : ControllerBase
{
private readonly IConfiguration _configuration;
public WebRtcController(IConfiguration configuration)
{
_configuration = configuration;
}
[HttpGet("ice-servers")]
public IActionResult GetIceServers()
{
var turnUrl = _configuration["WebRtc:TurnUrl"];
var turnUsername = _configuration["WebRtc:TurnUsername"];
var turnPassword = _configuration["WebRtc:TurnPassword"];
var iceServers = new List<object>();
if (!string.IsNullOrEmpty(turnUrl) && !string.IsNullOrEmpty(turnUsername) && !string.IsNullOrEmpty(turnPassword))
{
// Use the VPS server as both STUN and TURN
var stunUrl = turnUrl.Replace("turn:", "stun:");
iceServers.Add(new { urls = new[] { stunUrl } });
iceServers.Add(new
{
urls = new[] { turnUrl, turnUrl + "?transport=tcp" },
username = turnUsername,
credential = turnPassword,
});
}
return Ok(new { iceServers });
}
}