Code2.Web.SseTyped 0.1.19

dotnet add package Code2.Web.SseTyped --version 0.1.19                
NuGet\Install-Package Code2.Web.SseTyped -Version 0.1.19                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Code2.Web.SseTyped" Version="0.1.19" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Code2.Web.SseTyped --version 0.1.19                
#r "nuget: Code2.Web.SseTyped, 0.1.19"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Code2.Web.SseTyped as a Cake Addin
#addin nuget:?package=Code2.Web.SseTyped&version=0.1.19

// Install Code2.Web.SseTyped as a Cake Tool
#tool nuget:?package=Code2.Web.SseTyped&version=0.1.19                

Code2.Web.SseTyped

AspNet server sent events tools to emit message types mapped to the request path

Options

RootPath, (optional) Root path for sse request, default: "/sse"
AllowedTypeNames, (optional) Array of allowed type names to filter

Sample app

Sample chat app is available at https://github.com/2code-it/Web1.Sse.Chat
(webApi server with vue/vite client)

Client identification

Clients can be identified with the url opening the EventSource using a querystring, all query items are added as a connection property which can be used to filter target connections when sending a message.

user 1 uses url: /sse/Message?userId=1&groupId=1
user 2 uses url: /sse/Message?userId=2&groupId=1

both users can be reached using

sseService.Send(message);
//or
sseService.Send(message, p => p["groupId"]=="1");

user 1 only

sseService.Send(message, p => p["userId"]=="1");

Example setup

using Code2.Web.SseTyped;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddCors();
builder.Services.AddSseTyped();

var app = builder.Build();

app.UseCors(o => o.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
app.UseSseTyped();

ISseService sseService = app.Services.GetRequiredService<ISseService>();
Task.Run(() => SendMessage(sseService, 10)).Wait(0);

app.Run();

async void SendMessage(ISseService sseService, int amount)
{
	Message message = new Message { Text = "The message" };
	await sseService.Send(message);
	await Task.Delay(1000);
	if (amount > 0)
	{
		SendMessage(sseService, amount - 1);
	}
}

public class Message
{
	public string? Text { get; set; }
}

Example client

<html>
<body>
<script>
	const eventSource = new EventSource("http://localhost:1099/sse/Message");
	eventSource.onmessage = (e) => {
		const message = JSON.parse(e.data);
		console.log(message);
	}
</script>
</body>
</html>
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.19 147 3/30/2024