-
-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathIWebSocketClient.cs
More file actions
49 lines (44 loc) · 2.21 KB
/
IWebSocketClient.cs
File metadata and controls
49 lines (44 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Parse.Abstractions.Infrastructure.Execution;
/// <summary>
/// Represents an interface for a WebSocket client to handle WebSocket connections and communications.
/// </summary>
public interface IWebSocketClient
{
/// <summary>
/// An event that is triggered when a message is received via the WebSocket connection.
/// </summary>
/// <remarks>
/// The event handler receives the message as a string parameter. This can be used to process incoming
/// WebSocket messages, such as notifications, commands, or data updates.
/// </remarks>
public event EventHandler<string> MessageReceived;
/// <summary>
/// Establishes a WebSocket connection to the specified server URI.
/// </summary>
/// <param name="serverUri">The URI of the WebSocket server to connect to.</param>
/// <param name="cancellationToken">
/// A token to observe cancellation requests. The operation will stop if the token is canceled.
/// </param>
/// <returns>A task that represents the asynchronous operation of opening the WebSocket connection.</returns>
public Task OpenAsync(string serverUri, CancellationToken cancellationToken = default);
/// <summary>
/// Closes the active WebSocket connection asynchronously.
/// </summary>
/// <param name="cancellationToken">
/// A token to observe cancellation requests. The operation will stop if the token is canceled.
/// </param>
/// <returns>A task that represents the asynchronous operation of closing the WebSocket connection.</returns>
public Task CloseAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Sends a message over the established WebSocket connection asynchronously.
/// </summary>
/// <param name="message">The message to send through the WebSocket connection.</param>
/// <param name="cancellationToken">
/// A token to observe cancellation requests. The operation will stop if the token is canceled.
/// </param>
/// <returns>A task that represents the asynchronous operation of sending the message.</returns>
public Task SendAsync(string message, CancellationToken cancellationToken);
}