Signalr

"real-time" web applications

Why?

Live content

What is happening with the data outside the current application instance?

 

someone else could:

  • add
  • remove
  • modify

Who?

  • an user
  • a process
  • another application

What we need to do?

  • Refresh it!

How?

Press F5

or Ctrl-R

or hit the refresh button

The foundation of the web

http

works over TCP/IP

request
response

a client - request -> URI


Resource <- a server response

Hyperlinks

So, yes, you need to refresh your browser

fortunately we can dev rich applications for browsers

(Javascript)

Techniques 

  • scheduled request
  • Forever frame
  • Ajax long-pooling

Modern techniques

  • Websockets
  • Server Sent Events

Signalr

Abstraction for

  • Forever frame
  • Long pooling
  • Websockets
  • Server sent events

through two models of communication

Persistent connections

Low level communication API

Hubs

High level communication API

Allows to call function

  • From server to client
  • From client to server

Build over Persistent Connection API

Send message

  • one specific client
  • group of clients
  • all clients (broadcast)

For our business case?

we can use Signalr for

  • push new songs in the user feed
  • notify "likes" or new comments over our songs
  • live comments

DEMO?

Setup your dev env

Install

  • .NET Core -> https://www.microsoft.com/net
  • Visual Studio Code -> https://code.visualstudio.com

yeoman

npm install -g yo generator-aspnet bower

Create a Signalr app

Create an ASP.NET App

yo aspnet

Select Basic Application

... and Boostrap

Run the base app

dotnet restore
dotnet run

Open the app on VS Code

code . #remember to specify the path

Marginals App

  • Send a message to everybody when somebody feels like a marginal
  • Send a "Wake up marginal!" to someone

Server

AllMarginals (Hub)

Message for all

OneMarginals (Hub)