[MUSIC]
>> I'll show you right here. Like we talked about earlier,
this is my hub and right here I've got clients and
I can do.others,.groups,.users, etc.
Essentially what I would do at that point,
I'll just grab this and copy it out here.
I think that's a dynamic,
so what I can do is literally just give it any method,
doWork, "foo",
or I can say 24 and it would actually send that out.
Actually I'm going to do something like that.
That's what it used to look like, send Async.
In this case, this is when I'm sending
a message from the server to the clients.
My IntelliSense is getting all messed up.
But in this case, I would just give it
a name and that's my method name.
If you think about it, it's not really
a method name as much as it is
an event name on the client. That makes sense.
You can see here controlLocked, controlUnlocked.
Those are almost like events that I'm going to fire and then I can
just send 42 to answer all questions.
Rather I would have the new app on object array.
I could do it like that. I send 42,
and I can send Tom.
I can send here any series objects that I want at that point.
Weird errors, sorry for my IntelliSense.
Now, this is how you would send a message to
the clients from the server.
Obviously the next step is going to be how do you actually handle
those events that happen to be coming from the server.
What I would do and you're looking
at my awful old JavaScript code here,
if I were to open up real time,
which you would see in here,
is that the first stage that you do is you
want to actually create the connection,
but we'll get into that in a minute.
I'll talk to you about connections in a minute.
Think about this side which is SendCoreAsync,
which is basically just sending an event to the client.
Then how do you handle it?
Right here, connection.on.
The first parameter of that is
the name of the event that you want to handle, so controlLocked,
controlUnlocked, click to whatever,
server full, pick your poison.
Any event that is going to be fired or sent from here,
I can literally just use that same string
as the string. Sorry, frustrating magic.
You can actually do it over here.
Then this is an expression where I can basically just say,
I know what I'm getting back from
the server and I can just basically come up with
my event handler and deal
with that event argument coming in right here.
It was fun to show this in class
because people think about all the complexity
of RPC and the complexity of server push for the love,
the complexity of writing your own
protocol and something like websocket.
What we have here is exactly what she would think you would
have to have and I'm going to use this term loosely,
a pub-sub experience or an event-driven experience.
I want to send an event to the clients and I want to
handle the event on those clients using whatever object I have.
>> It's exactly how it should work.
>> Yeah. It's insanely simple. I'll show you the one I got you.
From a coding perspective,
if you're using the ASP.Net Core side,
if you're doing the Azure SignalR service,
you don't have the server, you've got
the service and you can basically fire events out to
your clients how you want to.
If you're in ASP.Net Core server-side land,
what you've got is essentially when you wire it up,
you essentially have to do this,
which basically dials in all the signal or stuff on the server.
Then if you want to map the route to you that hub,
this is essentially what you would do on the server as well.
This, when I started with signal R,
was the only thing I forgot every single time.
I always wanted to call it out because
I literally forgot it every single time.
I would hit F5, fire an event,
curse a lot, stop it,
do it again and then go,
I forgot to wire the main point.
If you find that situation
happening where you're like ready sentiment work that was easy,
it might look so easy,
you've probably forgotten this [inaudible] .
>> That sounds basically how I
wind up doing my development as well,
is I'll forget something really silly,
I'll go ahead and start it, if it doesn't really work,
I'll curse, then I'll assume,
it must have built wrong,
it must have been the compiler that went wrong.
>> It's clearly not.
>> Yeah, let me just try it again without changing any code.
It'll work this time.
>> I call that insanity, I think.
>> Exactly.