Class WebSocketWorker
A source worker that pulls events with WebSocket.
public abstract class WebSocketWorker : IDisposable
- Inheritance
-
WebSocketWorker
- Implements
- Inherited Members
Constructors
WebSocketWorker(Uri)
A source worker that pulls events with WebSocket.
protected WebSocketWorker(Uri uri)
Parameters
uriUri- The initial URI to connect to.
Properties
InitialUri
The initial URI.
protected Uri InitialUri { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
GetUri()
Gets the URI of the next connection.
protected virtual Uri GetUri()
Returns
- Uri
- The URI of the next connection.
Remarks
If not overridden, the request URI is always the initial URI provided in the constructor.
Handle(Stream, WebSocketMessageType, CancellationToken)
Handles a response.
protected virtual Task Handle(Stream stream, WebSocketMessageType messageType, CancellationToken cancellationToken)
Parameters
streamStream- The stream that contains the content of the response.
messageTypeWebSocketMessageType- The message type.
cancellationTokenCancellationToken- A cancellation token.
Returns
- Task
- The task.
Handle(Stream, CancellationToken)
Handles a response.
[Obsolete("Override Handle(Stream, WebSocketMessageType, CancellationToken) instead.")]
protected virtual Task Handle(Stream stream, CancellationToken cancellationToken)
Parameters
streamStream- The stream that contains the content of the response.
cancellationTokenCancellationToken- A cancellation token.
Returns
- Task
- The task.
OnConnected(CancellationToken)
Called when the WebSocket is connected.
protected virtual Task OnConnected(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken- A cancellation token.
Returns
- Task
- The task.
OnError(Exception)
Called when an error occurs.
protected abstract void OnError(Exception ex)
Parameters
exException- The exception.
OnHeartbeat()
Called when a response is received.
protected abstract void OnHeartbeat()
RunAsync(CancellationToken)
Runs the worker.
public Task RunAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken- A cancellation token.
Returns
- Task
- The task.
SendAsync(Stream, WebSocketMessageType, CancellationToken)
Sends a message.
protected Task SendAsync(Stream stream, WebSocketMessageType messageType, CancellationToken cancellationToken)
Parameters
streamStream- The stream that contains the content of the message.
messageTypeWebSocketMessageType- The message type.
cancellationTokenCancellationToken- A cancellation token.
Returns
- Task
- The task.
Remarks
The length of the stream must not change during sending.
Exceptions
- InvalidOperationException
- The socket is not connected.
- ObjectDisposedException
- The socket is has been closed.
SendAsync(ReadOnlyMemory<byte>, WebSocketMessageType, CancellationToken)
Sends a message.
protected Task SendAsync(ReadOnlyMemory<byte> content, WebSocketMessageType messageType, CancellationToken cancellationToken)
Parameters
contentReadOnlyMemory<byte>- The message content.
messageTypeWebSocketMessageType- The message type.
cancellationTokenCancellationToken- A cancellation token.
Returns
- Task
- The task.
Exceptions
- InvalidOperationException
- The socket is not connected.
- ObjectDisposedException
- The socket is has been closed.