Show / Hide Table of Contents

Class ServerSentEventsService

Service which provides operations over Server-Sent Events protocol.

Inheritance
System.Object
ServerSentEventsService
Implements
IServerSentEventsService
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Lib.AspNetCore.ServerSentEvents
Assembly: Lib.AspNetCore.ServerSentEvents.dll
Syntax
public class ServerSentEventsService : IServerSentEventsService

Constructors

ServerSentEventsService(IOptions<ServerSentEventsServiceOptions<ServerSentEventsService>>)

Initializes new instance of ServerSentEventsService.

Declaration
public ServerSentEventsService(IOptions<ServerSentEventsServiceOptions<ServerSentEventsService>> options)
Parameters
Type Name Description
Microsoft.Extensions.Options.IOptions<ServerSentEventsServiceOptions<ServerSentEventsService>> options

The options for the instance.

Properties

ReconnectInterval

Gets the interval after which clients will attempt to reestablish failed connections.

Declaration
public uint? ReconnectInterval { get; }
Property Value
Type Description
System.Nullable<System.UInt32>

Methods

AddToGroup(String, IServerSentEventsClient)

Adds a client to the specified group.

Declaration
public ServerSentEventsAddToGroupResult AddToGroup(string groupName, IServerSentEventsClient client)
Parameters
Type Name Description
System.String groupName

The group name.

IServerSentEventsClient client

The client to add to a group.

Returns
Type Description
ServerSentEventsAddToGroupResult

The task object representing the result of asynchronous operation

ChangeReconnectIntervalAsync(UInt32)

Changes the interval after which clients will attempt to reestablish failed connections.

Declaration
public Task ChangeReconnectIntervalAsync(uint reconnectInterval)
Parameters
Type Name Description
System.UInt32 reconnectInterval

The reconnect interval.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

ChangeReconnectIntervalAsync(UInt32, CancellationToken)

Changes the interval after which clients will attempt to reestablish failed connections.

Declaration
public Task ChangeReconnectIntervalAsync(uint reconnectInterval, CancellationToken cancellationToken)
Parameters
Type Name Description
System.UInt32 reconnectInterval

The reconnect interval.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

GetClient(Guid)

Gets the client based on the unique client identifier.

Declaration
public IServerSentEventsClient GetClient(Guid clientId)
Parameters
Type Name Description
System.Guid clientId

The unique client identifier.

Returns
Type Description
IServerSentEventsClient

The client.

GetClients()

Gets all clients.

Declaration
public IReadOnlyCollection<IServerSentEventsClient> GetClients()
Returns
Type Description
System.Collections.Generic.IReadOnlyCollection<IServerSentEventsClient>

The clients.

GetClients(String)

Gets clients in the specified group.

Declaration
public IReadOnlyCollection<IServerSentEventsClient> GetClients(string groupName)
Parameters
Type Name Description
System.String groupName

The group name.

Returns
Type Description
System.Collections.Generic.IReadOnlyCollection<IServerSentEventsClient>

The clients in the specified group.

OnConnectAsync(HttpRequest, IServerSentEventsClient)

Method which is called when client is establishing the connection. The base implementation raises the ClientConnected event.

Declaration
public virtual Task OnConnectAsync(HttpRequest request, IServerSentEventsClient client)
Parameters
Type Name Description
Microsoft.AspNetCore.Http.HttpRequest request

The request which has been made in order to establish the connection.

IServerSentEventsClient client

The client who is establishing the connection.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

OnDisconnectAsync(HttpRequest, IServerSentEventsClient)

Method which is called when client is disconnecting. The base implementation raises the ClientDisconnected event.

Declaration
public virtual Task OnDisconnectAsync(HttpRequest request, IServerSentEventsClient client)
Parameters
Type Name Description
Microsoft.AspNetCore.Http.HttpRequest request

The original request which has been made in order to establish the connection.

IServerSentEventsClient client

The client who is disconnecting.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

OnReconnectAsync(HttpRequest, IServerSentEventsClient, String)

Method which is called when client is reestablishing the connection. The base implementation raises the ClientConnected event.

Declaration
public virtual Task OnReconnectAsync(HttpRequest request, IServerSentEventsClient client, string lastEventId)
Parameters
Type Name Description
Microsoft.AspNetCore.Http.HttpRequest request

The request which has been made in order to establish the connection.

IServerSentEventsClient client

The client who is reestablishing the connection.

System.String lastEventId

The identifier of last event which client has received.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(ServerSentEvent)

Sends event to all clients.

Declaration
public Task SendEventAsync(ServerSentEvent serverSentEvent)
Parameters
Type Name Description
ServerSentEvent serverSentEvent

