asp.net signalr & webhooks - nagaraj's .net … signalr & webhooks agenda • getting...

18
ASP.NET SignalR & WebHooks http://nbende.wordpress.com

Upload: hakhue

Post on 20-May-2018

227 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

ASP.NET SignalR & WebHookshttp://nbende.wordpress.com

Page 2: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

Agenda

• Getting started with SignalR

• Using SignalR for Dual Communication modes

Page 3: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR
Page 4: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

What is ASP.NET SignalR

Page 5: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

Real-time web" functionality ?

Page 6: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

Why use SignalR?

Page 7: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR
Page 8: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

SignalR Hosts

Host agnostic – run in asp.net or stand alone

with self-host on OWIN

Page 9: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

What to include?

Page 10: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

Hubs and Connections

Connections – LOW LEVEL

Raw strings up and down

Broadcast to all clients, groups or individuals

Connection, reconnection and disconnection semantics

Hubs – Bit higher level

Client-server and server-client

Automatic client proxy generation

Page 11: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

Getting started with SignalR

Page 12: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

To Start

Page 13: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

<body>

<div class="container">

<input type="text" id="message" />

<input type="button" id="sendmessage" value="Send" />

<input type="hidden" id="displayname" />

<ul id="discussion">

</ul>

</div>

<!--Script references. -->

<script src="Scripts/jquery-1.6.4.min.js" ></script>

<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>

<script src="signalr/hubs"></script>

<!--Add script to update the page and send messages.-->

<script type="text/javascript">

$(function () {

// Declare a proxy to reference the hub.

var chat = $.connection.chatHub;

// Create a function that the hub can call to broadcast messages.

chat.client.broadcastMessage = function (name, message) {

Page 14: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

To Start ( VS 2013 )

Page 15: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

<div class="container"><input type="text" id="message" /><input type="button" id="sendmessage" value="Send" /><input type="hidden" id="displayname" /><ul id="discussion"></ul>

</div>

@section scripts {

Page 16: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

@section scripts {<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>

<!--Reference the autogenerated SignalR hub script. --><script src="~/signalr/hubs"></script><!--SignalR script to update the chat page and send messages.--><script>

$(function () {// Reference the auto-generated proxy for the hub.var chat = $.connection.chatHub;// Create a function that the hub can call back to display messages.chat.client.addNewMessageToPage = function (name, message) {

// Add the message to the page.$('#discussion').append('<li><strong>' + htmlEncode(name)

+ '</strong>: ' + htmlEncode(message) + '</li>');};// Get the user name and store it to prepend to messages.$('#displayname').val(prompt('Enter your name:', ''));// Set initial focus to message input box.$('#message').focus();// Start the connection.$.connection.hub.start().done(function () {

$('#sendmessage').click(function () {// Call the Send method on the hub.chat.server.send($('#displayname').val(), $('#message').val());// Clear text box and reset focus for next comment.$('#message').val('').focus();

});});

});// This optional function html-encodes messages for display in the page.function htmlEncode(value) {

var encodedValue = $('<div />').text(value).html();return encodedValue;

}</script>

}

Page 17: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

https://github.com/nbende/ASPDEMOS/tree/master/ApiAng

https://github.com/nbende/ASPDEMOS/tree/master/MVCApiDemo

https://github.com/nbende/ASPDEMOS/tree/master/SignalR2

https://github.com/nbende/ASPDEMOS/tree/master/SignalR2

Page 18: ASP.NET SignalR & WebHooks - Nagaraj's .NET … SignalR & WebHooks Agenda • Getting started with SignalR • Using SignalR for Dual Communication modes What is ASP.NET SignalR

Questions?