Refactor appsettings
This commit is contained in:
@@ -4,6 +4,4 @@ public class PlayFabSettings
|
||||
{
|
||||
public string PublisherId { get; set; }
|
||||
public string TitleId { get; set; }
|
||||
public string SignalRURL { get; set; }
|
||||
public string SignalRAccessToken { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Prospect.Server.Api.Config;
|
||||
|
||||
public class SignalRSettings
|
||||
{
|
||||
public string SignalRURL { get; set; }
|
||||
public string SignalRAccessToken { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Prospect.Server.Api.Config;
|
||||
|
||||
public class VivoxConfig
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Issuer { get; set; }
|
||||
public string Domain { get; set; }
|
||||
public string Server { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Net.Mime;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Prospect.Server.Api.Hubs;
|
||||
|
||||
namespace Prospect.Server.Api.Controllers;
|
||||
|
||||
public class NotifyRequest
|
||||
{
|
||||
[JsonPropertyName("type")]
|
||||
public string MessageType { get; set; }
|
||||
|
||||
[JsonPropertyName("data")]
|
||||
public object MessageData { get; set; }
|
||||
}
|
||||
|
||||
public class ServerReadyMessageData
|
||||
{
|
||||
[JsonPropertyName("success")]
|
||||
public bool Success { get; set; }
|
||||
[JsonPropertyName("sessionId")]
|
||||
public string SessionID { get; set; }
|
||||
[JsonPropertyName("squadId")]
|
||||
public string SquadID { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[Route("Notifications")]
|
||||
[ApiController]
|
||||
public class NotificationsController : Controller
|
||||
{
|
||||
private readonly IHubContext<CycleHub> _hubContext;
|
||||
private readonly ILogger<NotificationsController> _logger;
|
||||
|
||||
public NotificationsController(ILogger<NotificationsController> logger, IHubContext<CycleHub> hubContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
[HttpPost("TestNotify")]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
public async Task<IActionResult> TestNotify(NotifyRequest request)
|
||||
{
|
||||
// TODO: To test Notifications_DT
|
||||
_logger.LogDebug("Received test notification event {MessageType}", request.MessageType);
|
||||
await _hubContext.Clients.All.SendAsync(request.MessageType, request.MessageData);
|
||||
|
||||
return StatusCode(200);
|
||||
}
|
||||
|
||||
[HttpPost("ServerReady")]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
public async Task<IActionResult> ServerReady(ServerReadyMessageData request)
|
||||
{
|
||||
_logger.LogDebug("Received test notification event OnSquadMatchmakingSuccess");
|
||||
await _hubContext.Clients.All.SendAsync("OnSquadMatchmakingSuccess", request);
|
||||
|
||||
return StatusCode(200);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@ namespace Prospect.Server.Api.Services.CloudScript.Functions;
|
||||
[CloudScriptFunction("GetSignalRConnection")]
|
||||
public class GetSignalRConnection : ICloudScriptFunction<FYGetSignalRConnection, FYGetSignalRConnectionResult>
|
||||
{
|
||||
private readonly PlayFabSettings _settings;
|
||||
private readonly SignalRSettings _settings;
|
||||
|
||||
public GetSignalRConnection(IOptions<PlayFabSettings> settings)
|
||||
public GetSignalRConnection(IOptions<SignalRSettings> settings)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Prospect.Server.Api.Config;
|
||||
using Prospect.Server.Api.Services.CloudScript.Models;
|
||||
|
||||
namespace Prospect.Server.Api.Services.CloudScript.Functions;
|
||||
@@ -27,6 +29,13 @@ public class FYVivoxJoinTokenRequest
|
||||
[CloudScriptFunction("VivoxJoin")]
|
||||
public class VivoxJoin : ICloudScriptFunction<FYVivoxJoinTokenRequest, object>
|
||||
{
|
||||
private readonly VivoxConfig _settings;
|
||||
|
||||
public VivoxJoin(IOptions<VivoxConfig> settings)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
}
|
||||
|
||||
private int ReturnChannelType(string type) {
|
||||
switch (type) {
|
||||
case "GLOBAL": return 2;
|
||||
@@ -41,8 +50,7 @@ public class VivoxJoin : ICloudScriptFunction<FYVivoxJoinTokenRequest, object>
|
||||
public async Task<object> ExecuteAsync(FYVivoxJoinTokenRequest request)
|
||||
{
|
||||
var exp = (int)DateTimeOffset.UtcNow.AddDays(1).ToUnixTimeSeconds();
|
||||
// TODO: Replace with app configuration
|
||||
var token = TokenGenerator.vxGenerateToken("key", "issuer", exp, "join", request.Username, request.Channel);
|
||||
var token = TokenGenerator.vxGenerateToken(_settings.Key, _settings.Issuer, exp, "join", request.Username, request.Channel);
|
||||
|
||||
return new FYVivoxJoinData
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Prospect.Server.Api.Services.CloudScript.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Prospect.Server.Api.Config;
|
||||
using Prospect.Server.Api.Services.CloudScript.Models;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -84,12 +86,18 @@ public class TokenGenerator
|
||||
[CloudScriptFunction("VivoxLogin")]
|
||||
public class VivoxLogin : ICloudScriptFunction<FYVivoxLoginTokenRequest, FYVivoxJoinData>
|
||||
{
|
||||
private readonly VivoxConfig _settings;
|
||||
|
||||
public VivoxLogin(IOptions<VivoxConfig> settings)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
}
|
||||
|
||||
public async Task<FYVivoxJoinData> ExecuteAsync(FYVivoxLoginTokenRequest request)
|
||||
{
|
||||
// TODO: Replace with app configuration
|
||||
var channel = "sip:confctl-g-<issuer>.testchannel@mtu1xp.vivox.com"; // e - echo channel, g - global, p - positional
|
||||
var channel = $"sip:confctl-g-{_settings.Issuer}.testchannel@mtu1xp.vivox.com"; // e - echo channel, g - global, p - positional
|
||||
var exp = (int)DateTimeOffset.UtcNow.AddSeconds(90).ToUnixTimeSeconds();
|
||||
var token = TokenGenerator.vxGenerateToken("key", "issuer", exp, "login", request.Username, channel);
|
||||
var token = TokenGenerator.vxGenerateToken(_settings.Key, _settings.Issuer, exp, "login", request.Username, channel);
|
||||
|
||||
return new FYVivoxJoinData
|
||||
{
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
using Prospect.Server.Api.Services.CloudScript.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Prospect.Server.Api.Config;
|
||||
using Prospect.Server.Api.Services.CloudScript.Models;
|
||||
|
||||
namespace Prospect.Server.Api.Services.CloudScript.Functions;
|
||||
|
||||
[CloudScriptFunction("VivoxSettings")]
|
||||
public class VivoxSettings : ICloudScriptFunction<FYEmptyRequest, FYVivoxSettingsData>
|
||||
{
|
||||
private readonly VivoxConfig _settings;
|
||||
|
||||
public VivoxSettings(IOptions<VivoxConfig> settings)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
}
|
||||
|
||||
public Task<FYVivoxSettingsData> ExecuteAsync(FYEmptyRequest request)
|
||||
{
|
||||
return Task.FromResult(new FYVivoxSettingsData
|
||||
{
|
||||
// TODO: Replace with app configuration
|
||||
// VivoxDomain = "",
|
||||
// VivoxIssuer = "",
|
||||
// VivoxServer = ""
|
||||
VivoxDomain = _settings.Domain,
|
||||
VivoxIssuer = _settings.Issuer,
|
||||
VivoxServer = _settings.Server
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ public class Startup
|
||||
services.Configure<AuthTokenSettings>(Configuration.GetSection(nameof(AuthTokenSettings)));
|
||||
services.Configure<DatabaseSettings>(Configuration.GetSection(nameof(DatabaseSettings)));
|
||||
services.Configure<PlayFabSettings>(Configuration.GetSection(nameof(PlayFabSettings)));
|
||||
services.Configure<VivoxConfig>(Configuration.GetSection(nameof(VivoxConfig)));
|
||||
services.Configure<SignalRSettings>(Configuration.GetSection(nameof(SignalRSettings)));
|
||||
|
||||
services.AddSingleton<AuthTokenService>();
|
||||
services.AddSingleton<UserDataService>();
|
||||
|
||||
@@ -8,16 +8,24 @@
|
||||
},
|
||||
"PlayFabSettings": {
|
||||
"PublisherId": "850902E5B40508ED",
|
||||
"TitleId": "2EA46",
|
||||
"TitleId": "2EA46"
|
||||
},
|
||||
"SignalRSettings": {
|
||||
"SignalRURL": "https://127.0.0.1:8443/signalr/?hub=pubsub",
|
||||
"SignalRAccessToken": "TEST"
|
||||
},
|
||||
"VivoxConfig": {
|
||||
"Key": "",
|
||||
"Issuer": "",
|
||||
"Domain": "",
|
||||
"Server": ""
|
||||
},
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Https": {
|
||||
"Url": "https://127.0.0.1:8443"
|
||||
},
|
||||
"Http": {
|
||||
"Http": {
|
||||
"Url": "http://127.0.0.1:8000"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user