Fixed around 140 wrong namings and other refactorings which were marked as warnings

This commit is contained in:
Kwoth
2022-01-08 11:51:41 +01:00
parent a6330119e8
commit 2ce3262d59
109 changed files with 698 additions and 760 deletions

View File

@@ -64,9 +64,7 @@ namespace Ayu.Discord.Voice
}
public int SetControl(OpusCtl ctl, int value)
{
return LibOpus.EncoderCtl(_encoderPtr, ctl, value);
}
=> LibOpus.EncoderCtl(_encoderPtr, ctl, value);
public int Encode(Span<byte> input, byte[] output)
{
@@ -84,9 +82,7 @@ namespace Ayu.Discord.Voice
public void Dispose()
{
LibOpus.DestroyEncoder(_encoderPtr);
}
=> LibOpus.DestroyEncoder(_encoderPtr);
}
public enum OpusCtl

View File

@@ -8,7 +8,6 @@ namespace Ayu.Discord.Voice
{
public sealed class PoopyBufferImmortalized : ISongBuffer
{
private readonly int _frameSize;
private readonly byte[] _buffer;
private readonly byte[] _outputArray;
private CancellationToken _cancellationToken;
@@ -27,7 +26,6 @@ namespace Ayu.Discord.Voice
public PoopyBufferImmortalized(int frameSize)
{
_frameSize = frameSize;
_buffer = ArrayPool<byte>.Shared.Rent(1_000_000);
_outputArray = new byte[frameSize];
@@ -36,9 +34,7 @@ namespace Ayu.Discord.Voice
}
public void Stop()
{
_isStopped = true;
}
=> _isStopped = true;
// this method needs a rewrite
public Task<bool> BufferAsync(ITrackDataSource source, CancellationToken cancellationToken)
@@ -129,9 +125,7 @@ namespace Ayu.Discord.Voice
}
public void Dispose()
{
ArrayPool<byte>.Shared.Return(_buffer);
}
=> ArrayPool<byte>.Shared.Return(_buffer);
public void Reset()
{

View File

@@ -9,7 +9,7 @@ namespace Ayu.Discord.Gateway
{
public class SocketClient : IDisposable
{
private ClientWebSocket? _ws = null;
private ClientWebSocket? _ws;
public event Func<byte[], Task>? PayloadReceived = delegate { return Task.CompletedTask; };
public event Func<string, Task>? WebsocketClosed = delegate { return Task.CompletedTask; };

View File

@@ -163,9 +163,7 @@ namespace Ayu.Discord.Voice
}
public void Dispose()
{
Encoder.Dispose();
}
=> Encoder.Dispose();
}
public enum SendPcmError

View File

@@ -55,7 +55,7 @@ namespace Ayu.Discord.Voice
public uint Timestamp { get; set; }
public string MyIp { get; private set; } = string.Empty;
public ushort MyPort { get; private set; }
private bool shouldResume = false;
private bool _shouldResume;
private readonly CancellationTokenSource _stopCancellationSource;
private readonly CancellationToken _stopCancellationToken;
@@ -123,6 +123,8 @@ namespace Ayu.Discord.Voice
private async Task _ws_PayloadReceived(byte[] arg)
{
var payload = JsonConvert.DeserializeObject<VoicePayload>(Encoding.UTF8.GetString(arg));
if (payload is null)
return;
try
{
//Log.Information("Received payload with opcode {OpCode}", payload.OpCode);
@@ -138,7 +140,7 @@ namespace Ayu.Discord.Voice
case VoiceOpCode.Ready:
var ready = payload.Data.ToObject<VoiceReady>();
await HandleReadyAsync(ready!);
shouldResume = true;
_shouldResume = true;
break;
case VoiceOpCode.Heartbeat:
// sent, not received
@@ -161,7 +163,7 @@ namespace Ayu.Discord.Voice
await HandleHelloAsync(hello!);
break;
case VoiceOpCode.Resumed:
shouldResume = true;
_shouldResume = true;
break;
case VoiceOpCode.ClientDisconnect:
break;
@@ -183,7 +185,7 @@ namespace Ayu.Discord.Voice
hbt?.Change(Timeout.Infinite, Timeout.Infinite);
_heartbeatTimer = null;
if (!_stopCancellationToken.IsCancellationRequested && shouldResume)
if (!_stopCancellationToken.IsCancellationRequested && _shouldResume)
{
_ = _ws.RunAndBlockAsync(_websocketUrl, _stopCancellationToken);
return Task.CompletedTask;
@@ -199,9 +201,7 @@ namespace Ayu.Discord.Voice
}
public void SendRtpData(byte[] rtpData, int length)
{
_udpClient.Send(rtpData, length, _udpEp);
}
=> _udpClient.Send(rtpData, length, _udpEp);
private Task HandleSessionDescription(VoiceSessionDescription sd)
{
@@ -215,7 +215,7 @@ namespace Ayu.Discord.Voice
private Task ResumeAsync()
{
shouldResume = false;
_shouldResume = false;
return SendCommandPayloadAsync(new()
{
OpCode = VoiceOpCode.Resume,
@@ -270,7 +270,7 @@ namespace Ayu.Discord.Voice
await SendHeartbeatAsync();
}, default, data.HeartbeatInterval, data.HeartbeatInterval);
if (shouldResume)
if (_shouldResume)
{
return ResumeAsync();
}
@@ -341,7 +341,7 @@ namespace Ayu.Discord.Voice
public Task StopAsync()
{
Started = false;
shouldResume = false;
_shouldResume = false;
if(!_stopCancellationSource.IsCancellationRequested)
try { _stopCancellationSource.Cancel(); } catch { }
return _ws.CloseAsync("Stopped by the user.");