Skip to content

Latest commit

 

History

History
72 lines (37 loc) · 2.78 KB

SignarlRSample.md

File metadata and controls

72 lines (37 loc) · 2.78 KB

Notes and codes using SignalR building a CHATBOT ** Some important notes:** This example is based on the ASP.NET SignalR and not on the ASP.NET Core SignalR

Internet Explorer support ASP.NET Core SignalR doesn't support Microsoft Internet Explorer, whereas ASP.NET SignalR supports Microsoft Internet Explorer 8 or later. For more information, see ASP.NET Core SignalR supported platforms.

What is SignalR? ASP.NET Core SignalR is an open-source library that simplifies adding real-time web functionality to apps. Real-time web functionality enables server-side code to push content to clients instantly.

References Video: https://www.linkedin.com/learning/learning-signalr-with-asp-dot-net-core/add-a-signalr-hub?resume=false&u=89213594 https://learn.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-8.0

Good Candidates for SignalR:

  • Apps that require high frequency updates from the server. Examples are gaming, social networks, voting, auction, maps and GPS apps.
  • Dashboards and monitoring apps. Examples include company dashboards, instat sales updates, or travel alerts.
  • Collaborative apps. Whiteboard apps and team meeting software are examplesof collaborative apps.
  • Apps that require notifications. Social networks, email, chat, games, travel alerts, and many other apps use notifications.

SignalR uses hubs to communicate between clients and servers. image

IT'S IMPORTANT TO PLACE THE SIGNALR MIDDLEWARE AFTER HTTPS AND YOUR AUTHORIZATIONS SEE PICTURE BELOW image

NOTE: SIGNALR is usually ** implemented is to include them as part of your project(NUGET) not as CDN**

Example code: When loading your chatbox you can prompt the DISPLAY msg using the OnConnectedAsync image

Codes that loops the chatbox to reconnect after 5secs after being disconnected image

On SIGNARLR browsers usually block javascript so it won't be able to conncet to your api Example: https//api.example.com/chatHub -- where your SIGNALR codes reside So you need to configure CORS configuration see figure below. image Now it allows any fetch like GET & POST

SEGMENTATION OF CLIENTS ON SENDING MESSAGE Clients.Group("General") .SendAsync("Hello!"); - To send msg on segmented group

What to use groups for?

  • Chat rooms and channels
  • Topic subscriptions
  • Any other collection of connections