Giter VIP home page Giter VIP logo

signalr's Introduction

Build Package Version NuGet Downloads License

DEPRECATION NOTE: This package is no longer required since Blazor WebAssembly now supports SignalR Client. Users of this package should stop using it and use the official client instead.

Blazor Extensions

Blazor Extensions is a set of packages with the goal of adding useful features to Blazor.

Blazor Extensions SignalR

This package adds a Microsoft ASP.NET Core SignalR client library for Microsoft ASP.NET Blazor.

The package aims to mimic the C# APIs of SignalR Client as much as possible and it is developed by wrapping the TypeScript client by using Blazor's interop capabilities.

For more information about SignalR development, please check SignalR documentation.

Features

This package implements all public features of SignalR Typescript client.

Note: The Streaming APIs are not implemented yet. We will add it soon.

Sample usage

The following snippet shows how to setup the client to send and receive messages using SignalR.

The HubConnectionBuilder needs to get injected, which must be registered:

// in Startup.cs, ConfigureServices()
   services.AddTransient<HubConnectionBuilder>();
// in Component class
[Inject]
private HubConnectionBuilder _hubConnectionBuilder { get; set; }
// in Component Initialization code
var connection = _hubConnectionBuilder // the injected one from above.
        .WithUrl("/myHub", // The hub URL. If the Hub is hosted on the server where the blazor is hosted, you can just use the relative path.
        opt =>
        {
            opt.LogLevel = SignalRLogLevel.Trace; // Client log level
            opt.Transport = HttpTransportType.WebSockets; // Which transport you want to use for this connection
        })
        .Build(); // Build the HubConnection

connection.On("Receive", this.Handle); // Subscribe to messages sent from the Hub to the "Receive" method by passing a handle (Func<object, Task>) to process messages.
await connection.StartAsync(); // Start the connection.

await connection.InvokeAsync("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod" and pass parameters to it. 

var result = await connection.InvokeAsync<MyResult>("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod", pass parameters to it and get the result back.

Contributions and feedback

Please feel free to use the component, open issues, fix bugs or provide feedback.

Contributors

The following people are the maintainers of the Blazor Extensions projects:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.