Added WebSocket listener service.

This commit is contained in:
real-zony 2022-10-05 10:36:42 +08:00
parent cde1d32d33
commit dbc1e44d2a
7 changed files with 64 additions and 36 deletions

View File

@ -36,7 +36,7 @@ globalOption:
plugin:
- name: NetEase # 基于网易云音乐的歌词下载器。
priority: 1 # 优先级,升序排列,改为 -1 时禁用。
depth: 30 # 搜索深度,值越大搜索结果越多,但搜索时间越长。
depth: 10 # 搜索深度,值越大搜索结果越多,但搜索时间越长。
- name: QQ # 基于 QQ 音乐的歌词下载器。
priority: 2
# depth: 10 # 暂时不支持。

View File

@ -1,25 +1,36 @@
var builder = WebApplication.CreateBuilder(args);
using ZonyLrcTools.LocalServer;
var app = RegisterAndConfigureServices();
await ListenServices();
async Task ListenServices()
{
await new SuperSocketListener().ListenAsync();
await app?.RunAsync()!;
}
WebApplication? RegisterAndConfigureServices()
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapControllers();
return app;
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -1,28 +1,12 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49856",
"sslPort": 44367
}
},
"profiles": {
"ZonyLrcTools.LocalServer": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7015;http://localhost:5265",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:50002",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

View File

@ -0,0 +1,15 @@
using SuperSocket.WebSocket.Server;
namespace ZonyLrcTools.LocalServer;
public class SuperSocketListener
{
public async Task ListenAsync()
{
var host = WebSocketHostBuilder.Create()
.UseWebSocketMessageHandler(async (session, message) => { await session.SendAsync(message.Message); })
.Build();
await host.StartAsync();
}
}

View File

@ -7,6 +7,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SuperSocket.WebSocket" Version="2.0.0-beta.11" />
<PackageReference Include="SuperSocket.WebSocket.Server" Version="2.0.0-beta.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
@ -14,4 +19,8 @@
<Folder Include="Controllers" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj" />
</ItemGroup>
</Project>

View File

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

View File

@ -5,5 +5,14 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"serverOptions": {
"name": "ZonyLRcToolsServer",
"listeners": [
{
"ip": "Any",
"port": 50001
}
]
}
}