UiRealTimeCommunicator-develop 1.0.188-pr

This is a prerelease version of UiRealTimeCommunicator-develop.
There is a newer version of this package available.
See the version list below for details.
dotnet add package UiRealTimeCommunicator-develop --version 1.0.188-pr                
NuGet\Install-Package UiRealTimeCommunicator-develop -Version 1.0.188-pr                
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="UiRealTimeCommunicator-develop" Version="1.0.188-pr" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UiRealTimeCommunicator-develop --version 1.0.188-pr                
#r "nuget: UiRealTimeCommunicator-develop, 1.0.188-pr"                
#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 UiRealTimeCommunicator-develop as a Cake Addin
#addin nuget:?package=UiRealTimeCommunicator-develop&version=1.0.188-pr&prerelease

// Install UiRealTimeCommunicator-develop as a Cake Tool
#tool nuget:?package=UiRealTimeCommunicator-develop&version=1.0.188-pr&prerelease                

UiRealTimeCommunicator

UiRealTimeCommunicator is a NuGet library designed to enable seamless strongly-typed message exchange between a C# .NET 8 server-side application and a TypeScript client-side application using SignalR. This library simplifies WebSocket-based communication by providing strict type safety and an intuitive API, making it easy to implement real-time features like live updates, notifications, and interactive communication.

🚀 Features:

  • 🏗 Strongly-typed messages: Enforces compile-time safety and ensures that communication between client and server is consistent.
  • 🧑‍💻 Code generation: Automatically generates TypeScript models and contracts from the server-side code, reducing boilerplate and ensuring synchronization between client and server code.
  • 🔐 Type safety on both sides: Guarantees that the TypeScript client-side code mirrors the server-side contracts, eliminating runtime errors due to mismatched data structures.
  • 📡 WebSocket communication: Uses SignalR to enable fast and reliable real-time communication over WebSockets.
  • 🔄 Automatic serialization/deserialization: Automatically serializes and deserializes messages, allowing developers to focus on business logic rather than manually handling data transformations.
  • ⚙️ Flexible and extensible: Supports various real-time messaging scenarios, including notifications, data streaming, and event-driven architectures.

🛠 Installation:

