openvidu-basic-dotnet

This commit is contained in:
pabloFuente 2022-06-24 02:57:27 +02:00
parent ce469bff96
commit 4ae285f8e7
7 changed files with 175 additions and 0 deletions

37
openvidu-basic-dotnet/.gitignore vendored Normal file
View File

@ -0,0 +1,37 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/
# Visual Studio Code
.vscode
# Rider
.idea
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn
# Visual Studio 2015
.vs/

View File

@ -0,0 +1,65 @@
using System.Text;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
// Enable CORS support
builder.Services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
builder =>
{
builder.WithOrigins("*").AllowAnyHeader();
});
});
var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors(MyAllowSpecificOrigins);
IConfiguration config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables().Build();
var OPENVIDU_URL = config.GetValue<string>("OPENVIDU_URL");
var OPENVIDU_SECRET = config.GetValue<string>("OPENVIDU_SECRET");
// Allow for insecure certificate in OpenVidu deployment
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
HttpClient client = new HttpClient(handler);
client.BaseAddress = new System.Uri(OPENVIDU_URL);
// Set OpenVidu deployment secret
var basicAuth = Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes($"OPENVIDUAPP:{OPENVIDU_SECRET}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
app.MapPost("/sessions", async (HttpContext context) =>
{
HttpContent content = new StringContent(context.Request.Body.ToString(), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsJsonAsync("openvidu/api/sessions", content);
if (response.StatusCode == HttpStatusCode.Conflict) {
var json = await context.Request.ReadFromJsonAsync<Dictionary<string, object>>();
return json["customSessionId"];
}
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadFromJsonAsync<Dictionary<string, object>>();
return responseBody["sessionId"];
});
app.MapPost("/sessions/{sessionId}/connections", async ([FromRoute] string sessionId, [FromBody] string json) =>
{
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("openvidu/api/sessions/" + sessionId + "/connections", content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
});
app.Run();

View File

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://localhost:5000",
"sslPort": 5000
}
},
"profiles": {
"openvidu_basic_dotnet": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,13 @@
# openvidu-basic-dotnet
This is a minimal OpenVidu server application sample built for .NET. Visit [Application server](https://docs.openvidu.io/en/stable/application-server/) documentation for further context.
Prerequisites:
- [.NET 6.0](https://dotnet.microsoft.com/en-us/download)
Run the application:
```
dotnet run
```

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"OPENVIDU_URL": "https://localhost:4443/",
"OPENVIDU_SECRET": "MY_SECRET"
}

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>openvidu_basic_dotnet</RootNamespace>
</PropertyGroup>
</Project>