44 lines
1.3 KiB
C#
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 });
|
|
}
|
|
}
|