Server-Side (C# .NET 8)

Install the UiRealTimeCommunicator library via NuGet:

dotnet add package UiRealTimeCommunicator

Additionally, install the CLI tool for generating TypeScript code:

dotnet tool install --global UiRealTimeCommunicator.TypeScriptGenerator
# or update to the latest version
dotnet tool update --global UiRealTimeCommunicator.TypeScriptGenerator
Client-Side (TypeScript)

Once you have generated the TypeScript code, you will be able to use the contract and subscription models in your TypeScript frontend.

💻 Usage Example:

Server-Side (C#)

In your Program.cs, configure and add the UiRealTimeCommunicator to your services:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddUiRealTimeCommunicator(); // Add the service to DI container
...
var app = builder.Build();
app.UseUiRealTimeCommunicator(); // Enable real-time communication in the app pipeline

Define a SignalR Hub for communication:

[UiRtcHub("Weather")] // Declare a SignalR Hub with a specific name (Weather)
public class WeatherHub : IUiRtcHub { }

Define the sender contract for sending messages to the frontend:

public interface WeatherChannelSenderContract: IUiRtcSenderContract<WeatherHub>
{
    // Declare method and data for sending message to frontend
    [UiRtcMethod("WeatherForecast")]
    Task SendWeatherForecast(WeatherForecastModel forecast);
}

In your service, use the sender contract to send messages:

public class WeatherService(IUiRtcSenderService senderService)
{
    public async Task WeatherServiceMethod(WeatherForecastModel model)
    {
        // Send message to frontend with strongly-typed contract
        await senderService.Send<WeatherChannelSenderContract>().SendWeatherForecast(model);
    }
}

Define the handler contract to receive messages from the frontend:

[UiRtcMethod("GetWeatherForecast")]
public class GetWeatherForecastHandler() : IUiRtcHandler<WeatherHub, WeatherForecastRequestModel>
{
    public async Task ConsumeAsync(WeatherForecastRequestModel model)
    {
        // Handle message from frontend
        // Process the incoming request
    }
}

Define your data models and mark them for TypeScript code generation:

[TranspilationSource]
public class WeatherForecastModel
{
    public string City { get; set; }
    public double Temperature { get; set; }
    // Add additional fields
}

[TranspilationSource]
public class WeatherForecastRequestModel
{
    public string City { get; set; }
}

We utilize Tapper for model generation. For more details, visit the Tapper GitHub repository (external link).

Generate TypeScript Code for Client-Side

Use the CLI tool to generate TypeScript models and contracts from your C# project:

# -p Path to the project file (Xxx.csproj)
# -o Output directory and file
dotnet-uirtc -p ".\App-backend\App-backend.csproj" -o ".\app-frontend\src\communication\contract.ts"
Client-Side (TypeScript)

Install SignalR

Install SignalR in your TypeScript project. You can find more details on the SignalR npm page (external link).

npm install @microsoft/signalr
# or
yarn add @microsoft/signalr

In the TypeScript client, initialize the SignalR connection:

import { uiRtc } from "./communication/contract.ts";

await uiRtc.init({
  serverUrl: "http://localhost:5064/", // Your server URL
  activeHubs: "All", // Specify which hubs to subscribe to
});

Send a message from the frontend:

import {
  uiRtcCommunication,
  WeatherForecastRequestModel,
} from "../../communication/contract";

// Call a backend method and send a strongly-typed model
uiRtcCommunication.Weather.GetWeatherForecast({
  city: "Kharkiv",
} as WeatherForecastRequestModel); // Strongly typed

Subscribe to a message and handle the response:

import {
  uiRtcSubscription,
  WeatherForecastResponseModel,
} from "../../communication/contract";

// Listen for messages from the backend
uiRtcSubscription.Weather.WeatherForecast(
  (data: WeatherForecastResponseModel) => {
    // Handle received data
    console.log("Weather data received: ", data);
  }
);

🎯 Why UiRealTimeCommunicator?

  • ✅ Easy setup and integration: Simple installation and configuration for both server and client sides. No complicated setup or dependencies.
  • ✅ Reliable data exchange: Ensures high-quality, real-time data transfer using WebSockets and SignalR with strong type safety.
  • ✅ Fully typed communication: Both client and server-side code are strongly typed, reducing runtime errors and improving developer productivity.
  • ✅ Automatic code generation: The CLI tool automatically generates TypeScript models, ensuring consistency between server and client code and reducing boilerplate.
  • ✅ Scalable architecture: Ideal for building scalable real-time applications such as chat systems, live updates, and notifications.
  • ✅ Reduces boilerplate code: The framework abstracts away many manual tasks like serialization, deserialization, and message routing, allowing developers to focus on core functionality.

Start building real-time applications today! The library ensures a seamless and type-safe communication layer for your .NET and TypeScript applications.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows 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
1.0.20250216.2 83 2/16/2025
1.0.20250215.2 81 2/15/2025
1.0.20250213.2 106 2/13/2025
1.0.20250212.2 90 2/12/2025
1.0.20250209.23 90 2/9/2025
1.0.20250209.21 93 2/9/2025
1.0.20250209.6 89 2/9/2025
1.0.20250209.4 79 2/9/2025
1.0.20250208.11 86 2/8/2025
1.0.20250208.10 83 2/8/2025
1.0.20250208.8 88 2/8/2025
1.0.20250208.7 86 2/8/2025
1.0.20250208.6 84 2/8/2025
1.0.20250208.5 89 2/8/2025
1.0.20250208.4 80 2/8/2025
1.0.20250208.3 92 2/8/2025
1.0.20250201.3 90 2/1/2025
1.0.20250131.6 93 1/31/2025
1.0.203-pr 77 2/16/2025
1.0.200-pr 80 2/15/2025
1.0.197-pr 82 2/13/2025
1.0.194-pr 80 2/12/2025
1.0.191-pr 84 2/9/2025
1.0.189-pr 73 2/9/2025
1.0.188-pr 81 2/9/2025
1.0.187-pr 75 2/9/2025
1.0.186-pr 76 2/9/2025
1.0.185-pr 74 2/9/2025
1.0.184-pr 83 2/9/2025
1.0.179-pr 84 2/9/2025
1.0.177-pr 76 2/9/2025
1.0.176-pr 81 2/9/2025
1.0.174-pr 72 2/9/2025
1.0.172-pr 79 2/9/2025
1.0.149 84 2/1/2025
1.0.148 83 1/31/2025
1.0.147 87 1/31/2025
1.0.145 91 1/31/2025