openvidu-basic-dotnet
This commit is contained in:
parent
ce469bff96
commit
4ae285f8e7
37
openvidu-basic-dotnet/.gitignore
vendored
Normal file
37
openvidu-basic-dotnet/.gitignore
vendored
Normal 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/
|
||||
65
openvidu-basic-dotnet/Program.cs
Normal file
65
openvidu-basic-dotnet/Program.cs
Normal 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();
|
||||
31
openvidu-basic-dotnet/Properties/launchSettings.json
Normal file
31
openvidu-basic-dotnet/Properties/launchSettings.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
openvidu-basic-dotnet/README.md
Normal file
13
openvidu-basic-dotnet/README.md
Normal 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
|
||||
```
|
||||
8
openvidu-basic-dotnet/appsettings.Development.json
Normal file
8
openvidu-basic-dotnet/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
11
openvidu-basic-dotnet/appsettings.json
Normal file
11
openvidu-basic-dotnet/appsettings.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"OPENVIDU_URL": "https://localhost:4443/",
|
||||
"OPENVIDU_SECRET": "MY_SECRET"
|
||||
}
|
||||
10
openvidu-basic-dotnet/openvidu-basic-dotnet.csproj
Normal file
10
openvidu-basic-dotnet/openvidu-basic-dotnet.csproj
Normal 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>
|
||||
Loading…
x
Reference in New Issue
Block a user