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
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
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.
Exceptions
- InvalidOperationException
- The socket is not connected.
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.