diff --git a/src/WebSocket4Net/IWebSocket.cs b/src/WebSocket4Net/IWebSocket.cs new file mode 100644 index 0000000..363d23d --- /dev/null +++ b/src/WebSocket4Net/IWebSocket.cs @@ -0,0 +1,23 @@ +using System; +using System.Buffers; +using System.Threading; +using System.Threading.Tasks; +using SuperSocket.WebSocket; + +namespace WebSocket4Net +{ + public interface IWebSocket + { + ValueTask OpenAsync(CancellationToken cancellationToken = default); + + ValueTask ReceiveAsync(); + + ValueTask SendAsync(string message); + + ValueTask SendAsync(ReadOnlyMemory data); + + ValueTask SendAsync(ref ReadOnlySequence sequence); + + ValueTask CloseAsync(CloseReason closeReason, string message = null); + } +} \ No newline at end of file diff --git a/src/WebSocket4Net/WebSocket.cs b/src/WebSocket4Net/WebSocket.cs index 113fba3..8a383ee 100644 --- a/src/WebSocket4Net/WebSocket.cs +++ b/src/WebSocket4Net/WebSocket.cs @@ -18,7 +18,7 @@ namespace WebSocket4Net { - public class WebSocket : EasyClient + public class WebSocket : EasyClient, IWebSocket { private static readonly Encoding _asciiEncoding = Encoding.ASCII; private static readonly Encoding _utf8Encoding = new UTF8Encoding(false); @@ -294,11 +294,6 @@ public ValueTask SendAsync(ref ReadOnlySequence sequence) return SendAsync(_packageEncoder, package); } - public async ValueTask CloseAsync(CloseReason closeReason) - { - await CloseAsync(closeReason, string.Empty); - } - private byte[] GetBuffer(int size) { return new byte[size]; @@ -309,7 +304,7 @@ public override async ValueTask CloseAsync() await CloseAsync(CloseReason.NormalClosure, string.Empty); } - public async ValueTask CloseAsync(CloseReason closeReason, string message) + public async ValueTask CloseAsync(CloseReason closeReason, string message = null) { var package = new WebSocketPackage();