Table of Contents

Class WebSocketWorker

Namespace
Cryville.EEW
Assembly
Cryville.EEW.dll
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

uri Uri
The initial URI to connect to.

Properties

InitialUri

The initial URI.
protected Uri InitialUri { get; }

Property Value

Uri

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

disposing bool

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

stream Stream
The stream that contains the content of the response.
messageType WebSocketMessageType
The message type.
cancellationToken CancellationToken
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

stream Stream
The stream that contains the content of the response.
cancellationToken CancellationToken
A cancellation token.

Returns

Task
The task.

OnConnected(CancellationToken)

Called when the WebSocket is connected.
protected virtual Task OnConnected(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task
The task.

OnError(Exception)

Called when an error occurs.
protected abstract void OnError(Exception ex)

Parameters

ex Exception
The exception.

OnHeartbeat()

Called when a response is received.
protected abstract void OnHeartbeat()

RunAsync(CancellationToken)

Runs the worker.
public Task RunAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task
The task.

SendAsync(Stream, WebSocketMessageType, CancellationToken)

Sends a message.
protected Task SendAsync(Stream stream, WebSocketMessageType messageType, CancellationToken cancellationToken)

Parameters

stream Stream
The stream that contains the content of the message.
messageType WebSocketMessageType
The message type.
cancellationToken CancellationToken
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

content ReadOnlyMemory<byte>
The message content.
messageType WebSocketMessageType
The message type.
cancellationToken CancellationToken
A cancellation token.

Returns

Task
The task.

Exceptions

InvalidOperationException
The socket is not connected.
ObjectDisposedException
The socket is has been closed.