The event.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(ServerSentEvent, Func<IServerSentEventsClient, Boolean>)

Sends event to all clients.

Declaration
public Task SendEventAsync(ServerSentEvent serverSentEvent, Func<IServerSentEventsClient, bool> clientPredicate)
Parameters
Type Name Description
ServerSentEvent serverSentEvent

The event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(ServerSentEvent, Func<IServerSentEventsClient, Boolean>, CancellationToken)

Sends event to all clients.

Declaration
public Task SendEventAsync(ServerSentEvent serverSentEvent, Func<IServerSentEventsClient, bool> clientPredicate, CancellationToken cancellationToken)
Parameters
Type Name Description
ServerSentEvent serverSentEvent

The event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(ServerSentEvent, CancellationToken)

Sends event to all clients.

Declaration
public Task SendEventAsync(ServerSentEvent serverSentEvent, CancellationToken cancellationToken)
Parameters
Type Name Description
ServerSentEvent serverSentEvent

The event.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String)

Sends event to all clients.

Declaration
public Task SendEventAsync(string text)
Parameters
Type Name Description
System.String text

The simple text event.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, ServerSentEvent)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, ServerSentEvent serverSentEvent)
Parameters
Type Name Description
System.String groupName

The group name.

ServerSentEvent serverSentEvent

The event.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, ServerSentEvent, Func<IServerSentEventsClient, Boolean>)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, ServerSentEvent serverSentEvent, Func<IServerSentEventsClient, bool> clientPredicate)
Parameters
Type Name Description
System.String groupName

The group name.

ServerSentEvent serverSentEvent

The event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, ServerSentEvent, Func<IServerSentEventsClient, Boolean>, CancellationToken)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, ServerSentEvent serverSentEvent, Func<IServerSentEventsClient, bool> clientPredicate, CancellationToken cancellationToken)
Parameters
Type Name Description
System.String groupName

The group name.

ServerSentEvent serverSentEvent

The event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, ServerSentEvent, CancellationToken)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, ServerSentEvent serverSentEvent, CancellationToken cancellationToken)
Parameters
Type Name Description
System.String groupName

The group name.

ServerSentEvent serverSentEvent

The event.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, Func<IServerSentEventsClient, Boolean>)

Sends event to all clients.

Declaration
public Task SendEventAsync(string text, Func<IServerSentEventsClient, bool> clientPredicate)
Parameters
Type Name Description
System.String text

The simple text event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, Func<IServerSentEventsClient, Boolean>, CancellationToken)

Sends event to all clients.

Declaration
public Task SendEventAsync(string text, Func<IServerSentEventsClient, bool> clientPredicate, CancellationToken cancellationToken)
Parameters
Type Name Description
System.String text

The simple text event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, String)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, string text)
Parameters
Type Name Description
System.String groupName

The group name.

System.String text

The simple text event.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, String, Func<IServerSentEventsClient, Boolean>)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, string text, Func<IServerSentEventsClient, bool> clientPredicate)
Parameters
Type Name Description
System.String groupName

The group name.

System.String text

The simple text event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, String, Func<IServerSentEventsClient, Boolean>, CancellationToken)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, string text, Func<IServerSentEventsClient, bool> clientPredicate, CancellationToken cancellationToken)
Parameters
Type Name Description
System.String groupName

The group name.

System.String text

The simple text event.

System.Func<IServerSentEventsClient, System.Boolean> clientPredicate

The function to test each client for a condition.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, String, CancellationToken)

Sends event to clients in group.

Declaration
public Task SendEventAsync(string groupName, string text, CancellationToken cancellationToken)
Parameters
Type Name Description
System.String groupName

The group name.

System.String text

The simple text event.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

SendEventAsync(String, CancellationToken)

Sends event to all clients.

Declaration
public Task SendEventAsync(string text, CancellationToken cancellationToken)
Parameters
Type Name Description
System.String text

The simple text event.

System.Threading.CancellationToken cancellationToken

The cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

Events

ClientConnected

Occurs when client has connected.

Declaration
public event EventHandler<ServerSentEventsClientConnectedArgs> ClientConnected
Event Type
Type Description
System.EventHandler<ServerSentEventsClientConnectedArgs>

ClientDisconnected

Occurs when client has disconnected.

Declaration
public event EventHandler<ServerSentEventsClientDisconnectedArgs> ClientDisconnected
Event Type
Type Description
System.EventHandler<ServerSentEventsClientDisconnectedArgs>

Implements

IServerSentEventsService
Back to top Copyright © 2017 - 2023 Tomasz Pęczek