Skip to content

Commit

Permalink
兼容wss
Browse files Browse the repository at this point in the history
  • Loading branch information
NepPure committed Jan 15, 2024
1 parent 176afee commit 3cb5bb3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Lagrange.OneBot/Core/Network/Service/ReverseWSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class ReverseWSService(IOptionsSnapshot<ReverseWSServiceOptions>
: BackgroundService, ILagrangeWebService
{
protected const string Tag = nameof(ReverseWSService);

public event EventHandler<MsgRecvEventArgs>? OnMessageReceived;

protected readonly ReverseWSServiceOptions _options = options.Value;
Expand Down Expand Up @@ -42,7 +42,7 @@ public ValueTask SendJsonAsync<T>(T payload, string? identifier, CancellationTok
{
var connCtx = _connCtx ?? throw new InvalidOperationException("Reverse webSocket service was not running");
var connTask = connCtx.ConnectTask;

return !connTask.IsCompletedSuccessfully
? SendJsonAsync(connCtx.WebSocket, connTask, payload, connCtx.Token)
: SendJsonAsync(connCtx.WebSocket, payload, connCtx.Token);
Expand Down Expand Up @@ -76,12 +76,16 @@ protected ClientWebSocket CreateDefaultWebSocket()
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
string urlstr = $"{_options.Host}:{_options.Port}{_options.Suffix}";
if (!_options.Host.StartsWith("ws://") && !_options.Host.StartsWith("wss://"))
{
urlstr = "ws://" + urlstr;
}
if (!Uri.TryCreate(urlstr, UriKind.Absolute, out var url))
{
Log.LogInvalidUrl(_logger, Tag, urlstr);
return;
}

while (true)
{
try
Expand Down

0 comments on commit 3cb5bb3

Please sign in to comment.