Skip to content

Commit 2f41ab5

Browse files
committed
Added helper methods, convenience WaitForEvent methods and common filter settings types
1 parent 87df74f commit 2f41ab5

10 files changed

Lines changed: 1827 additions & 17 deletions

File tree

ObsWebSocket.Core/Networking/IWebSocketConnection .cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,93 @@ namespace ObsWebSocket.Core.Networking;
88
/// </summary>
99
public interface IWebSocketConnection : IDisposable
1010
{
11+
/// <summary>
12+
/// Gets the current state of the WebSocket connection.
13+
/// </summary>
1114
WebSocketState State { get; }
15+
16+
/// <summary>
17+
/// Gets the current close status of the WebSocket connection, if available.
18+
/// </summary>
1219
WebSocketCloseStatus? CloseStatus { get; }
20+
21+
/// <summary>
22+
/// Gets the close status description of the WebSocket connection, if available.
23+
/// </summary>
1324
string? CloseStatusDescription { get; }
25+
26+
/// <summary>
27+
/// Gets the Subprotocol used for the WebSocket connection.
28+
/// </summary>
1429
string? SubProtocol { get; }
30+
31+
/// <summary>
32+
/// Gets the options used to configure the WebSocket connection.
33+
/// </summary>
1534
ClientWebSocketOptions Options { get; }
1635

36+
/// <summary>
37+
/// Connects to the WebSocket server using the specified URI.
38+
/// </summary>
39+
/// <param name="uri"></param>
40+
/// <param name="cancellationToken"></param>
41+
/// <returns></returns>
1742
Task ConnectAsync(Uri uri, CancellationToken cancellationToken);
43+
44+
/// <summary>
45+
/// Sends a message to the WebSocket connection.
46+
/// </summary>
47+
/// <param name="buffer"></param>
48+
/// <param name="messageType"></param>
49+
/// <param name="endOfMessage"></param>
50+
/// <param name="cancellationToken"></param>
51+
/// <returns></returns>
1852
ValueTask SendAsync(
1953
ReadOnlyMemory<byte> buffer,
2054
WebSocketMessageType messageType,
2155
bool endOfMessage,
2256
CancellationToken cancellationToken
2357
);
58+
59+
/// <summary>
60+
/// Receives a message from the WebSocket connection and returns the result.
61+
/// </summary>
62+
/// <param name="buffer"></param>
63+
/// <param name="cancellationToken"></param>
64+
/// <returns></returns>
2465
ValueTask<ValueWebSocketReceiveResult> ReceiveAsync(
2566
Memory<byte> buffer,
2667
CancellationToken cancellationToken
2768
);
69+
70+
/// <summary>
71+
/// Closes the WebSocket connection and sends a close frame to the server.
72+
/// </summary>
73+
/// <param name="closeStatus"></param>
74+
/// <param name="statusDescription"></param>
75+
/// <param name="cancellationToken"></param>
76+
/// <returns></returns>
2877
Task CloseAsync(
2978
WebSocketCloseStatus closeStatus,
3079
string? statusDescription,
3180
CancellationToken cancellationToken
3281
);
82+
83+
/// <summary>
84+
/// Closes the output stream of the WebSocket connection without closing the connection itself.
85+
/// </summary>
86+
/// <param name="closeStatus"></param>
87+
/// <param name="statusDescription"></param>
88+
/// <param name="cancellationToken"></param>
89+
/// <returns></returns>
3390
Task CloseOutputAsync(
3491
WebSocketCloseStatus closeStatus,
3592
string? statusDescription,
3693
CancellationToken cancellationToken
3794
);
95+
96+
/// <summary>
97+
/// Aborts the WebSocket connection without sending a close frame.
98+
/// </summary>
3899
void Abort();
39100
}

ObsWebSocket.Core/ObsWebSocket.Core.csproj

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2929
</PropertyGroup>
3030
<ItemGroup>
31-
<PackageReference
32-
Include="Microsoft.Extensions.DependencyInjection.Abstractions"
33-
Version="9.0.4"
34-
/>
31+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.4" />
3532
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.4" />
3633
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
3734
<PackageReference Include="MessagePack" Version="3.1.3" />
@@ -49,11 +46,7 @@
4946
<AdditionalFiles Include="..\protocol.json" Link="protocol.json" />
5047
</ItemGroup>
5148
<ItemGroup>
52-
<ProjectReference
53-
Include="..\ObsWebSocket.SourceGenerators\ObsWebSocket.SourceGenerators.csproj"
54-
OutputItemType="Analyzer"
55-
ReferenceOutputAssembly="false"
56-
/>
49+
<ProjectReference Include="..\ObsWebSocket.SourceGenerators\ObsWebSocket.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
5750
</ItemGroup>
5851
<ItemGroup>
5952
<None Include="..\LICENSE.txt" Pack="true" PackagePath="" />

0 commit comments

Comments
 (0)