All Projects → Lupusa87 → BlazorWebSocketHelper

Lupusa87 / BlazorWebSocketHelper

Licence: other
All Blazor Demos

Programming Languages

C#
18002 projects
javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to BlazorWebSocketHelper

Amazing-Favorites
Amazing Favorites is a browser extension to help you to manage you bookmarks efficiently.
Stars: ✭ 48 (+54.84%)
Mutual labels:  blazor
MudBlazor
Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
Stars: ✭ 4,539 (+14541.94%)
Mutual labels:  blazor
timewarp-templates
A distributed application template for dotnet. Utilizing Blazor, Web API, gRPC, Tye, YARP etc.
Stars: ✭ 37 (+19.35%)
Mutual labels:  blazor
TabBlazor
Blazor admin template based on Tabler UI
Stars: ✭ 222 (+616.13%)
Mutual labels:  blazor
XAF Security E4908
This repository contains examples for Role-based Access Control, Permission Management, and OData / Web / REST API Services for Entity Framework and XPO ORM
Stars: ✭ 47 (+51.61%)
Mutual labels:  blazor
blazor-validation
Validation extensions for Microsoft Blazor / FluentValidation
Stars: ✭ 142 (+358.06%)
Mutual labels:  blazor
blazorators
This project converts TypeScript type declarations into C# representations, and use C# source generators to expose automatic JavaScript interop functionality.
Stars: ✭ 225 (+625.81%)
Mutual labels:  blazor
Blazor-CRUD-With-CloudFirestore
Single Page Application (SPA) using Blazor with the help of Google Cloud Firestore as Database provider
Stars: ✭ 34 (+9.68%)
Mutual labels:  blazor
Fun.Blazor
Powered by .NET blazor!!! ❤ F#
Stars: ✭ 107 (+245.16%)
Mutual labels:  blazor
NodaTimePicker
A Date/Time picker component library for Blazor using NodaTime
Stars: ✭ 49 (+58.06%)
Mutual labels:  blazor
BlazorVirtualScrolling
Blazor components for efficiently rendering large lists and data using virtual scrolling
Stars: ✭ 56 (+80.65%)
Mutual labels:  blazor
BlazorTimeline
Responsive, vertical timeline component.
Stars: ✭ 56 (+80.65%)
Mutual labels:  blazor
Blazor.PersianDatePicker
A free JavaScript Jalali (Persian) and Gregorian (Miladi) dual datepicker library for Blazor applications
Stars: ✭ 40 (+29.03%)
Mutual labels:  blazor
MvvmBlazor
A lightweight Blazor Mvvm Library
Stars: ✭ 203 (+554.84%)
Mutual labels:  blazor
BlazorSimpleSurvey
Blazor Simple Survey
Stars: ✭ 39 (+25.81%)
Mutual labels:  blazor
BethanysPieShopHR
Server-side Blazor project
Stars: ✭ 45 (+45.16%)
Mutual labels:  blazor
BlazoredLocalStorage
This library has been moved to the Blazored org
Stars: ✭ 26 (-16.13%)
Mutual labels:  blazor
blazor-dom-confetti
Celebrate success with dom confetti on Blazor projects!
Stars: ✭ 16 (-48.39%)
Mutual labels:  blazor
Fritz.HatCollection
A static website that displays a collection of Fritz's Hats
Stars: ✭ 21 (-32.26%)
Mutual labels:  blazor
BlazorSvgHelper
All Blazor Demos
Stars: ✭ 36 (+16.13%)
Mutual labels:  blazor

Blazor WebSocket Helper

If you like my blazor works and want to see more open sourced repos please support me with paypal donation

Please send email if you consider to hire me.

!!!!!!!!!!!! Readme should be updated because it is relevant to version 1.0.1 !!!!!!!!!!!!

This repo contains Pure WebSocket library for blazor.

Helper is available on nuget

For install use command - Install-Package BlazorWebSocketHelper

After installing package please add bellow script to your index.html

<script src="_content/BlazorWebSocketHelper/BwsJsInterop.js"></script>

You can use websocket in blazor easy and convenient way using this library.

image

Usage sample:

markup:

<div style="margin:5px">
    <button class="btn btn-primary" style="width:120px;margin:5px" onclick="@WsConnect">@Ws_Button</button>
    <span style="margin:5px">URL</span>
    <input bind="@Ws_URL" style="margin:5px;width:250px" />
    <span style="width:120px;margin:5px">status:@Ws_Status</span>
    <button class="btn btn-primary" style="margin:5px" onclick="@WsGetStatus">Get status</button>
</div>
<br />
<div style="margin:5px">
    <input style="margin:5px;width:250px" bind="@Ws_Message" />
    <button class="btn btn-primary" style="margin:5px" onclick="@WsSendMessage">Send</button>
</div>
<br />
<span style="margin:5px">Log:</span>
<br />
@foreach (var item in WebSocketHelper1.Log)
{
    <br />
    <CompMessage bwsMessage="@item" parent="@this" />
    <br />

}

code:

  public string Ws_URL = "wss://echo.websocket.org";
  protected WebSocketHelper WebSocketHelper1;
  
  public void WsConnect()
  {
    WebSocketHelper1 = new WebSocketHelper(Ws_URL);

    WebSocketHelper1.OnStateChange = WsOnStateChange;
    WebSocketHelper1.OnMessage = WsOnMessage;
    WebSocketHelper1.OnError = WsOnError;
  }
  public void WsOnStateChange(short par_state)
  {
    Ws_Status = WebSocketHelper1.bwsState.ToString();
    StateHasChanged();
  }
  public void WsOnError(string par_error)
  {
    BwsJsInterop.Alert(par_error);
  }
  public void WsOnMessage(string par_message)
  {
    StateHasChanged();
  }
  public void WsSendMessage()
  {
      if (WebSocketHelper1.bwsState == BwsEnums.BwsState.Open)
      {
          if (!string.IsNullOrEmpty(Ws_Message))
          {
              WebSocketHelper1.send(Ws_Message);
              Ws_Message = string.Empty;
              StateHasChanged();
          }
          else
          {
              BwsJsInterop.Alert("Please input message");
          }
      }
      else
      {
          BwsJsInterop.Alert("Connection is closed");
      }
  }
  

For example this helper was used here

You can see code here

Any PRs are welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].