You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/tutorial-build-chat.md
+21-13Lines changed: 21 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,6 @@ First let's create an empty ASP.NET Core app.
90
90
}
91
91
92
92
app.UseStaticFiles();
93
-
94
93
app.UseRouting();
95
94
96
95
app.UseEndpoints(endpoints =>
@@ -120,27 +119,36 @@ You may remember in the [publish and subscribe message tutorial](./tutorial-pub-
120
119
dotnet add package Microsoft.Extensions.Azure
121
120
```
122
121
123
-
2. Add a `SampleChatHub` class to handle hub events. And DI the service middleware and service client inside `ConfigureServices`. Don't forget to replace `<connection_string>` with the one of your services.
122
+
2. Add a `SampleChatHub` class to handle hub events. And DI the service middleware and service client inside `ConfigureServices()`. Don't forget to replace `<connection_string>` with the one of your services.
124
123
125
124
```csharp
126
-
private sealed class SampleChatHub : WebPubSubHub
125
+
public void ConfigureServices(IServiceCollection services)
services.AddWebPubSub(o => o.ServiceEndpoint = new ServiceEndpoint("<connection_string>"))
128
+
.AddWebPubSubServiceClient<SampleChatHub>();
129
+
}
129
130
130
-
public SampleChatHub(WebPubSubServiceClient<SampleChatHub> serviceClient)
131
+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
132
+
{
133
+
if (env.IsDevelopment())
131
134
{
132
-
_serviceClient = serviceClient;
135
+
app.UseDeveloperExceptionPage();
133
136
}
137
+
138
+
app.UseStaticFiles();
139
+
app.UseRouting();
140
+
141
+
app.UseEndpoints(endpoints =>
142
+
{
143
+
});
134
144
}
135
-
136
-
public void ConfigureServices(IServiceCollection services)
145
+
146
+
private sealed class SampleChatHub : WebPubSubHub
137
147
{
138
-
services.AddWebPubSub(o => o.ServiceEndpoint = new ServiceEndpoint("<connection_string>"))
139
-
.AddWebPubSubServiceClient<SampleChatHub>();
140
148
}
141
149
```
142
150
143
-
`AddWebPubSubServiceClient<THub>` is used to inject the service client, with which we can generate client connection token and invoke service REST APIs when hub events are triggered.
151
+
`AddWebPubSubServiceClient<THub>()` is used to inject the service client`WebPubSubServiceClient<THub>`, with which we can use in negotiation step to generate client connection token andin hub methods to invoke service REST APIs when hub events are triggered.
144
152
145
153
3. Add a `/negotiate` API to the server inside `app.UseEndpoints` to generate the token.
146
154
@@ -491,7 +499,7 @@ Here we're using Web PubSub middleware SDK, there is already an implementation t
491
499
});
492
500
```
493
501
494
-
2. Go the `SampleChatHub` we created in previous step and override `OnConnectedAsync()` method we'd like server to invoke service when `connected` event is triggered.
502
+
2. Go the `SampleChatHub` we created in previous step. Add a constructor to work with `WebPubSubServiceClient<SampleChatHub>` so we can use to invoke service. And override `OnConnectedAsync()` method to respond when `connected` event is triggered.
495
503
```csharp
496
504
private sealed class SampleChatHub : WebPubSubHub
497
505
{
@@ -509,7 +517,7 @@ Here we're using Web PubSub middleware SDK, there is already an implementation t
509
517
}
510
518
```
511
519
512
-
In the above code, we use the service client to broadcast a notification message to all and indicate whom is joined.
520
+
In the above code, we use the service client to broadcast a notification message to all of whom is joined.
0 commit comments